From ecdc7940f4e628b6f254a8f73d82e2c205bac350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 14 May 2024 00:02:59 +0200 Subject: [PATCH 1/2] Android: Fix issue where shortcuts wouldn't override the currently running game. --- UI/GameInfoCache.cpp | 2 +- UI/GameInfoCache.h | 4 ++++ android/jni/app-android.cpp | 16 ++++++++++++---- .../src/org/ppsspp/ppsspp/NativeActivity.java | 9 +++++++++ .../src/org/ppsspp/ppsspp/PpssppActivity.java | 4 +++- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 98eedf05cd..9c7a45b2a2 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -456,7 +456,7 @@ public: // Mark everything requested as done, so std::unique_lock lock(info_->lock); info_->MarkReadyNoLock(flags_); - ERROR_LOG(LOADER, "Failed getting game info."); + ERROR_LOG(LOADER, "Failed getting game info for %s", info_->GetFilePath().ToVisualString().c_str()); return; } diff --git a/UI/GameInfoCache.h b/UI/GameInfoCache.h index 589882a3dd..b7f0ed5510 100644 --- a/UI/GameInfoCache.h +++ b/UI/GameInfoCache.h @@ -109,6 +109,10 @@ public: std::string GetTitle(); void SetTitle(const std::string &newTitle); + const Path &GetFilePath() const { + return filePath_; + } + bool Ready(GameInfoFlags flags) { std::unique_lock guard(lock); // Avoid the operator, we want to check all the bits. diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index f49e51529b..c4c4d36e10 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -791,6 +791,7 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init std::vector temp; args.push_back(app_name.c_str()); if (!shortcut_param.empty()) { + EARLY_LOG("NativeInit shortcut param %s", shortcut_param.c_str()); parse_args(temp, shortcut_param); for (const auto &arg : temp) { args.push_back(arg.c_str()); @@ -799,7 +800,7 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init NativeInit((int)args.size(), &args[0], user_data_path.c_str(), externalStorageDir.c_str(), cacheDir.c_str()); - // In debug mode, don't allow creating software Vulkan devices (reject by VulkaMaybeAvailable). + // In debug mode, don't allow creating software Vulkan devices (reject by VulkanMaybeAvailable). // Needed for #16931. #ifdef NDEBUG if (!VulkanMayBeAvailable()) { @@ -1321,9 +1322,9 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_accelerometer(JNIEnv *, NativeAccelerometer(x, y, z); } -extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessageFromJava(JNIEnv *env, jclass, jstring message, jstring param) { - std::string msg = GetJavaString(env, message); - std::string prm = GetJavaString(env, param); +extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessageFromJava(JNIEnv *env, jclass, jstring jmessage, jstring jparam) { + std::string msg = GetJavaString(env, jmessage); + std::string prm = GetJavaString(env, jparam); // A bit ugly, see InputDeviceState.java. static InputDeviceID nextInputDeviceID = DEVICE_ID_ANY; @@ -1366,6 +1367,13 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_sendMessageFromJava(JNI System_PostUIMessage(UIMessage::POWER_SAVING, prm); } else if (msg == "exception") { g_OSD.Show(OSDType::MESSAGE_ERROR, std::string("Java Exception"), prm, 10.0f); + } else if (msg == "shortcutParam") { + if (prm.empty()) { + WARN_LOG(SYSTEM, "shortcutParam empty"); + return; + } + INFO_LOG(SYSTEM, "shortcutParam received: %s", prm.c_str()); + System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, StripQuotes(prm)); } else { ERROR_LOG(SYSTEM, "Got unexpected message from Java, ignoring: %s / %s", msg.c_str(), prm.c_str()); } diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index ecedbf2c3e..8061f7426d 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -443,6 +443,7 @@ public abstract class NativeActivity extends Activity { String languageRegion = Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry(); String shortcut = overrideShortcutParam == null ? shortcutParam : overrideShortcutParam; overrideShortcutParam = null; + shortcutParam = null; NativeApp.audioConfig(optimalFramesPerBuffer, optimalSampleRate); NativeApp.init(model, deviceType, languageRegion, apkFilePath, dataDir, extStorageDir, externalFilesDir, nativeLibDir, additionalStorageDirs, cacheDir, shortcut, Build.VERSION.SDK_INT, Build.BOARD); @@ -594,6 +595,7 @@ public abstract class NativeActivity extends Activity { // whether to start at 1x or 2x. sizeManager.updateDisplayMeasurements(); + boolean wasInitialized = initialized; if (!initialized) { Initialize(); initialized = true; @@ -661,6 +663,13 @@ public abstract class NativeActivity extends Activity { Log.i(TAG, "setcontentview after"); startRenderLoopThread(); } + + if (shortcutParam != null && shortcutParam.length() > 0) { + Log.i(TAG, "Got shortcutParam in onCreate on secondary run: " + shortcutParam); + // Make sure we only send it once. + NativeApp.sendMessageFromJava("shortcutParam", shortcutParam); + shortcutParam = null; + } } @Override diff --git a/android/src/org/ppsspp/ppsspp/PpssppActivity.java b/android/src/org/ppsspp/ppsspp/PpssppActivity.java index d661c887d8..397731140a 100644 --- a/android/src/org/ppsspp/ppsspp/PpssppActivity.java +++ b/android/src/org/ppsspp/ppsspp/PpssppActivity.java @@ -99,7 +99,9 @@ public class PpssppActivity extends NativeActivity { if (data != null) { String path = data.toString(); Log.i(TAG, "Found Shortcut Parameter in data: " + path); - super.setShortcutParam("\"" + path.replace("\\", "\\\\").replace("\"", "\\\"") + "\""); + String escaped = "\"" + path.replace("\\", "\\\\").replace("\"", "\\\"") + "\""; + Log.i(TAG, "Escaped: " + escaped); + super.setShortcutParam(escaped); // Toast.makeText(getApplicationContext(), path, Toast.LENGTH_SHORT).show(); } else { String param = getIntent().getStringExtra(SHORTCUT_EXTRA_KEY); From dadc37cb9b09ab8ee0d6d5590895bdc74b9e2749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 14 May 2024 00:04:40 +0200 Subject: [PATCH 2/2] EmuScreen: If a requested-to-boot game is already running, ignore the request. --- UI/EmuScreen.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index eafa4c9fde..a06b1c60ef 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -537,6 +537,11 @@ void EmuScreen::sendMessage(UIMessage message, const char *value) { return; } } else if (message == UIMessage::REQUEST_GAME_BOOT) { + // TODO: Ignore or not if it's the same game that's already running? + if (gamePath_ == Path(value)) { + WARN_LOG(LOADER, "Game already running, ignoring"); + return; + } const char *ext = strrchr(value, '.'); if (ext != nullptr && !strcmp(ext, ".ppst")) { SaveState::Load(Path(value), -1, &AfterStateBoot);