Workaround orientation bug in Android when unlocking the screen.

Or I'm doing something wrong somewhere...

Also kill off "Auto" orientation. It's just a pain.

Fixes #10128
This commit is contained in:
Henrik Rydgård 2017-11-16 12:23:10 +01:00
parent cabfec32c8
commit 53a351c29d
3 changed files with 28 additions and 15 deletions

View file

@ -677,8 +677,8 @@ void GameSettingsScreen::CreateViews() {
#if PPSSPP_PLATFORM(ANDROID) #if PPSSPP_PLATFORM(ANDROID)
if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_MOBILE) { if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_MOBILE) {
static const char *screenRotation[] = {"Auto", "Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed"}; static const char *screenRotation[] = {"Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed"};
PopupMultiChoice *rot = systemSettings->Add(new PopupMultiChoice(&g_Config.iScreenRotation, co->T("Screen Rotation"), screenRotation, 0, ARRAY_SIZE(screenRotation), co->GetName(), screenManager())); PopupMultiChoice *rot = systemSettings->Add(new PopupMultiChoice(&g_Config.iScreenRotation, co->T("Screen Rotation"), screenRotation, 1, ARRAY_SIZE(screenRotation), co->GetName(), screenManager()));
rot->OnChoice.Handle(this, &GameSettingsScreen::OnScreenRotation); rot->OnChoice.Handle(this, &GameSettingsScreen::OnScreenRotation);
if (System_GetPropertyBool(SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE)) { if (System_GetPropertyBool(SYSPROP_SUPPORTS_SUSTAINED_PERF_MODE)) {

View file

@ -310,7 +310,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
// OK, config should be initialized, we can query for screen rotation. // OK, config should be initialized, we can query for screen rotation.
if (Build.VERSION.SDK_INT >= 9) { if (Build.VERSION.SDK_INT >= 9) {
updateScreenRotation(); updateScreenRotation("Initialize");
} }
// Detect OpenGL support. // Detect OpenGL support.
@ -355,7 +355,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
} }
@TargetApi(9) @TargetApi(9)
private void updateScreenRotation() { private void updateScreenRotation(String cause) {
// Query the native application on the desired rotation. // Query the native application on the desired rotation.
int rot = 0; int rot = 0;
String rotString = NativeApp.queryConfig("screenRotation"); String rotString = NativeApp.queryConfig("screenRotation");
@ -365,11 +365,12 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
Log.e(TAG, "Invalid rotation: " + rotString); Log.e(TAG, "Invalid rotation: " + rotString);
return; return;
} }
Log.i(TAG, "Setting requested rotation: " + rot + " ('" + rotString + "')"); Log.i(TAG, "Setting requested rotation: " + rot + " ('" + rotString + "') (" + cause + ")");
switch (rot) { switch (rot) {
case 0: case 0:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); // Auto is no longer supported.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break; break;
case 1: case 1:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
@ -462,7 +463,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
refreshRate = display.getRefreshRate(); refreshRate = display.getRefreshRate();
// OK, config should be initialized, we can query for screen rotation. // OK, config should be initialized, we can query for screen rotation.
updateScreenRotation(); updateScreenRotation("onCreate");
updateSustainedPerformanceMode(); updateSustainedPerformanceMode();
// Keep the screen bright - very annoying if it goes dark when tilting away // Keep the screen bright - very annoying if it goes dark when tilting away
@ -524,7 +525,18 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
pixelWidth = holder.getSurfaceFrame().width(); pixelWidth = holder.getSurfaceFrame().width();
pixelHeight = holder.getSurfaceFrame().height(); pixelHeight = holder.getSurfaceFrame().height();
Log.d(TAG, "Surface created. pixelWidth=" + pixelWidth + ", pixelHeight=" + pixelHeight + " holder: " + holder.toString());
// Workaround for terrible bug when locking and unlocking the screen in landscape mode on Nexus 5X.
int requestedOr = getRequestedOrientation();
boolean requestedPortrait = requestedOr == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || requestedOr == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
boolean detectedPortrait = pixelHeight > pixelWidth;
if (requestedPortrait != detectedPortrait) {
Log.e(TAG, "Bad orientation detected! Recreating activity.");
recreate();;
return;
}
Log.d(TAG, "Surface created. pixelWidth=" + pixelWidth + ", pixelHeight=" + pixelHeight + " holder: " + holder.toString() + " or: " + requestedOr);
NativeApp.setDisplayParameters(pixelWidth, pixelHeight, (int)densityDpi, refreshRate); NativeApp.setDisplayParameters(pixelWidth, pixelHeight, (int)densityDpi, refreshRate);
getDesiredBackbufferSize(desiredSize); getDesiredBackbufferSize(desiredSize);
@ -687,7 +699,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
} }
// OK, config should be initialized, we can query for screen rotation. // OK, config should be initialized, we can query for screen rotation.
if (javaGL || Build.VERSION.SDK_INT >= 9) { if (javaGL || Build.VERSION.SDK_INT >= 9) {
updateScreenRotation(); updateScreenRotation("onResume");
} }
Log.i(TAG, "onResume"); Log.i(TAG, "onResume");
@ -840,10 +852,10 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
return input.getDescriptor(); return input.getDescriptor();
} else { } else {
List<InputDevice.MotionRange> motions = input.getMotionRanges(); List<InputDevice.MotionRange> motions = input.getMotionRanges();
String fakeid = ""; StringBuilder fakeid = new StringBuilder();
for (InputDevice.MotionRange range : motions) for (InputDevice.MotionRange range : motions)
fakeid += range.getAxis(); fakeid.append(range.getAxis());
return fakeid; return fakeid.toString();
} }
} }
@ -999,7 +1011,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
input.selectAll(); input.selectAll();
// Lovely! // Lovely!
AlertDialog.Builder bld = null; AlertDialog.Builder bld;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
bld = new AlertDialog.Builder(this); bld = new AlertDialog.Builder(this);
else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@ -1181,13 +1193,13 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
finish(); finish();
} else if (command.equals("rotate")) { } else if (command.equals("rotate")) {
if (javaGL) { if (javaGL) {
updateScreenRotation(); updateScreenRotation("rotate");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Log.i(TAG, "Must recreate activity on rotation"); Log.i(TAG, "Must recreate activity on rotation");
} }
} else { } else {
if (Build.VERSION.SDK_INT >= 9) { if (Build.VERSION.SDK_INT >= 9) {
updateScreenRotation(); updateScreenRotation("rotate");
} }
} }
} else if (command.equals("sustainedPerfMode")) { } else if (command.equals("sustainedPerfMode")) {

View file

@ -92,6 +92,7 @@ public class PpssppActivity extends NativeActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
// called by the C++ code through JNI. Dispatch anything we can't directly handle // called by the C++ code through JNI. Dispatch anything we can't directly handle
// on the gfx thread to the UI thread. // on the gfx thread to the UI thread.
public void postCommand(String command, String parameter) { public void postCommand(String command, String parameter) {