Skip to content

Commit

Permalink
Merge pull request #19142 from hrydgard/fix-shortcut-launch
Browse files Browse the repository at this point in the history
Android: Fix issue where shortcuts wouldn't override the currently running game.
  • Loading branch information
hrydgard committed May 14, 2024
2 parents 8fdb6e1 + dadc37c commit dbcac0e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
5 changes: 5 additions & 0 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion UI/GameInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ class GameInfoWorkItem : public Task {
// Mark everything requested as done, so
std::unique_lock<std::mutex> 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;
}

Expand Down
4 changes: 4 additions & 0 deletions UI/GameInfoCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class GameInfo {
std::string GetTitle();
void SetTitle(const std::string &newTitle);

const Path &GetFilePath() const {
return filePath_;
}

bool Ready(GameInfoFlags flags) {
std::unique_lock<std::mutex> guard(lock);
// Avoid the operator, we want to check all the bits.
Expand Down
16 changes: 12 additions & 4 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init
std::vector<std::string> 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());
Expand All @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
9 changes: 9 additions & 0 deletions android/src/org/ppsspp/ppsspp/NativeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ public void Initialize() {
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);
Expand Down Expand Up @@ -594,6 +595,7 @@ public void onCreate(Bundle savedInstanceState) {
// whether to start at 1x or 2x.
sizeManager.updateDisplayMeasurements();

boolean wasInitialized = initialized;
if (!initialized) {
Initialize();
initialized = true;
Expand Down Expand Up @@ -661,6 +663,13 @@ public void onCreate(Bundle savedInstanceState) {
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
Expand Down
4 changes: 3 additions & 1 deletion android/src/org/ppsspp/ppsspp/PpssppActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public void run() {
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);
Expand Down

0 comments on commit dbcac0e

Please sign in to comment.