Android: Don't let RetroAchievements override onPause

When Android sends Dolphin to the background, emulation *must* pause,
otherwise emulation continues running and continues outputting audio to
the user. RetroAchievements mustn't be allowed to override it.
This commit is contained in:
JosJuice 2025-07-26 19:48:52 +02:00
commit c3be049571
6 changed files with 10 additions and 8 deletions

View file

@ -362,7 +362,7 @@ public final class NativeLibrary
/** /**
* Pauses emulation. * Pauses emulation.
*/ */
public static native void PauseEmulation(); public static native void PauseEmulation(boolean overrideAchievementRestrictions);
/** /**
* Stops emulation. * Stops emulation.

View file

@ -455,7 +455,7 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
MENU_ACTION_REFRESH_WIIMOTES -> NativeLibrary.RefreshWiimotes() MENU_ACTION_REFRESH_WIIMOTES -> NativeLibrary.RefreshWiimotes()
MENU_ACTION_PAUSE_EMULATION -> { MENU_ACTION_PAUSE_EMULATION -> {
hasUserPausedEmulation = true hasUserPausedEmulation = true
NativeLibrary.PauseEmulation() NativeLibrary.PauseEmulation(false)
} }
MENU_ACTION_UNPAUSE_EMULATION -> { MENU_ACTION_UNPAUSE_EMULATION -> {

View file

@ -109,7 +109,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
override fun onPause() { override fun onPause() {
if (NativeLibrary.IsRunningAndUnpaused() && !NativeLibrary.IsShowingAlertMessage()) { if (NativeLibrary.IsRunningAndUnpaused() && !NativeLibrary.IsShowingAlertMessage()) {
Log.debug("[EmulationFragment] Pausing emulation.") Log.debug("[EmulationFragment] Pausing emulation.")
NativeLibrary.PauseEmulation() NativeLibrary.PauseEmulation(true)
} }
super.onPause() super.onPause()
} }

View file

@ -271,10 +271,12 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmula
Core::SetState(Core::System::GetInstance(), Core::State::Running); Core::SetState(Core::System::GetInstance(), Core::State::Running);
} }
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(JNIEnv*, jclass) JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(
JNIEnv*, jclass, bool override_achievement_restrictions)
{ {
HostThreadLock guard; HostThreadLock guard;
Core::SetState(Core::System::GetInstance(), Core::State::Paused); Core::SetState(Core::System::GetInstance(), Core::State::Paused, true,
override_achievement_restrictions);
} }
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv*, jclass) JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv*, jclass)

View file

@ -672,7 +672,7 @@ static void EmuThread(Core::System& system, std::unique_ptr<BootParameters> boot
// Set or get the running state // Set or get the running state
void SetState(Core::System& system, State state, bool report_state_change, void SetState(Core::System& system, State state, bool report_state_change,
bool initial_execution_state) bool override_achievement_restrictions)
{ {
// State cannot be controlled until the CPU Thread is operational // State cannot be controlled until the CPU Thread is operational
if (s_state.load() != State::Running) if (s_state.load() != State::Running)
@ -682,7 +682,7 @@ void SetState(Core::System& system, State state, bool report_state_change,
{ {
case State::Paused: case State::Paused:
#ifdef USE_RETRO_ACHIEVEMENTS #ifdef USE_RETRO_ACHIEVEMENTS
if (!initial_execution_state && !AchievementManager::GetInstance().CanPause()) if (!override_achievement_restrictions && !AchievementManager::GetInstance().CanPause())
return; return;
#endif // USE_RETRO_ACHIEVEMENTS #endif // USE_RETRO_ACHIEVEMENTS
// NOTE: GetState() will return State::Paused immediately, even before anything has // NOTE: GetState() will return State::Paused immediately, even before anything has

View file

@ -146,7 +146,7 @@ bool WantsDeterminism();
// [NOT THREADSAFE] For use by Host only // [NOT THREADSAFE] For use by Host only
void SetState(Core::System& system, State state, bool report_state_change = true, void SetState(Core::System& system, State state, bool report_state_change = true,
bool initial_execution_state = false); bool override_achievement_restrictions = false);
State GetState(Core::System& system); State GetState(Core::System& system);
void SaveScreenShot(); void SaveScreenShot();