Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Stop uninstall loops when game activity is unknown

Leonardo Lobato29acfe860d65
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index 35fc95f..a9adc15 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -1050,6 +1050,9 @@ void Controller::TickUninstalls() {
facts.has_title = std::any_of(snapshot.installs.begin(), snapshot.installs.end(),
[id](const RuntimeInstallView& view) { return view.app_id == id; });
facts.removing = snapshot.removing_app == id;
+ facts.removal_started = std::any_of(snapshot.installs.begin(), snapshot.installs.end(), [id](const RuntimeInstallView& view) {
+ return view.app_id == id && view.state == runtime::PreparationState::kRemoving;
+ });
facts.removals_handled = snapshot.removals_handled;
if (const auto failure = snapshot.removal_failures.find(id); failure != snapshot.removal_failures.end())
facts.removal_failure = failure->second;
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index 64dad7b..eb28111 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -55,6 +55,10 @@ constexpr int kMaxPreparationSteps = 64;
// the worker made at most this long ago.
constexpr auto kLaunchPollInterval = std::chrono::seconds(2);
constexpr std::int64_t kPreflightFreshMs = 5000;
+// The console's process list could not show whether the title runs (the reason is in
+// runtime.log). Closing the game cannot help when no game runs; a restart usually does.
+constexpr char kActivityUnknown[] =
+ "The PS5 could not tell Playden whether the game is running. Restart the PS5, then try again.";
std::string InstallId(std::uint32_t app_id) { return "steam-" + std::to_string(app_id); }
@@ -1484,6 +1488,11 @@ std::string RuntimeHost::RunPrepare(Composition& c, const RuntimePrepareRequest&
// Re-ensure the staged title (idempotent for a matching title; it also
// repairs directory modes from earlier builds) before resuming.
if (existing->state == rt::PreparationState::kPreparing || existing->state == rt::PreparationState::kRegistering) {
+ // Only when the next step can run: each step stops while the title may run, and a
+ // folder rebuilt here (one the player deleted, say) would put the title back on Home.
+ const auto activity = c.coordinator->Activity(existing->title_id);
+ if (activity == rt::NativeActivity::kUnknown) return kActivityUnknown;
+ if (activity != rt::NativeActivity::kStopped) return "Close the game first.";
const auto staged = c.installer->StageTitle(*existing);
Log("resume title check state=" + std::to_string(static_cast<int>(staged.state)) + " code=" + staged.code +
" message=" + staged.message);
@@ -1794,7 +1803,7 @@ std::string RuntimeHost::MaintenanceRefusal(Composition& c, const rt::RuntimeIns
if (!pending.ok) return "The launch record cannot be read; restart Playden.";
if (pending.session) return "Close the game first.";
const auto activity = c.coordinator->Activity(record.title_id);
- if (activity == rt::NativeActivity::kUnknown) return "The PS5 can't tell whether the game is running. Try again.";
+ if (activity == rt::NativeActivity::kUnknown) return kActivityUnknown;
if (activity != rt::NativeActivity::kStopped) return "Close the game first.";
return {};
}
@@ -1957,8 +1966,7 @@ std::string RuntimeHost::RunRemove(Composition& c, std::uint32_t app, bool delet
}
const auto activity = c.coordinator->Activity(record.title_id);
if (activity == rt::NativeActivity::kActive) return "Close the game before uninstalling it.";
- if (activity != rt::NativeActivity::kStopped)
- return "Playden cannot tell whether the game is running. Close it and try again.";
+ if (activity != rt::NativeActivity::kStopped) return kActivityUnknown;
const bool resuming = record.state == rt::PreparationState::kRemoving && record.journal &&
record.journal->operation.rfind("remove", 0) == 0;
// The game's name for the kept bottle, read before its title folder goes.
@@ -2206,8 +2214,10 @@ void RuntimeHost::Run() {
if (kit_reason.empty()) kit_reason = "No verified compatibility kit is installed.";
c.installer = std::make_unique<UnavailablePackageInstaller>(kit_reason);
}
+ auto native = config_.native;
+ if (!native.log) native.log = [this](const std::string& line) { Log(line); };
c.coordinator = std::make_unique<ps5::Ps5NativeCoordinator>(
- c.records, *c.installer, c.registry, config_.homebrew_root, config_.native);
+ c.records, *c.installer, c.registry, config_.homebrew_root, std::move(native));
c.owner = std::make_unique<rt::SettingsPublicationOwner>(c.records, *c.installer, *c.coordinator);
c.service = std::make_unique<rt::RuntimeInstallService>(
c.records, *c.installer, *c.coordinator,
diff --git a/src/homebrew/uninstall_flow.cpp b/src/homebrew/uninstall_flow.cpp
index 7b1aa3f..ca2b1cf 100644
--- a/src/homebrew/uninstall_flow.cpp
+++ b/src/homebrew/uninstall_flow.cpp
@@ -85,10 +85,12 @@ UninstallAction UninstallFlow::Advance(GameId id, const UninstallFacts& facts) {
}
} else {
if (facts.removing || facts.removals_handled <= entry.removals_before) return {};
+ // A refusal before the removal began changed nothing: there is no removal for Retry to continue.
if (facts.has_title)
return Stop(id, "The PS5 title could not be removed: " +
(facts.removal_failure.empty() ? std::string("unknown reason.") : facts.removal_failure) +
- " The game stays installed; Retry on its PS5 title continues.");
+ (facts.removal_started ? " The game stays installed; Retry on its PS5 title continues."
+ : " The game stays installed."));
entry.step = UninstallStep::kRemoveDownload;
}
}
diff --git a/src/homebrew/uninstall_flow.hpp b/src/homebrew/uninstall_flow.hpp
index c75b371..a55db0b 100644
--- a/src/homebrew/uninstall_flow.hpp
+++ b/src/homebrew/uninstall_flow.hpp
@@ -28,6 +28,7 @@ struct UninstallAction {
struct UninstallFacts {
bool has_title = false; // an install record exists (Ready, failed or being removed)
bool removing = false; // the runtime is removing it now
+ bool removal_started = false; // its record holds a removal journal that Retry continues
std::uint64_t removals_handled = 0;
std::string removal_failure; // the runtime's latest removal refusal or failure
bool saves_moving = false; // a Cloud transfer runs for the game
diff --git a/src/platform/ps5/native_coordinator.cpp b/src/platform/ps5/native_coordinator.cpp
index e9b8242..3bc5a0a 100644
--- a/src/platform/ps5/native_coordinator.cpp
+++ b/src/platform/ps5/native_coordinator.cpp
@@ -59,7 +59,34 @@ Ps5NativeCoordinator::Ps5NativeCoordinator(runtime::InstallRecordStore& records,
TitleRegistry& registry, std::filesystem::path root, NativeCoordinatorOperations operations)
: records_(records), package_(package), registry_(registry), root_(std::move(root)), operations_(std::move(operations)) {
if (!operations_.database) operations_.database = ReadNativeTitleDatabase;
- if (!operations_.activity) operations_.activity = [](const auto& title) { return ReadTitleActivity(title); };
+ if (!operations_.activity) operations_.activity = LoggedTitleActivity(operations_.log);
+}
+std::function<runtime::NativeActivity(const std::string&)> LoggedTitleActivity(
+ std::function<void(const std::string&)> log) {
+ struct Reasons { std::mutex mutex; std::map<std::string, std::string> unknown; };
+ auto reasons = std::make_shared<Reasons>();
+ return [log = std::move(log), reasons](const std::string& title) {
+ std::string reason;
+ const auto activity = ReadTitleActivity(title, &reason);
+ if (!log) return activity;
+ std::string line;
+ {
+ std::lock_guard<std::mutex> lock(reasons->mutex);
+ const auto found = reasons->unknown.find(title);
+ if (activity == runtime::NativeActivity::kUnknown) {
+ if (found == reasons->unknown.end() || found->second != reason) {
+ reasons->unknown[title] = reason;
+ line = "title activity unknown title=" + title + " reason=" + reason;
+ }
+ } else if (found != reasons->unknown.end()) {
+ reasons->unknown.erase(found);
+ line = std::string("title activity known again title=") + title +
+ (activity == runtime::NativeActivity::kActive ? " active" : " stopped");
+ }
+ }
+ if (!line.empty()) log(line);
+ return activity;
+ };
}
runtime::NativeTitleAvailability Ps5NativeCoordinator::Availability(const std::string& title) {
if (!IsPlaydenGameTitle(title)) return {};
diff --git a/src/platform/ps5/native_coordinator.h b/src/platform/ps5/native_coordinator.h
index b33e781..c323829 100644
--- a/src/platform/ps5/native_coordinator.h
+++ b/src/platform/ps5/native_coordinator.h
@@ -3,6 +3,9 @@
#include "platform/ps5/title_registry.h"
#include "runtime/install_service.h"
#include <filesystem>
+#include <map>
+#include <memory>
+#include <mutex>
namespace playden::ps5 {
struct TitleSourceObservation {
@@ -17,6 +20,8 @@ TitleSourceObservation ReadTitleSource(const std::filesystem::path& homebrew_roo
struct NativeCoordinatorOperations {
std::function<TitleDatabaseObservation(const std::string&)> database;
std::function<runtime::NativeActivity(const std::string&)> activity;
+ // Receives why the default activity reader could not tell whether a title runs.
+ std::function<void(const std::string&)> log;
};
class Ps5NativeCoordinator final : public runtime::NativeCoordinator {
public:
@@ -41,4 +46,8 @@ class Ps5NativeCoordinator final : public runtime::NativeCoordinator {
std::filesystem::path root_;
NativeCoordinatorOperations operations_;
};
+// The default activity reader: an unknown result is logged when its reason changes,
+// and once more when the title's activity is known again.
+std::function<runtime::NativeActivity(const std::string&)> LoggedTitleActivity(
+ std::function<void(const std::string&)> log);
} // namespace playden::ps5
diff --git a/src/platform/ps5/title_activity.cpp b/src/platform/ps5/title_activity.cpp
index 23ec519..5888f3e 100644
--- a/src/platform/ps5/title_activity.cpp
+++ b/src/platform/ps5/title_activity.cpp
@@ -1,6 +1,8 @@
#include "platform/ps5/title_activity.h"
#include "platform/ps5/title_runtime.h"
#include <algorithm>
+#include <cerrno>
+#include <cstdio>
#include <cstring>
#include <set>
#if defined(__PROSPERO__)
@@ -34,78 +36,118 @@ std::optional<std::vector<std::int32_t>> DecodeTitleActivityProcessIds(const std
}
return InventoryValid(pids) ? std::optional<std::vector<std::int32_t>>(std::move(pids)) : std::nullopt;
}
-runtime::NativeActivity QueryTitleActivity(const std::string& title, const TitleActivityApi& api) {
+runtime::NativeActivity QueryTitleActivity(const std::string& title, const TitleActivityApi& api, std::string* reason) {
using runtime::NativeActivity;
- if (!ValidTitleId(title) || !api.processes || !api.identity) return NativeActivity::kUnknown;
- auto first = api.processes(); if (!first || !InventoryValid(*first)) return NativeActivity::kUnknown;
+ const auto unknown = [reason](std::string why) {
+ if (reason) *reason = std::move(why);
+ return NativeActivity::kUnknown;
+ };
+ if (!ValidTitleId(title) || !api.processes || !api.identity) return unknown("no title id or process reader");
+ auto first = api.processes(); if (!first || !InventoryValid(*first)) return unknown("process list unreadable");
std::sort(first->begin(), first->end());
std::vector<ProcessTitleIdentity> identities(first->size());
- bool complete = true;
- auto valid_identity = [](const std::optional<ProcessTitleIdentity>& value) {
+ // The first process whose identity cannot be trusted, and how many there are.
+ std::string untrusted; unsigned untrusted_count = 0;
+ auto valid_identity = [&](std::int32_t pid, const std::optional<ProcessTitleIdentity>& value) {
// FW13.60 PID 1 has app_id zero and a valid system title. A successful
// title identity is authoritative regardless of app_id; only an untitled
// identity requires app_id zero. Failed calls never become non-apps.
- return value && ((value->app_id == 0 && value->title_id.empty()) || ValidTitleId(value->title_id));
+ if (value && ((value->app_id == 0 && value->title_id.empty()) || ValidTitleId(value->title_id))) return true;
+ if (!untrusted_count++)
+ untrusted = "pid=" + std::to_string(pid) + (value ? " app_id=" + std::to_string(value->app_id) +
+ " title=\"" + value->title_id + "\" is not a title"
+ : std::string(" identity unavailable"));
+ return false;
+ };
+ const auto untrusted_reason = [&] {
+ return untrusted + (untrusted_count > 1 ? " (+" + std::to_string(untrusted_count - 1) + " more)" : std::string());
};
for (std::size_t i = 0; i < first->size(); ++i) {
const auto pid = (*first)[i]; if (pid == 0) continue; // Kernel cannot be a user title.
auto identity = api.identity(pid);
- if (!valid_identity(identity)) { complete = false; continue; }
+ if (!valid_identity(pid, identity)) continue;
if (identity->title_id == title) return NativeActivity::kActive;
identities[i] = *identity;
}
- if (!complete) return NativeActivity::kUnknown;
- auto second = api.processes(); if (!second || !InventoryValid(*second)) return NativeActivity::kUnknown;
- std::sort(second->begin(), second->end()); if (*first != *second) return NativeActivity::kUnknown;
+ if (untrusted_count) return unknown(untrusted_reason());
+ auto second = api.processes(); if (!second || !InventoryValid(*second)) return unknown("process list unreadable");
+ std::sort(second->begin(), second->end()); if (*first != *second) return unknown("process list changed");
+ std::string changed;
for (std::size_t i = 0; i < second->size(); ++i) {
- if ((*second)[i] == 0) continue;
- auto identity = api.identity((*second)[i]);
- if (!valid_identity(identity)) { complete = false; continue; }
+ const auto pid = (*second)[i]; if (pid == 0) continue;
+ auto identity = api.identity(pid);
+ if (!valid_identity(pid, identity)) continue;
if (identity->title_id == title) return NativeActivity::kActive;
- if (identity->app_id != identities[i].app_id || identity->title_id != identities[i].title_id) complete = false;
+ if (changed.empty() && (identity->app_id != identities[i].app_id || identity->title_id != identities[i].title_id))
+ changed = "pid=" + std::to_string(pid) + " identity changed";
}
- if (!complete) return NativeActivity::kUnknown;
- auto final = api.processes(); if (!final || !InventoryValid(*final)) return NativeActivity::kUnknown;
+ if (untrusted_count) return unknown(untrusted_reason());
+ if (!changed.empty()) return unknown(changed);
+ auto final = api.processes(); if (!final || !InventoryValid(*final)) return unknown("process list unreadable");
std::sort(final->begin(), final->end());
- return *first == *final ? NativeActivity::kStopped : NativeActivity::kUnknown;
+ return *first == *final ? NativeActivity::kStopped : unknown("process list changed");
}
-runtime::NativeActivity ReadTitleActivity(const std::string& title, const TitleActivityTrace& trace) {
- if (!ValidTitleId(title)) return runtime::NativeActivity::kUnknown;
+runtime::NativeActivity ReadTitleActivity(const std::string& title, std::string* reason) {
+ if (!ValidTitleId(title)) {
+ if (reason) *reason = "no title id";
+ return runtime::NativeActivity::kUnknown;
+ }
#if defined(__PROSPERO__)
// Same 96-byte AppInfo layout used by the title-scoped elevation helper.
struct AppInfo { std::uint32_t app_id; std::uint64_t reserved; char title_id[14]; char padding[0x3c]; };
static_assert(sizeof(AppInfo) == 96 && offsetof(AppInfo, title_id) == 16);
static_assert(offsetof(kinfo_proc, ki_pid) == 72 && offsetof(kinfo_proc, ki_structsize) == 0);
+ // The first kernel call that failed, for an unknown result's reason.
+ std::string failed;
+ const auto unknown = [&](const std::string& why) {
+ if (reason) *reason = failed.empty() ? why : why + "; " + failed;
+ return runtime::NativeActivity::kUnknown;
+ };
using GetInfo = int (*)(int, AppInfo*); GetInfo get_info = nullptr;
if (sceKernelDlsym(0x2001, "sceKernelGetAppInfo", reinterpret_cast<void**>(&get_info)) != 0 || !get_info)
- return runtime::NativeActivity::kUnknown;
- auto identity = [get_info, &trace](std::int32_t pid) -> std::optional<ProcessTitleIdentity> {
+ return unknown("sceKernelGetAppInfo is not available");
+ auto identity = [get_info, &failed](std::int32_t pid) -> std::optional<ProcessTitleIdentity> {
AppInfo value{};
const auto rc = get_info(pid, &value);
const auto* end = static_cast<const char*>(std::memchr(value.title_id, 0, sizeof(value.title_id)));
- if (trace) trace("identity pid=" + std::to_string(pid) + " rc=" + std::to_string(static_cast<std::uint32_t>(rc)) +
- " app_id=" + std::to_string(value.app_id) + " title=" + (end ? std::string(value.title_id, end - value.title_id) : "<unterminated>"));
- if (rc != 0) return std::nullopt;
- if (!end) return std::nullopt;
+ if (rc != 0 || !end) {
+ if (failed.empty()) {
+ char code[16]; std::snprintf(code, sizeof(code), "0x%08x", static_cast<unsigned>(rc));
+ failed = "sceKernelGetAppInfo pid=" + std::to_string(pid) + " rc=" + code + (end ? "" : " title unterminated");
+ }
+ return std::nullopt;
+ }
return ProcessTitleIdentity{value.app_id, std::string(value.title_id, static_cast<std::size_t>(end - value.title_id))};
};
const auto self_pid = ::getpid(); auto self = self_pid > 0 ? identity(self_pid) : std::nullopt;
- if (!self || !self->app_id || !ValidTitleId(self->title_id)) return runtime::NativeActivity::kUnknown;
+ if (!self || !self->app_id || !ValidTitleId(self->title_id)) return unknown("Playden's own identity unavailable");
TitleActivityApi api; api.identity = identity;
- api.processes = [self_pid, &trace]() -> std::optional<std::vector<std::int32_t>> {
+ api.processes = [self_pid, &failed]() -> std::optional<std::vector<std::int32_t>> {
+ const auto fail = [&failed](const std::string& why) {
+ if (failed.empty()) failed = why;
+ return std::nullopt;
+ };
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PROC, 0}; std::size_t length = 0;
- if (::sysctl(mib, 4, nullptr, &length, nullptr, 0) != 0 || !length || length > kMaxBytes) return std::nullopt;
+ if (::sysctl(mib, 4, nullptr, &length, nullptr, 0) != 0)
+ return fail("sysctl size errno=" + std::to_string(errno));
+ if (!length || length > kMaxBytes) return fail("sysctl size bytes=" + std::to_string(length));
std::vector<std::uint8_t> bytes(length);
- if (::sysctl(mib, 4, bytes.data(), &length, nullptr, 0) != 0 || length > bytes.size() || !length) return std::nullopt;
+ if (::sysctl(mib, 4, bytes.data(), &length, nullptr, 0) != 0)
+ return fail("sysctl errno=" + std::to_string(errno));
+ if (length > bytes.size() || !length) return fail("sysctl bytes=" + std::to_string(length));
bytes.resize(length); auto pids = DecodeTitleActivityProcessIds(bytes);
- if (trace) trace("snapshot bytes=" + std::to_string(bytes.size()) + " processes=" + (pids ? std::to_string(pids->size()) : "invalid"));
+ if (!pids) return fail("process records malformed bytes=" + std::to_string(length));
// Qualify the snapshot's PID field against this independently known PID.
- if (!pids || std::find(pids->begin(), pids->end(), self_pid) == pids->end()) return std::nullopt;
+ if (std::find(pids->begin(), pids->end(), self_pid) == pids->end())
+ return fail("process list lacks Playden's pid=" + std::to_string(self_pid));
return pids;
};
- return QueryTitleActivity(title, api);
+ std::string query_reason;
+ const auto activity = QueryTitleActivity(title, api, &query_reason);
+ return activity == runtime::NativeActivity::kUnknown ? unknown(query_reason) : activity;
#else
- (void)title; (void)trace; return runtime::NativeActivity::kUnknown;
+ if (reason) *reason = "not a PS5 build";
+ return runtime::NativeActivity::kUnknown;
#endif
}
} // namespace playden::ps5
diff --git a/src/platform/ps5/title_activity.h b/src/platform/ps5/title_activity.h
index e004bcb..37c9dea 100644
--- a/src/platform/ps5/title_activity.h
+++ b/src/platform/ps5/title_activity.h
@@ -17,9 +17,11 @@ struct TitleActivityApi {
std::optional<std::vector<std::int32_t>> DecodeTitleActivityProcessIds(const std::vector<std::uint8_t>& bytes);
// A positively identified target is active; stopped requires complete valid
// identities twice with unchanged enclosing inventories. Unknown never authorizes edits.
-runtime::NativeActivity QueryTitleActivity(const std::string& title_id, const TitleActivityApi& api);
+// An unknown result says why in `reason`, when given.
+runtime::NativeActivity QueryTitleActivity(const std::string& title_id, const TitleActivityApi& api,
+ std::string* reason = nullptr);
// Read-only native boundary. Host builds always return unknown. FW13.60 native
// ABI/API qualification is required before production uses this for mutation.
-using TitleActivityTrace = std::function<void(const std::string&)>;
-runtime::NativeActivity ReadTitleActivity(const std::string& title_id, const TitleActivityTrace& trace = {});
+// An unknown result says why in `reason`, with the first failed kernel call.
+runtime::NativeActivity ReadTitleActivity(const std::string& title_id, std::string* reason = nullptr);
} // namespace playden::ps5
diff --git a/tests/homebrew_runtime_host_test.cpp b/tests/homebrew_runtime_host_test.cpp
index 3eee172..78168ff 100644
--- a/tests/homebrew_runtime_host_test.cpp
+++ b/tests/homebrew_runtime_host_test.cpp
@@ -533,6 +533,24 @@ void ResumesInterruptedCaptureFromSavedRequest(bool tamper_backup = false) {
auto bytes = Read(backup); bytes[0] = bytes[0] == 'X' ? 'Y' : 'X';
Write(backup, bytes, 0600);
}
+ if (!tamper_backup) {
+ // While the console cannot tell whether the title runs, the resume stops before it
+ // rebuilds a title folder the player deleted (ShadowMount would put it back on Home).
+ CHECK(failed.installs[0].state == PreparationState::kPreparing ||
+ failed.installs[0].state == PreparationState::kRegistering);
+ const auto title = fixture.root / "data/homebrew/FAKE78001", aside = fixture.root / "title-aside";
+ fs::rename(title, aside);
+ fixture.activity->store(static_cast<int>(NativeActivity::kUnknown));
+ const auto asked = host.Snapshot().revision;
+ host.Prepare(Hl2());
+ WaitFor(host, [asked](const RuntimeSnapshot& s) {
+ return s.revision > asked && !s.preparing_app && s.refusals.count(220) &&
+ s.refusals.at(220).find("Restart the PS5") != std::string::npos;
+ });
+ CHECK(!fs::exists(title) && fixture.registry_mutations == 0);
+ fs::rename(aside, title);
+ fixture.activity->store(static_cast<int>(NativeActivity::kStopped));
+ }
const auto before = host.Snapshot().revision;
host.Prepare(Hl2());
WaitFor(host, [before](const RuntimeSnapshot& s) { return s.revision > before && !s.refusals.count(220); });
diff --git a/tests/homebrew_uninstall_flow_test.cpp b/tests/homebrew_uninstall_flow_test.cpp
index 77126f3..974400a 100644
--- a/tests/homebrew_uninstall_flow_test.cpp
+++ b/tests/homebrew_uninstall_flow_test.cpp
@@ -55,8 +55,21 @@ int main() {
titled.removal_failure = "Close the game before uninstalling it.";
action = flow.Advance(43, titled);
CHECK(action.kind == Kind::kStop && action.reason.find("Close the game") != std::string::npos);
+ // A refusal before the removal began has no removal for Retry to continue.
+ CHECK(action.reason.find("Retry") == std::string::npos);
CHECK(!flow.Step(43));
+ // A removal that stopped partway is continued by Retry.
+ CHECK(flow.Begin(47, false, false));
+ titled = {};
+ titled.has_title = true;
+ CHECK(flow.Advance(47, titled).kind == Kind::kRemoveTitle);
+ titled.removals_handled = 1;
+ titled.removal_started = true;
+ titled.removal_failure = "The console has not confirmed that the PS5 title is gone.";
+ action = flow.Advance(47, titled);
+ CHECK(action.kind == Kind::kStop && action.reason.find("Retry on its PS5 title continues") != std::string::npos);
+
// A game without a PS5 title goes straight to the download.
CHECK(flow.Begin(44, false, false));
CHECK(flow.Advance(44, UninstallFacts{}).kind == Kind::kRemoveDownload);
diff --git a/tests/native_coordinator_test.cpp b/tests/native_coordinator_test.cpp
index b5fd3d0..b0b5d08 100644
--- a/tests/native_coordinator_test.cpp
+++ b/tests/native_coordinator_test.cpp
@@ -120,5 +120,11 @@ int main() {
CHECK(!native.Query(record).available);
CHECK(native.Activity("../unsafe") == NativeActivity::kUnknown);
std::filesystem::remove_all(temporary);
+ // The default reader logs an unknown result once per reason, not on every check.
+ std::vector<std::string> lines;
+ const auto logged = LoggedTitleActivity([&](const std::string& line) { lines.push_back(line); });
+ CHECK(logged("FAKE78001") == NativeActivity::kUnknown && logged("FAKE78001") == NativeActivity::kUnknown);
+ CHECK(logged("FAKE78002") == NativeActivity::kUnknown);
+ CHECK(lines.size() == 2 && lines[0] == "title activity unknown title=FAKE78001 reason=not a PS5 build");
std::puts("native coordinator tests passed");
}
diff --git a/tests/title_activity_test.cpp b/tests/title_activity_test.cpp
index 289f477..3a9d44b 100644
--- a/tests/title_activity_test.cpp
+++ b/tests/title_activity_test.cpp
@@ -32,10 +32,16 @@ int main() {
api.identity = [&](int pid) { return std::optional<ProcessTitleIdentity>({pid == 201 ? 123u : 0u,
pid == 201 ? (++identities == 1 ? "FAKE78002" : "FAKE78001") : ""}); };
CHECK(QueryTitleActivity("FAKE78001", api) == NativeActivity::kActive);
+ std::string reason;
api.identity = [](int) { return std::optional<ProcessTitleIdentity>{}; };
- CHECK(QueryTitleActivity("FAKE78002", api) == NativeActivity::kUnknown);
- api.identity = [](int) { return std::optional<ProcessTitleIdentity>({123, ""}); };
- CHECK(QueryTitleActivity("FAKE78002", api) == NativeActivity::kUnknown);
+ CHECK(QueryTitleActivity("FAKE78002", api, &reason) == NativeActivity::kUnknown);
+ CHECK(reason == "pid=100 identity unavailable (+1 more)");
+ api.identity = [](int pid) { return std::optional<ProcessTitleIdentity>({pid == 201 ? 123u : 0u, ""}); };
+ CHECK(QueryTitleActivity("FAKE78002", api, &reason) == NativeActivity::kUnknown);
+ CHECK(reason == "pid=201 app_id=123 title=\"\" is not a title");
+ // An untrusted identity does not hide a positively identified target.
+ api.identity = [](int pid) { return std::optional<ProcessTitleIdentity>({pid == 201 ? 123u : 7u, pid == 201 ? "FAKE78001" : ""}); };
+ CHECK(QueryTitleActivity("FAKE78001", api) == NativeActivity::kActive);
api.identity = [](int) { return std::optional<ProcessTitleIdentity>({0, "FAKE78001"}); };
CHECK(QueryTitleActivity("FAKE78001", api) == NativeActivity::kActive);
// FW13.60 PID 1 is a successful titled system identity with app_id zero.
@@ -45,10 +51,14 @@ int main() {
api.identity = [](int) { return std::optional<ProcessTitleIdentity>({0, ""}); };
unsigned reads = 0;
api.processes = [&] { return std::optional<std::vector<std::int32_t>>({{100, ++reads == 1 ? 201 : 202}}); };
- CHECK(QueryTitleActivity("FAKE78002", api) == NativeActivity::kUnknown);
+ CHECK(QueryTitleActivity("FAKE78002", api, &reason) == NativeActivity::kUnknown && reason == "process list changed");
+ unsigned calls = 0;
+ api.processes = [] { return std::optional<std::vector<std::int32_t>>({{100, 201}}); };
+ api.identity = [&](int pid) { return std::optional<ProcessTitleIdentity>({0u, pid == 201 && ++calls == 2 ? "NPXS45095" : ""}); };
+ CHECK(QueryTitleActivity("FAKE78002", api, &reason) == NativeActivity::kUnknown && reason == "pid=201 identity changed");
api.processes = [] { return std::optional<std::vector<std::int32_t>>({{100, 100}}); };
- CHECK(QueryTitleActivity("FAKE78002", api) == NativeActivity::kUnknown);
+ CHECK(QueryTitleActivity("FAKE78002", api, &reason) == NativeActivity::kUnknown && reason == "process list unreadable");
CHECK(QueryTitleActivity("../unsafe", api) == NativeActivity::kUnknown);
- CHECK(ReadTitleActivity("FAKE78002") == NativeActivity::kUnknown);
+ CHECK(ReadTitleActivity("FAKE78002", &reason) == NativeActivity::kUnknown && reason == "not a PS5 build");
std::puts("title activity tests passed");
}