mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Android: Add workaround for a race condition seen on some Redmi phones on app switching
This commit is contained in:
@@ -836,7 +836,7 @@ public abstract class NativeActivity extends Activity {
|
||||
super.onPause();
|
||||
Log.i(TAG, "onPause");
|
||||
loseAudioFocus(this.audioManager, this.audioFocusChangeListener);
|
||||
sizeManager.setPaused(true);
|
||||
sizeManager.onPause();
|
||||
NativeApp.pause();
|
||||
if (!javaGL) {
|
||||
mSurfaceView.onPause();
|
||||
@@ -872,7 +872,7 @@ public abstract class NativeActivity extends Activity {
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
updateSustainedPerformanceMode();
|
||||
sizeManager.setPaused(false);
|
||||
sizeManager.onResume();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
updateSystemUiVisibility();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.DisplayCutout;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
@@ -39,6 +40,8 @@ public class SizeManager implements SurfaceHolder.Callback {
|
||||
private Point desiredSize = new Point();
|
||||
private int badOrientationCount = 0;
|
||||
|
||||
// Used to fix a race condition on some Android versions.
|
||||
private Surface earlySurface = null;
|
||||
|
||||
private boolean paused = false;
|
||||
|
||||
@@ -46,9 +49,19 @@ public class SizeManager implements SurfaceHolder.Callback {
|
||||
activity = a;
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
if (earlySurface != null) {
|
||||
Log.i(TAG, "Applying deferred surface");
|
||||
activity.notifySurface(earlySurface);
|
||||
earlySurface = null;
|
||||
}
|
||||
paused = false;
|
||||
}
|
||||
|
||||
public void setPaused(boolean p) {
|
||||
paused = p;
|
||||
public void onPause() {
|
||||
paused = true;
|
||||
// Make sure.
|
||||
earlySurface = null;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.P)
|
||||
@@ -126,7 +139,8 @@ public class SizeManager implements SurfaceHolder.Callback {
|
||||
if (!paused) {
|
||||
activity.notifySurface(holder.getSurface());
|
||||
} else {
|
||||
Log.i(TAG, "Skipping notifySurface while paused");
|
||||
earlySurface = holder.getSurface();
|
||||
Log.i(TAG, "Skipping notifySurface while paused - deferring to resume");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user