Xbox Cloud Gaming app for PS5 Homebrew
C
Report a problem with a QR code; a crash is noticed at the next start
Rafael Abud Ferreirad9014de3473b
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 27ceece..0c12e18 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -81,6 +81,8 @@ add_library(xcloud_ui STATICsrc/app/library.cppsrc/app/settings.cppsrc/app/update_check.cpp+ src/app/report.cpp+ src/app/crash_guard.cppsrc/app/updater.cppsrc/app/auto_deband.cppextern/qrcodegen/qrcodegen.cdiff --git a/src/app/cli_main.cpp b/src/app/cli_main.cppindex 64bcf67..755c0c0 100644--- a/src/app/cli_main.cpp+++ b/src/app/cli_main.cpp@@ -18,6 +18,7 @@// xcloud-cli logout#include "app/library.h"#include "app/updater.h"+#include "app/report.h"#include "auth/auth_manager.h"#include "media/decoder.h"#include "net/http.h"@@ -605,6 +606,38 @@ int main(int argc, char** argv) {}int seconds = pos.size() > 1 ? std::atoi(pos[1]) : 30;rc = cmdStream(am, pos[0], seconds > 0 ? seconds : 30, pos.size() > 2 ? pos[2] : nullptr, res, opts, region);+ } else if (cmd == "ui-report" && argi < argc) {+ // Offline: #38's error screen (Triangle: report), its report's QR+ // code (a real link, from a made-up log), and Settings' hints.+ ui::Fonts fonts;+ if (!fonts.load("assets/fonts")) return 1;+ ui::ImageCache images([] {});+ ui::AppUi app(fonts, images);+ ui::Canvas canvas(1920, 1080);+ std::string out = argv[argi];+ auto save = [&](const std::string& name) {+ app.render(canvas, 1000);+ std::string path = out + "/" + name + ".png";+ stbi_write_png(path.c_str(), canvas.width(), canvas.height(), 4, canvas.data(), canvas.width() * 4);+ std::printf("wrote %s\n", path.c_str());+ };+ std::string error = "Secure connections could not be set up: certificates /app0/assets/cacert.pem: PK - "+ "Read/write of file failed (-15872). Log: /data/homebrew/PPSA99810/xcloud.log";+ app.showError(error);+ save("report_error");+ std::string log = "08:11:34 [I] === PSBox Cloud Gaming starting ===\n";+ for (int i = 0; i < 30; ++i) log += "08:11:3" + std::to_string(i % 10) + " [I] gpu: something at step " + std::to_string(i) + "\n";+ log += "08:11:37 [E] TLS setup: certificates /app0/assets/cacert.pem: PK - Read/write of file failed (-15872)\n"+ "08:11:37 [I] NOTIFY: PSBox: secure connections unavailable\n";+ app::report::Info info{error.substr(0, 70), error, XC_APP_VERSION, "13.00",+ app::report::sanitize(app::report::logExcerpt(log, false), {})};+ std::string url = app::report::issueUrl(info);+ std::printf("url: %zu characters\n%s\n", url.size(), url.c_str());+ app.showReport(url, ui::tr(ui::Str::ReportProblem));+ save("report_qr");+ app.showReport(url, ui::tr(ui::Str::CrashedLastTime));+ save("report_crash");+ return 0;} else if (cmd == "ui-settings" && argi < argc) {// Offline: Settings with the region list open, then the language list.ui::Fonts fonts;diff --git a/src/app/crash_guard.cpp b/src/app/crash_guard.cppnew file mode 100644index 0000000..12bb967--- /dev/null+++ b/src/app/crash_guard.cpp@@ -0,0 +1,120 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+#include "app/crash_guard.h"++#include "platform/platform.h"+#include "util/log.h"++#include <atomic>+#include <csignal>+#include <cstring>+#include <exception>+#include <fcntl.h>+#include <thread>+#include <unistd.h>++namespace xc::app::crash {++namespace {++char g_marker[512] = {};+char g_stage[96] = "starting";+std::atomic<uint64_t> g_beat{0};++const char* signalName(int sig) {+ switch (sig) {+ case SIGSEGV: return "SIGSEGV";+ case SIGBUS: return "SIGBUS";+ case SIGILL: return "SIGILL";+ case SIGFPE: return "SIGFPE";+ case SIGABRT: return "SIGABRT";+ default: return "?";+ }+}++// Async-signal-safe: open / write / close only, no allocation.+void writeMarker(const char* kind) {+ if (!g_marker[0]) return;+ int fd = ::open(g_marker, O_WRONLY | O_CREAT | O_TRUNC, 0666);+ if (fd < 0) return;+ auto put = [fd](const char* s) { (void)!::write(fd, s, std::strlen(s)); };+ put(kind);+ put("\n");+ put(g_stage);+ put("\n");+ ::close(fd);+}++void onSignal(int sig) {+ char kind[48] = "signal ";+ char num[8];+ int n = 0, v = sig;+ do num[n++] = static_cast<char>('0' + v % 10), v /= 10; while (v && n < 7);+ size_t k = std::strlen(kind);+ while (n) kind[k++] = num[--n];+ kind[k] = 0;+ std::strcat(kind, " (");+ std::strcat(kind, signalName(sig));+ std::strcat(kind, ")");+ writeMarker(kind);+ std::signal(sig, SIG_DFL);+ std::raise(sig);+}++} // namespace++void install(const std::string& markerPath) {+ std::strncpy(g_marker, markerPath.c_str(), sizeof g_marker - 1);+ for (int sig : {SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGABRT}) std::signal(sig, onSignal);+ std::set_terminate([] {+ writeMarker("uncaught exception");+ std::abort();+ });+}++void setStage(const char* stage) {+ // Written before a crash can read it half-copied: the end first.+ char tmp[sizeof g_stage];+ std::strncpy(tmp, stage, sizeof tmp - 1);+ tmp[sizeof tmp - 1] = 0;+ std::memcpy(g_stage, tmp, sizeof tmp);+}++void heartbeat() { g_beat = platform::nowMs(); }++void startWatchdog(uint32_t stallMs) {+ heartbeat();+ std::thread([stallMs] {+ bool stalled = false;+ for (;;) {+ platform::sleepMs(1000);+ uint64_t idle = platform::nowMs() - g_beat.load();+ if (!stalled && idle > stallMs) {+ stalled = true;+ XC_LOGW("crash guard: the main loop has not run for %llu ms (%s)", static_cast<unsigned long long>(idle), g_stage);+ writeMarker("stalled");+ } else if (stalled && idle < 1000) {+ stalled = false;+ XC_LOGI("crash guard: the main loop is back");+ ::unlink(g_marker);+ }+ }+ }).detach();+}++Previous takePrevious(const std::string& markerPath) {+ Previous p;+ std::string text;+ if (!platform::readFile(markerPath, text)) return p;+ ::unlink(markerPath.c_str());+ size_t nl = text.find('\n');+ p.found = true;+ p.kind = text.substr(0, nl);+ if (nl != std::string::npos) {+ p.stage = text.substr(nl + 1);+ while (!p.stage.empty() && (p.stage.back() == '\n' || p.stage.back() == '\r')) p.stage.pop_back();+ }+ return p;+}++} // namespace xc::app::crashdiff --git a/src/app/crash_guard.h b/src/app/crash_guard.hnew file mode 100644index 0000000..94d3560--- /dev/null+++ b/src/app/crash_guard.h@@ -0,0 +1,34 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+// Notices when the app went down. On the PS5 the app never ends normally:+// closed from the system's menu, its process is killed like a crash would.+// So a crash leaves a marker itself: a fatal signal (or an uncaught C+++// exception) writes what it was and the app's stage at the time, and a main+// loop stuck for long writes one too. The next start reads it and offers a+// report; being closed by the user leaves none.+#pragma once++#include <cstdint>+#include <string>++namespace xc::app::crash {++// Handlers for the fatal signals and std::terminate, writing to `markerPath`.+void install(const std::string& markerPath);+// What the app is doing (copied; up to 95 bytes): "home", "streaming ...".+void setStage(const char* stage);+// The main loop is alive. startWatchdog(): a thread that writes a "stalled"+// marker after `stallMs` without a heartbeat, and removes it if the loop+// comes back (a long hang, not a crash).+void heartbeat();+void startWatchdog(uint32_t stallMs);++struct Previous {+ bool found = false;+ std::string kind; // "signal 11 (SIGSEGV)", "uncaught exception", "stalled"+ std::string stage; // setStage()'s at the time+};+// The last session's marker, if it left one (then removed).+Previous takePrevious(const std::string& markerPath);++} // namespace xc::app::crashdiff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex 1d5b58f..5d10fbc 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -6,6 +6,8 @@// (the game's menu, gestures and controllers while streaming),// price_loop.cpp (store prices) and autoplay.cpp (the unattended tests).#include "app/autoplay.h"+#include "app/crash_guard.h"+#include "app/report.h"#include "app/ps5_app.h"#include "app/settings.h"#include "app/stream_screen.h"@@ -60,6 +62,27 @@ using namespace xc::app;namespace {std::unique_ptr<ui::ImageCache> g_images;+crash::Previous g_lastCrash;+std::string crashMarkerPath() { return platform::dataDir() + "/crash.marker"; }++// "Report a problem": the bug form's link, filled in, as a QR code. `what`+// is the error shown (empty from Settings); `previousSession` takes the log+// of the session that went down instead of this one.+void openReport(const std::string& what, bool previousSession, const std::string& heading) {+ std::string logText;+ platform::readFile(platform::dataDir() + "/xcloud.log", logText);+ std::vector<std::string> privateWords = {g_ui->gamertag()};+ for (int i = 0; i < input::kMaxPads; ++i) privateWords.push_back(input::padUserName(i));+ report::Info info;+ info.what = report::sanitize(what.empty() ? "Reported from Settings" : what, privateWords);+ info.title = what.empty() ? "Problem report" : info.what.substr(0, 70);+ info.release = XC_APP_VERSION;+ info.firmware = platform::firmwareVersion();+ info.log = report::sanitize(report::logExcerpt(logText, previousSession), privateWords);+ std::string url = report::issueUrl(info);+ XC_LOGI("report: QR code shown (%zu characters)", url.size());+ g_ui->showReport(url, heading);+}// Dead zone, trigger vibration and confirm button from g_settings.void applyControllerSettings() {@@ -137,6 +160,11 @@ int main(int argc, char** argv) {platform::init();log::setFile((platform::dataDir() + "/xcloud.log").c_str());XC_LOGI("=== PSBox Cloud Gaming starting ===");+ // Did the last session go down? (A crash leaves a marker; being closed+ // from the system's menu doesn't.) Offered as a report once signed in.+ g_lastCrash = crash::takePrevious(crashMarkerPath());+ if (g_lastCrash.found) XC_LOGW("the last session went down: %s (%s)", g_lastCrash.kind.c_str(), g_lastCrash.stage.c_str());+ crash::install(crashMarkerPath());loadAutoplay();// An update cut short: the old files went back, and the old eboot.bin// is the one to run.@@ -223,7 +251,25 @@ int main(int argc, char** argv) {unsigned padChecks = 0;uint64_t lightBarAt = 0;bool lightBarSet = false; // false from the menu/keyboard until the buttons are let go+ crash::startWatchdog(15000); // a main loop stuck for 15 s leaves a marker+ ui::Screen stageScreen = ui::Screen::Splash;for (;;) {+ crash::heartbeat();+ if (ui::Screen sc = g_ui->screen(); sc != stageScreen) {+ // What the app is doing, for a crash marker (the worker names+ // the stream itself).+ stageScreen = sc;+ static const char* const kNames[] = {"splash", "sign-in", "home", "game page", "launching",+ "streaming", "error", "settings", "updating"};+ size_t i = static_cast<size_t>(sc);+ if (sc != ui::Screen::Streaming && sc != ui::Screen::Launching && i < std::size(kNames)) crash::setStage(kNames[i]);+ // After a crash: its report, once the app is up again.+ if (g_lastCrash.found && (sc == ui::Screen::Home || sc == ui::Screen::Error)) {+ g_lastCrash.found = false;+ openReport("Closed unexpectedly: " + g_lastCrash.kind + " while " + g_lastCrash.stage, true,+ ui::tr(ui::Str::CrashedLastTime));+ }+ }if (g_restartWanted) {// After an update: the new version, started in place of this one.if (!g_autoplay.noRestart) platform::restartApp();@@ -427,6 +473,7 @@ int main(int argc, char** argv) {break;}case ui::Action::UpdateLater: skipOfferedUpdate(); break;+ case ui::Action::Report: openReport(ev.reportWhat, false, ui::tr(ui::Str::ReportProblem)); break;case ui::Action::None: break;}diff --git a/src/app/report.cpp b/src/app/report.cppnew file mode 100644index 0000000..5cbc80d--- /dev/null+++ b/src/app/report.cpp@@ -0,0 +1,146 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+#include "app/report.h"++#include <cctype>+#include <cstring>+#include <set>++namespace xc::app::report {++namespace {++constexpr const char* kForm =+ "https://github.com/RafaelNGP/xbox-cloud-gaming-ps5/issues/new?template=bug_report.yml";+constexpr const char* kSessionStart = "=== PSBox Cloud Gaming starting ===";++// A query value: unreserved characters and a few safe ones as they are,+// space as '+', the rest percent-encoded.+std::string encode(const std::string& s) {+ static const char* hex = "0123456789ABCDEF";+ std::string out;+ for (unsigned char c : s) {+ if (std::isalnum(c) || std::strchr("-_.~:/@!$'()*,;", c)) out += static_cast<char>(c);+ else if (c == ' ') out += '+';+ else out += '%', out += hex[c >> 4], out += hex[c & 15];+ }+ return out;+}++bool isTokenChar(char c) { return std::isalnum(static_cast<unsigned char>(c)) || c == '-' || c == '_' || c == '.' || c == '='; }++} // namespace++std::string sanitize(const std::string& text, const std::vector<std::string>& privateWords) {+ std::string s = text;+ for (const auto& w : privateWords) {+ if (w.size() < 3) continue;+ for (size_t at = s.find(w); at != std::string::npos; at = s.find(w, at + 6)) s.replace(at, w.size(), "<name>");+ }+ std::string out;+ for (size_t i = 0; i < s.size();) {+ // A token: "eyJ..." (JWT) or what follows "XBL3.0 x=".+ if (s.compare(i, 3, "eyJ") == 0 || s.compare(i, 9, "XBL3.0 x=") == 0) {+ size_t j = i + (s[i] == 'X' ? 9 : 3);+ while (j < s.size() && (isTokenChar(s[j]) || s[j] == ';')) ++j;+ out += "<token>";+ i = j;+ continue;+ }+ // An IPv4 address: four numbers with dots, not part of a longer number.+ if (std::isdigit(static_cast<unsigned char>(s[i])) && (i == 0 || !std::isalnum(static_cast<unsigned char>(s[i - 1])))) {+ size_t j = i;+ int parts = 0;+ while (parts < 4) {+ size_t k = j;+ while (k < s.size() && std::isdigit(static_cast<unsigned char>(s[k])) && k - j < 3) ++k;+ if (k == j) break;+ ++parts;+ j = k;+ if (parts < 4 && j < s.size() && s[j] == '.') ++j;+ else break;+ }+ if (parts == 4 && (j >= s.size() || !std::isdigit(static_cast<unsigned char>(s[j])))) {+ out += "<ip>";+ i = j;+ continue;+ }+ }+ // A long hexadecimal id (24+ digits).+ if (std::isxdigit(static_cast<unsigned char>(s[i])) && (i == 0 || !std::isalnum(static_cast<unsigned char>(s[i - 1])))) {+ size_t j = i;+ while (j < s.size() && std::isxdigit(static_cast<unsigned char>(s[j]))) ++j;+ if (j - i >= 24 && (j >= s.size() || !std::isalnum(static_cast<unsigned char>(s[j])))) {+ out += "<id>";+ i = j;+ continue;+ }+ }+ out += s[i++];+ }+ // E-mail addresses: the word around an '@' with a dot after it.+ for (size_t at = out.find('@'); at != std::string::npos; at = out.find('@', at + 1)) {+ size_t a = at, b = at + 1;+ while (a > 0 && (isTokenChar(out[a - 1]) || out[a - 1] == '+')) --a;+ while (b < out.size() && isTokenChar(out[b])) ++b;+ if (a < at && out.find('.', at) < b) {+ out.replace(a, b - a, "<email>");+ at = a;+ }+ }+ return out;+}++std::string logExcerpt(const std::string& logText, bool previousSession, size_t lastLines) {+ // The sessions' starts; the one wanted runs to the next (or the end).+ std::vector<size_t> starts;+ for (size_t at = logText.find(kSessionStart); at != std::string::npos; at = logText.find(kSessionStart, at + 1)) {+ size_t lineStart = logText.rfind('\n', at);+ starts.push_back(lineStart == std::string::npos ? 0 : lineStart + 1);+ }+ if (starts.empty()) starts.push_back(0);+ size_t idx = starts.size() - 1;+ if (previousSession) {+ if (starts.size() < 2) return {};+ idx = starts.size() - 2;+ }+ size_t from = starts[idx], to = idx + 1 < starts.size() ? starts[idx + 1] : logText.size();+ std::vector<std::string> lines;+ for (size_t at = from; at < to;) {+ size_t nl = logText.find('\n', at);+ if (nl == std::string::npos || nl > to) nl = to;+ if (nl > at) lines.push_back(logText.substr(at, nl - at));+ at = nl + 1;+ }+ // The first line (the version's start), warnings and errors, and the+ // last lines; in order, each once, each at most 160 characters.+ std::set<size_t> keep;+ for (size_t i = 0; i < lines.size(); ++i)+ if (i == 0 || lines[i].find("[E]") != std::string::npos || lines[i].find("[W]") != std::string::npos ||+ i + lastLines >= lines.size())+ keep.insert(i);+ std::string out;+ size_t last = 0;+ for (size_t i : keep) {+ if (!out.empty() && i > last + 1) out += "...\n";+ out += lines[i].substr(0, 160) + "\n";+ last = i;+ }+ return out;+}++std::string issueUrl(const Info& info, size_t maxLength) {+ std::string head = std::string(kForm) + "&title=" + encode(info.title) + "&what=" + encode(info.what) ++ "&release=" + encode(info.release) + "&firmware=" + encode(info.firmware) + "&log=";+ // The log's end matters most: whole lines are dropped from its start+ // until the link fits.+ std::string log = info.log;+ for (;;) {+ std::string url = head + encode(log);+ if (url.size() <= maxLength || log.empty()) return url.size() <= maxLength ? url : head;+ size_t nl = log.find('\n', log.compare(0, 4, "...\n") == 0 ? 4 : 0);+ log = nl == std::string::npos ? std::string() : "...\n" + log.substr(nl + 1);+ }+}++} // namespace xc::app::reportdiff --git a/src/app/report.h b/src/app/report.hnew file mode 100644index 0000000..d69a426--- /dev/null+++ b/src/app/report.h@@ -0,0 +1,37 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+// "Report a problem": a link to the GitHub bug form, filled in, for a QR+// code (the phone opens it, the user reviews and sends it; no token in the+// app, and it works with the PS5 offline). A QR code holds only so much, so+// the log goes in as an excerpt: its error / warning lines and its last+// lines, filtered for private data.+#pragma once++#include <string>+#include <vector>++namespace xc::app::report {++struct Info {+ std::string title; // the issue's title+ std::string what; // what happened (the error shown, or the crash)+ std::string release; // app version+ std::string firmware; // PS5 system software, when known+ std::string log; // logExcerpt()'s+};++// The bug form's link, at most `maxLength` characters: the log is cut from+// its start (its end matters most) to fit.+std::string issueUrl(const Info& info, size_t maxLength = 1800);++// From the whole log (sessions start with "=== PSBox Cloud Gaming starting+// ==="): the current session's or, with `previousSession`, the one before+// (the session that went down); its [E] / [W] lines and last lines.+std::string logExcerpt(const std::string& logText, bool previousSession, size_t lastLines = 20);++// Private data out: `privateWords` (gamertag, user names) as <name>, IPv4+// addresses as <ip>, tokens as <token>, e-mail addresses as <email>, long+// hexadecimal ids as <id>.+std::string sanitize(const std::string& text, const std::vector<std::string>& privateWords);++} // namespace xc::app::reportdiff --git a/src/app/worker.cpp b/src/app/worker.cppindex 2304dab..8a3d163 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -4,6 +4,7 @@// playing a title (queue -> /connect -> Provisioned -> StreamPlayer). It// owns AuthManager and the GssvClients and does all the network work.#include "app/autoplay.h"+#include "app/crash_guard.h"#include "app/library.h"#include "app/ps5_app.h"#include "app/stream_player.h"@@ -56,7 +57,11 @@ bool g_gameClosedOnServer = false;std::map<std::string, std::string> g_regionFallback;// Streams until the player ends or the user leaves; returns a status line.+// The cloud title being played, for crash markers (set by play()).+std::string g_stageTitle;+std::string stream(xcloud::GssvClient& gssv) {+ crash::setStage(gssv.isHome() ? "streaming own Xbox" : ("streaming " + g_stageTitle).c_str());g_gameClosedOnServer = false;app::StreamPlayer player(gssv);if (g_autoplay.dump) player.dumpVideo(platform::dataDir() + "/stream.aus", 20);@@ -260,6 +265,9 @@ std::string play(auth::AuthManager& am, xcloud::GssvClient& gssv, const ui::GameXC_LOGI("stream settings: %s%s, region %s, locale %s", res.c_str(),hasCustom ? " (per-game)" : "", region ? region->name.c_str() : "?", ui::gameLocale());}+ // For a crash marker: what is being started (a console's id stays out).+ g_stageTitle = game.titleId;+ crash::setStage(gssv.isHome() ? "starting own Xbox" : ("starting " + game.titleId).c_str());if (!gssv.startSession(game.titleId, ui::gameLocale(), err)) return err;if (game.heroUrl.empty() && !game.productId.empty()) {// Picked before the background hydration reached it: fetch the herodiff --git a/src/platform/host/platform_host.cpp b/src/platform/host/platform_host.cppindex 7b3c65a..8430fe5 100644--- a/src/platform/host/platform_host.cpp+++ b/src/platform/host/platform_host.cpp@@ -94,4 +94,6 @@ KeyboardStatus pollSystemKeyboard(std::string&) { return KeyboardStatus::Closed;bool restartApp() { return false; }+std::string firmwareVersion() { return {}; }+} // namespace xc::platformdiff --git a/src/platform/platform.h b/src/platform/platform.hindex 0cc524d..46d7223 100644--- a/src/platform/platform.h+++ b/src/platform/platform.h@@ -66,6 +66,9 @@ KeyboardStatus pollSystemKeyboard(std::string& text);// when it can't (false; the host never can).bool restartApp();+// The console's system software ("13.00"); empty where unknown.+std::string firmwareVersion();+bool readFile(const std::string& path, std::string& out);bool writeFileAtomic(const std::string& path, const std::string& data);diff --git a/src/platform/ps5/platform_ps5.cpp b/src/platform/ps5/platform_ps5.cppindex 7ccc61d..481de88 100644--- a/src/platform/ps5/platform_ps5.cpp+++ b/src/platform/ps5/platform_ps5.cpp@@ -17,6 +17,12 @@#include <sys/socket.h>extern "C" {+struct SceKernelSwVersion {+ uint64_t size;+ char versionString[0x1C];+ uint32_t version;+};+int sceKernelGetSystemSwVersion(SceKernelSwVersion* version);int sceSystemServiceLoadExec(const char* path, char* const argv[]);int sceKernelSendNotificationRequest(int device, void* request, size_t size, int blocking);int sceNetInit(void);@@ -119,6 +125,16 @@ bool restartApp() {return false;}+std::string firmwareVersion() {+ SceKernelSwVersion v{};+ v.size = sizeof v;+ if (sceKernelGetSystemSwVersion(&v) != 0) return {};+ v.versionString[sizeof v.versionString - 1] = 0;+ std::string s = v.versionString;+ while (!s.empty() && s.front() == ' ') s.erase(0, 1);+ return s;+}+void notify(const std::string& text) { notify(text, text); }void notify(const std::string& text, const std::string& forLog) {diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex d472585..369fad3 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -253,6 +253,24 @@ void AppUi::showSignIn(const std::string& code, const std::string& url) {dirty_ = true;}+std::string AppUi::gamertag() const {+ std::lock_guard<std::mutex> lock(mutex_);+ return gamertag_;+}++void AppUi::showReport(const std::string& url, const std::string& heading) {+ std::lock_guard<std::mutex> lock(mutex_);+ reportOpen_ = true;+ reportUrl_ = url;+ reportHeading_ = heading;+ dirty_ = true;+}++bool AppUi::reportOpen() const {+ std::lock_guard<std::mutex> lock(mutex_);+ return reportOpen_;+}+void AppUi::setProfile(const std::string& gamertag, const std::string& gamerpicUrl, const std::string& gamerscore) {std::lock_guard<std::mutex> lock(mutex_);gamertag_ = gamertag;@@ -1869,6 +1887,10 @@ void AppUi::handleGameSettings(const NavInput& in, UiEvent& ev) {UiEvent AppUi::handle(const NavInput& in) {std::lock_guard<std::mutex> lock(mutex_);UiEvent ev;+ if (reportOpen_) { // the report's QR code: Circle (or Cross) closes it+ if (in.back || in.accept) reportOpen_ = false, dirty_ = true;+ return ev;+ }if (screen_ == Screen::Home && updatePrompt_) {// The update pop-up has the pad: left / right, Cross picks, Circle is "Not now".if (in.left || in.right) promptFocus_ = 1 - promptFocus_, dirty_ = true;@@ -1926,6 +1948,8 @@ UiEvent AppUi::handle(const NavInput& in) {dirty_ = true;ev.action = Action::SettingsChanged;ev.settings = settings_;+ } else if (in.triangle) {+ ev.action = Action::Report; // "Report a problem"}break;case Screen::Details:@@ -1968,6 +1992,10 @@ UiEvent AppUi::handle(const NavInput& in) {} else if (in.accept) {ev.action = Action::Retry;}+ if (in.triangle) { // "Report a problem", with the error shown+ ev.action = Action::Report;+ ev.reportWhat = error_;+ }break;default: break;}@@ -2254,9 +2282,10 @@ namespace {// A QR code of `url` on a white card whose top-right corner is (right, top),// about `target` px of code; the card's rect (empty when it can't be encoded).-Rect drawQr(Canvas& c, const std::string& url, int right, int top, int target) {+Rect drawQr(Canvas& c, const std::string& url, int right, int top, int target,+ qrcodegen_Ecc ecc = qrcodegen_Ecc_MEDIUM) {uint8_t qr[qrcodegen_BUFFER_LEN_MAX], tmp[qrcodegen_BUFFER_LEN_MAX];- if (!qrcodegen_encodeText(url.c_str(), tmp, qr, qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX,+ if (!qrcodegen_encodeText(url.c_str(), tmp, qr, ecc, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX,qrcodegen_Mask_AUTO, true))return {};int n = qrcodegen_getSize(qr);@@ -2977,9 +3006,10 @@ void AppUi::drawError(Canvas& c) {y += 38;}if (!errorGame_.titleId.empty())- drawHints(c, {{kIconCross, tr(Str::TryAgain)}, {kIconCircle, tr(Str::Back)}});+ drawHints(c, {{kIconCross, tr(Str::TryAgain)}, {kIconTriangle, tr(Str::ReportProblem)}, {kIconCircle, tr(Str::Back)}});else- drawHints(c, {{kIconCross, tr(Str::TryAgain)}, {kIconTouchpad, tr(Str::HoldSignOut)}});+ drawHints(c, {{kIconCross, tr(Str::TryAgain)}, {kIconTriangle, tr(Str::ReportProblem)},+ {kIconTouchpad, tr(Str::HoldSignOut)}});}void AppUi::drawSettings(Canvas& c) {@@ -3091,8 +3121,36 @@ void AppUi::drawSettings(Canvas& c) {}drawHints(c, {{kIconCross, tr(Str::Select)}, {kIconCircle, tr(Str::Back)}});} else {- drawHints(c, {{kIconCross, tr(Str::Change)}, {kIconCircle, tr(Str::Back)}});+ drawHints(c, {{kIconCross, tr(Str::Change)}, {kIconTriangle, tr(Str::ReportProblem)}, {kIconCircle, tr(Str::Back)}});+ }+}++void AppUi::drawReport(Canvas& c) {+ // A panel over the screen: the heading and what the QR code does on the+ // left, the code on the right (dense: about 1.8 KB, so large).+ c.fillRect({0, 0, kW, kH}, rgba(0, 0, 0, 170));+ constexpr int kPanelW = 1500, kPanelH = 720;+ Rect panel{(kW - kPanelW) / 2, (kH - kPanelH) / 2 - 30, kPanelW, kPanelH};+ c.fillRect({panel.x + 8, panel.y + 12, panel.w, panel.h}, rgba(0, 0, 0, 120), 26);+ c.fillRect(panel, kPanel, 24);+ c.strokeRect(panel, rgba(255, 255, 255, 50), 2, 24);+ Rect qr = drawQr(c, reportUrl_, panel.x + panel.w - 48, panel.y + 48, 600, qrcodegen_Ecc_LOW);+ int textW = (qr.w ? qr.x : panel.x + panel.w) - panel.x - 112;+ int y = panel.y + 56;+ for (const auto& line : fonts_.bold.wrap(reportHeading_, 40, textW, 3)) {+ fonts_.bold.draw(c, line, panel.x + 56, y, 40, kWhite);+ y += 54;}+ y += 24;+ for (Str s : {Str::ReportScan, Str::ReportIncludes}) {+ for (const auto& line : fonts_.regular.wrap(tr(s), 26, textW, 4)) {+ fonts_.regular.draw(c, line, panel.x + 56, y, 26, kGray);+ y += 38;+ }+ y += 20;+ }+ c.fillRect({0, kH - 80, kW, 80}, kBg);+ drawHints(c, {{kIconCircle, tr(Str::Back)}});}void AppUi::drawUpdatePrompt(Canvas& c) {@@ -3466,6 +3524,7 @@ void AppUi::render(Canvas& c, uint64_t nowMs) {case Screen::Streaming: break;}if (screen_ == Screen::Home && updatePrompt_) drawUpdatePrompt(c);+ if (reportOpen_) drawReport(c);if ((screen_ == Screen::Home && !updatePrompt_) || screen_ == Screen::Error) drawSignOutHold(c, nowMs);if (!toast_.empty()) animating_ = true; // to expire it}diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 6ca5b99..caa7ddf 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -123,7 +123,8 @@ constexpr int kSettingRows = 8; // language, resolution, region, dead zone, tri// the answer to the update pop-up, or Updates in Settings.enum class Action {None, Play, SignOut, Retry, CancelLaunch, SettingsChanged, PrefsChanged, ConsolesShown, UpdateNow, UpdateLater,- GameSettingsChanged+ GameSettingsChanged,+ Report // "Report a problem" (Triangle on an error or in Settings): reportWhat is the error shown};// How "Your games" is sorted (R3).@@ -144,6 +145,7 @@ struct UiEvent {// PrefsChanged: hidden games (product ids) and the "Your games" order.std::vector<std::string> hidden;LibrarySort librarySort = LibrarySort::Recent;+ std::string reportWhat; // Report: the error on screen (empty from Settings)};// "SOUTHCENTRALUS" -> "South Central US".@@ -160,6 +162,11 @@ public:void showSignIn(const std::string& code, const std::string& url);// The signed-in account, top right; `gamerscore` (digits) under the name.void setProfile(const std::string& gamertag, const std::string& gamerpicUrl, const std::string& gamerscore = {});+ std::string gamertag() const; // for keeping it out of reports+ // "Report a problem": a QR code of `url` (the GitHub bug form, filled+ // in) over whatever is on screen, with `heading`; Circle closes it.+ void showReport(const std::string& url, const std::string& heading);+ bool reportOpen() const;// Replaces the rows, keeping the focus on the same game when possible.void setRows(std::vector<GameRow> rows);// "Your games": the account's games, then those to buy; `known` false@@ -336,6 +343,7 @@ private:void drawError(Canvas& c);void drawSettings(Canvas& c);void drawUpdatePrompt(Canvas& c);+ void drawReport(Canvas& c);// The light bar's colour picker (Settings > Light bar > Custom colour).void openColourPicker(int previousMode);void handleColourPicker(const NavInput& in);@@ -426,6 +434,8 @@ private:std::map<std::string, DetailInfo> detailInfo_; // fetched on demand, by product idstd::string updateCurrent_, updateAvailable_;bool updateChecking_ = false;+ bool reportOpen_ = false; // the report's QR code is up+ std::string reportUrl_, reportHeading_;bool updatePrompt_ = false; // the pop-up is up (on the home screen)int promptFocus_ = 0; // 0 Update now, 1 Not nowstd::string updatingTo_, updateStatus_;diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex c64fc56..fca31a4 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -241,6 +241,10 @@ constexpr Column kEnglish = {"Audio output", // MenuAudioOutput"TV", // AudioRouteTv"DualSense Speaker", // AudioRoutePad+ "Report a problem", // ReportProblem+ "Scan it with your phone: GitHub's bug form opens, filled in. You review it before sending it.", // ReportScan+ "It includes the app's version, the error and lines of its log, without personal data.", // ReportIncludes+ "PSBox closed unexpectedly last time", // CrashedLastTime};constexpr Column kPortugueseBR = {@@ -452,6 +456,10 @@ constexpr Column kPortugueseBR = {"Saída de áudio","TV","Alto-falante do controle",+ "Relatar problema",+ "Escaneie com o celular: o formulário de bug do GitHub abre preenchido. Você revisa antes de enviar.",+ "Inclui a versão do app, o erro e linhas do log, sem dados pessoais.",+ "O PSBox fechou inesperadamente da última vez",};constexpr Column kSpanish = {@@ -663,6 +671,10 @@ constexpr Column kSpanish = {"Salida de audio","TV","Altavoz del mando",+ "Informar de un problema",+ "Escanéalo con el móvil: se abre el formulario de errores de GitHub, ya rellenado. Lo revisas antes de enviarlo.",+ "Incluye la versión de la app, el error y líneas del registro, sin datos personales.",+ "PSBox se cerró inesperadamente la última vez",};constexpr Column kFrench = {@@ -874,6 +886,10 @@ constexpr Column kFrench = {"Sortie audio","TV","Haut-parleur de la manette",+ "Signaler un problème",+ "Scannez-le avec votre téléphone : le formulaire de bug de GitHub s'ouvre, déjà rempli. Vous le relisez avant de l'envoyer.",+ "Il contient la version de l'app, l'erreur et des lignes du journal, sans données personnelles.",+ "PSBox s'est fermé de façon inattendue la dernière fois",};constexpr Column kGerman = {@@ -1085,6 +1101,10 @@ constexpr Column kGerman = {"Audioausgabe","TV","Controller-Lautsprecher",+ "Problem melden",+ "Mit dem Handy scannen: Das Fehlerformular auf GitHub öffnet sich ausgefüllt. Du prüfst es vor dem Senden.",+ "Enthalten sind die App-Version, der Fehler und Zeilen des Logs, ohne persönliche Daten.",+ "PSBox wurde beim letzten Mal unerwartet beendet",};constexpr Column kItalian = {@@ -1296,6 +1316,10 @@ constexpr Column kItalian = {"Uscita audio","TV","Altoparlante del controller",+ "Segnala un problema",+ "Inquadralo con il telefono: si apre il modulo dei bug di GitHub già compilato. Lo controlli prima di inviarlo.",+ "Include la versione dell'app, l'errore e righe del log, senza dati personali.",+ "PSBox si è chiuso inaspettatamente l'ultima volta",};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 8f44378..95949c3 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -218,6 +218,10 @@ enum class Str {MenuAudioOutput, // "Audio output"AudioRouteTv, // "TV"AudioRoutePad, // "DualSense Speaker"+ ReportProblem, // button hint: opens the report's QR code+ ReportScan, // the report panel+ ReportIncludes,+ CrashedLastTime, // the report panel's heading after a crashCount};diff --git a/tests/test_main.cpp b/tests/test_main.cppindex 118d135..d35d457 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -5,6 +5,8 @@#include "app/settings.h"#include "app/update_check.h"#include "app/updater.h"+#include "app/crash_guard.h"+#include "app/report.h"#include "media/audio_encoder.h"#include "input/tuning.h"#include "net/http.h"@@ -21,6 +23,9 @@#include <cmath>#include <cstdio>+#include <csignal>+#include <sys/wait.h>+#include <unistd.h>#include <cstdlib>#include <vector>#include <string>@@ -506,6 +511,61 @@ static void testControllerTuning() {CHECK(triggerCommand(38, 0, 1, 2, true, 0) == still); // vibration off: only the weight}+static void testReport() {+ using namespace xc::app::report;+ // Private data out.+ // Made-up values (the tokens put together here, so the source holds none).+ const std::string jwt = std::string("ey") + "JmYWtlIjoidG9rZW4ifQ" + "QUJDREVGR0hJSktMTU5PUA.abc";+ const std::string xbl = std::string("XBL3.0 x=") + "12345;" + "ey" + "Jfake";+ std::string s = sanitize("signed in as SomePlayer from 203.0.113.7 token " + jwt + " auth " + xbl ++ " mail [email protected] id 0123456789abcdef0123456789abcdef ok",+ {"SomePlayer"});+ CHECK(s.find("SomePlayer") == std::string::npos && s.find("<name>") != std::string::npos);+ CHECK(s.find("203.0.113") == std::string::npos && s.find("<ip>") != std::string::npos);+ CHECK(s.find("ey" "J") == std::string::npos && s.find("12345") == std::string::npos && s.find("<token>") != std::string::npos);+ CHECK(s.find("example.com") == std::string::npos && s.find("<email>") != std::string::npos);+ CHECK(s.find("0123456789abcdef0123") == std::string::npos && s.find("<id>") != std::string::npos);+ CHECK(sanitize("v0.9.5 at 1080p, 60 fps, 9 ms", {}) == "v0.9.5 at 1080p, 60 fps, 9 ms"); // nothing private++ // The excerpt: the session wanted, its warnings / errors and last lines.+ std::string log = "10:00 [I] === PSBox Cloud Gaming starting ===\n10:00 [E] old error\n"+ "11:00 [I] === PSBox Cloud Gaming starting ===\n";+ for (int i = 0; i < 40; ++i) log += "11:01 [I] line " + std::to_string(i) + "\n";+ log += "11:02 [W] a warning\n11:03 [I] tail\n";+ std::string now = logExcerpt(log, false, 5), before = logExcerpt(log, true, 5);+ CHECK(now.find("old error") == std::string::npos && now.find("a warning") != std::string::npos);+ CHECK(now.find("line 39") != std::string::npos && now.find("line 3\n") == std::string::npos && now.find("...") != std::string::npos);+ CHECK(before.find("old error") != std::string::npos && before.find("line") == std::string::npos);+ CHECK(logExcerpt("no sessions\n", true).empty());++ // The link fits the QR code; the log keeps its end.+ Info info{"Error: certificates", "TLS setup failed", "0.9.6", "13.00", ""};+ for (int i = 0; i < 200; ++i) info.log += "12:00 [I] a long line of the log number " + std::to_string(i) + "\n";+ std::string url = issueUrl(info, 1800);+ CHECK(url.size() <= 1800 && url.find("template=bug_report.yml") != std::string::npos);+ CHECK(url.find("number+199") != std::string::npos && url.find("number+0%0A") == std::string::npos);+ CHECK(url.find("release=0.9.6") != std::string::npos && url.find("title=Error:+certificates") != std::string::npos);+}++static void testCrashGuard() {+ // A crash in a child process leaves the marker with its stage.+ std::string marker = "/tmp/xcloud-tests-crash.marker";+ std::remove(marker.c_str());+ pid_t pid = fork();+ if (pid == 0) {+ xc::app::crash::install(marker);+ xc::app::crash::setStage("streaming TEST");+ std::raise(SIGSEGV);+ _exit(0);+ }+ int status = 0;+ waitpid(pid, &status, 0);+ CHECK(WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV); // still dies of it+ auto prev = xc::app::crash::takePrevious(marker);+ CHECK(prev.found && prev.kind == "signal 11 (SIGSEGV)" && prev.stage == "streaming TEST");+ CHECK(!xc::app::crash::takePrevious(marker).found); // taken once+}+static void testBuiltinCa() {// A missing bundle (an incomplete copy of the app): the copy built in.CHECK(xc::net::initTls("/nonexistent/cacert.pem"));@@ -556,6 +616,8 @@ static void testAudioEncoder() {}int main() {+ testReport();+ testCrashGuard();testBuiltinCa();testAudioEncoder();testAutoDeband();