Android: Add workaround for a race condition seen on some Redmi phones on app switching

This commit is contained in:
Henrik Rydgård
2025-05-28 12:51:47 +02:00
parent 0c55bfcb70
commit a0ba0d2f7d
2 changed files with 19 additions and 5 deletions
@@ -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();
}
+17 -3
View File
@@ -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");
}
}