Bug 1242521 - [1.1] Check for Gecko interface availability before accessing activity. r=snorp
authorEugen Sawin <esawin@mozilla.com>
Tue, 26 Jan 2016 20:05:31 +0100
changeset 318137 86ea08134f3797823dd6c2892d07a8ce80938e0b
parent 318136 92e279613f0e6d98c0d206a5d9e7f7106a9dea2c
child 318138 e265e7992928c9ca7bacfd8bfca1929e974b2467
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1242521
milestone47.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 1242521 - [1.1] Check for Gecko interface availability before accessing activity. r=snorp
mobile/android/base/java/org/mozilla/gecko/GeckoScreenOrientation.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoScreenOrientation.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoScreenOrientation.java
@@ -104,17 +104,17 @@ public class GeckoScreenOrientation {
 
     /*
      * Update screen orientation.
      * Retrieve orientation and rotation via GeckoAppShell.
      *
      * @return Whether the screen orientation has changed.
      */
     public boolean update() {
-        Activity activity = GeckoAppShell.getGeckoInterface().getActivity();
+        Activity activity = getActivity();
         if (activity == null) {
             return false;
         }
         Configuration config = activity.getResources().getConfiguration();
         return update(config.orientation);
     }
 
     /*
@@ -206,32 +206,40 @@ public class GeckoScreenOrientation {
      * @return Whether the unlocking was successful.
      */
     public boolean unlock() {
         Log.d(LOGTAG, "unlocking");
         setRequestedOrientation(mDefaultScreenOrientation);
         return update();
     }
 
+    private Activity getActivity() {
+        if (GeckoAppShell.getGeckoInterface() == null) {
+            return null;
+        }
+        return GeckoAppShell.getGeckoInterface().getActivity();
+    }
+
     /*
      * Set the given requested orientation for the current activity.
      * This is essentially an unlock without an update.
      *
      * @param aScreenOrientation
      *        Gecko screen orientation.
      *
      * @return Whether the requested orientation was set. This can only fail if
-     *         the current activity cannot be retrieved vie GeckoAppShell.
+     *         the current activity cannot be retrieved via GeckoAppShell.
      *
      */
     private boolean setRequestedOrientation(ScreenOrientation aScreenOrientation) {
         int activityOrientation = screenOrientationToActivityInfoOrientation(aScreenOrientation);
-        Activity activity = GeckoAppShell.getGeckoInterface().getActivity();
+        Activity activity = getActivity();
         if (activity == null) {
             Log.w(LOGTAG, "setRequestOrientation: failed to get activity");
+            return false;
         }
         if (activity.getRequestedOrientation() == activityOrientation) {
             return false;
         }
         activity.setRequestedOrientation(activityOrientation);
         return true;
     }
 
@@ -284,17 +292,17 @@ public class GeckoScreenOrientation {
                 return 0;
         }
     }
 
     /*
      * @return Device rotation from Display.getRotation().
      */
     private int getRotation() {
-        Activity activity = GeckoAppShell.getGeckoInterface().getActivity();
+        Activity activity = getActivity();
         if (activity == null) {
             Log.w(LOGTAG, "getRotation: failed to get activity");
             return DEFAULT_ROTATION;
         }
         return activity.getWindowManager().getDefaultDisplay().getRotation();
     }
 
     /*