Bug 1545429 - Avoid passing unsupported Android screen orientation flag combinations to Gecko. r=snorp
authorHenri Sivonen <hsivonen@hsivonen.fi>
Tue, 02 Jul 2019 17:42:34 +0000
changeset 543911 2521756a55f00f7b6a126600a67d64d7e5f86c33
parent 543910 8e16f13a88c856819d8ca6ace8ccb32b852361f7
child 543912 a70f62521b875857e709f4120006ac2429c869c2
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1545429
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1545429 - Avoid passing unsupported Android screen orientation flag combinations to Gecko. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D36351
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
widget/android/AndroidBridge.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
@@ -56,18 +56,18 @@ public class GeckoScreenOrientation {
             return NONE;
         }
     }
 
     // Singleton instance.
     private static GeckoScreenOrientation sInstance;
     // Default rotation, used when device rotation is unknown.
     private static final int DEFAULT_ROTATION = Surface.ROTATION_0;
-    // Last updated screen orientation.
-    private ScreenOrientation mScreenOrientation;
+    // Last updated screen orientation with Gecko value space.
+    private ScreenOrientation mScreenOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
     // Whether the update should notify Gecko about screen orientation changes.
     private boolean mShouldNotify = true;
 
     public interface OrientationChangeListener {
         void onScreenOrientationChanged(ScreenOrientation newOrientation);
     }
 
     private final List<OrientationChangeListener> mListeners;
@@ -150,41 +150,46 @@ public class GeckoScreenOrientation {
      * Update screen orientation given the screen orientation.
      *
      * @param aScreenOrientation
      *        Gecko screen orientation based on android orientation and rotation.
      *
      * @return Whether the screen orientation has changed.
      */
     public synchronized boolean update(final ScreenOrientation aScreenOrientation) {
-        if (mScreenOrientation == aScreenOrientation) {
+        // Gecko expects a definite screen orientation, so we default to the
+        // primary orientations.
+        ScreenOrientation screenOrientation;
+        if ((aScreenOrientation.value & ScreenOrientation.PORTRAIT_PRIMARY.value) != 0) {
+            screenOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
+        } else if ((aScreenOrientation.value & ScreenOrientation.PORTRAIT_SECONDARY.value) != 0) {
+            screenOrientation = ScreenOrientation.PORTRAIT_SECONDARY;
+        } else if ((aScreenOrientation.value & ScreenOrientation.LANDSCAPE_PRIMARY.value) != 0) {
+            screenOrientation = ScreenOrientation.LANDSCAPE_PRIMARY;
+        } else if ((aScreenOrientation.value & ScreenOrientation.LANDSCAPE_SECONDARY.value) != 0) {
+            screenOrientation = ScreenOrientation.LANDSCAPE_SECONDARY;
+        } else {
+            screenOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
+        }
+        if (mScreenOrientation == screenOrientation) {
             return false;
         }
-        mScreenOrientation = aScreenOrientation;
+        mScreenOrientation = screenOrientation;
         Log.d(LOGTAG, "updating to new orientation " + mScreenOrientation);
         notifyListeners(mScreenOrientation);
         if (mShouldNotify) {
-            // Gecko expects a definite screen orientation, so we default to the
-            // primary orientations.
-            ScreenOrientation primaryOrientation = aScreenOrientation;
-            if (aScreenOrientation == ScreenOrientation.PORTRAIT) {
-                primaryOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
-            } else if (aScreenOrientation == ScreenOrientation.LANDSCAPE) {
-                primaryOrientation = ScreenOrientation.LANDSCAPE_PRIMARY;
-            } else if (aScreenOrientation == ScreenOrientation.DEFAULT) {
-                primaryOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
-            } else if (aScreenOrientation == ScreenOrientation.NONE) {
+            if (aScreenOrientation == ScreenOrientation.NONE) {
                 return false;
             }
 
             if (GeckoThread.isRunning()) {
-                onOrientationChange(primaryOrientation.value, getAngle());
+                onOrientationChange(screenOrientation.value, getAngle());
             } else {
                 GeckoThread.queueNativeCall(GeckoScreenOrientation.class, "onOrientationChange",
-                                            primaryOrientation.value, getAngle());
+                                            screenOrientation.value, getAngle());
             }
         }
         ScreenManagerHelper.refreshScreenInfo();
         return true;
     }
 
     private void notifyListeners(final ScreenOrientation newOrientation) {
         final Runnable notifier = new Runnable() {
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -663,18 +663,16 @@ void nsAndroidBridge::RemoveObservers() 
   }
 }
 
 uint32_t AndroidBridge::GetScreenOrientation() {
   ALOG_BRIDGE("AndroidBridge::GetScreenOrientation");
 
   int16_t orientation = GeckoAppShell::GetScreenOrientation();
 
-  if (!orientation) return hal::eScreenOrientation_None;
-
   return static_cast<hal::ScreenOrientation>(orientation);
 }
 
 uint16_t AndroidBridge::GetScreenAngle() {
   return GeckoAppShell::GetScreenAngle();
 }
 
 nsresult AndroidBridge::GetProxyForURI(const nsACString& aSpec,