Bug 1806072 - screen.orientation.angle isn't updated on Pixel 6a. r=geckoview-reviewers,owlish
When using Pixel 6a, orientation information seems to be invalid. It seems that this is similar to bug 1754802. So we should get the rotation information from ScreenCompat per API level. And, when changing screen orientation by `screen.orientation.lock()`, Display Manager API observes changing, but it may get previous information at this timing. After changing display information, `onConfigureChanges` is notified, then we an get correct information, so we have to update information via it if newer Android. Differential Revision: https://phabricator.services.mozilla.com/D164885
This commit is contained in:
@@ -1261,6 +1261,10 @@ public class GeckoAppShell {
|
||||
return GeckoScreenOrientation.getInstance().getScreenOrientation().value;
|
||||
}
|
||||
|
||||
/* package */ static int getRotation() {
|
||||
return sScreenCompat.getRotation();
|
||||
}
|
||||
|
||||
@WrapForJNI(calledFrom = "gecko")
|
||||
private static int getScreenAngle() {
|
||||
return GeckoScreenOrientation.getInstance().getAngle();
|
||||
@@ -1386,6 +1390,8 @@ public class GeckoAppShell {
|
||||
|
||||
private interface ScreenCompat {
|
||||
Rect getScreenSize();
|
||||
|
||||
int getRotation();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
@@ -1396,6 +1402,12 @@ public class GeckoAppShell {
|
||||
final Display disp = wm.getDefaultDisplay();
|
||||
return new Rect(0, 0, disp.getWidth(), disp.getHeight());
|
||||
}
|
||||
|
||||
public int getRotation() {
|
||||
final WindowManager wm =
|
||||
(WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
|
||||
return wm.getDefaultDisplay().getRotation();
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
@@ -1408,6 +1420,12 @@ public class GeckoAppShell {
|
||||
disp.getRealSize(size);
|
||||
return new Rect(0, 0, size.x, size.y);
|
||||
}
|
||||
|
||||
public int getRotation() {
|
||||
final WindowManager wm =
|
||||
(WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
|
||||
return wm.getDefaultDisplay().getRotation();
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.S)
|
||||
@@ -1431,6 +1449,11 @@ public class GeckoAppShell {
|
||||
final WindowManager windowManager = getWindowContext().getSystemService(WindowManager.class);
|
||||
return windowManager.getCurrentWindowMetrics().getBounds();
|
||||
}
|
||||
|
||||
public int getRotation() {
|
||||
final WindowManager windowManager = getWindowContext().getSystemService(WindowManager.class);
|
||||
return windowManager.getDefaultDisplay().getRotation();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
@@ -13,7 +13,6 @@ import android.graphics.Rect;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.Surface;
|
||||
import android.view.WindowManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
@@ -105,14 +104,15 @@ public class GeckoScreenOrientation {
|
||||
* @return Whether the screen orientation has changed.
|
||||
*/
|
||||
public boolean update() {
|
||||
// Check whether we have the application context for fenix/a-c unit test.
|
||||
final Context appContext = GeckoAppShell.getApplicationContext();
|
||||
if (appContext == null) {
|
||||
return false;
|
||||
}
|
||||
final WindowManager windowManager =
|
||||
(WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
final Display display = windowManager.getDefaultDisplay();
|
||||
return update(getScreenOrientation(display));
|
||||
final Rect rect = GeckoAppShell.getScreenSizeIgnoreOverride();
|
||||
final int orientation =
|
||||
rect.width() >= rect.height() ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT;
|
||||
return update(getScreenOrientation(orientation, getRotation()));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -268,12 +268,6 @@ public class GeckoScreenOrientation {
|
||||
* @return Device rotation.
|
||||
*/
|
||||
private int getRotation() {
|
||||
final Context appContext = GeckoAppShell.getApplicationContext();
|
||||
if (appContext == null) {
|
||||
return DEFAULT_ROTATION;
|
||||
}
|
||||
final WindowManager windowManager =
|
||||
(WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
return windowManager.getDefaultDisplay().getRotation();
|
||||
return GeckoAppShell.getRotation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,13 +635,15 @@ public class GeckoView extends FrameLayout {
|
||||
if (mSession != null) {
|
||||
final GeckoRuntime runtime = mSession.getRuntime();
|
||||
if (runtime != null) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1
|
||||
|| Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
// onConfigurationChanged is not called for 180 degree orientation changes,
|
||||
// we will miss such rotations and the screen orientation will not be
|
||||
// updated.
|
||||
//
|
||||
// If API is 17+, we use DisplayManager API to detect all degree
|
||||
// orientation change.
|
||||
// orientation change. But if API is 31+, DisplayManager API may report previous
|
||||
// information. So we have to report it again.
|
||||
runtime.orientationChanged(newConfig.orientation);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user