Bug 1527666 - Handle long back press manually only on Android N.r=petru
authorVlad Baicu <vlad.baicu@softvision.ro>
Thu, 18 Apr 2019 12:06:53 +0000
changeset 470167 da464aa8549f6031a68ed6577a1eb890a936a19e
parent 470166 5be51df44c5c75a8ffd199f9dccb2c614ecb7be2
child 470168 be0c4eed11e43d177ded8e8ddf0ab5379c9f3f44
push id112843
push useraiakab@mozilla.com
push dateFri, 19 Apr 2019 09:50:22 +0000
treeherdermozilla-inbound@c06f27cbfe40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspetru
bugs1527666
milestone68.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 1527666 - Handle long back press manually only on Android N.r=petru On versions >= N all long back presses we're handled manually in onKeyDown and onKeyUp which could lead to certain complications. I have changed it only for Android N where onKeyLongPress does not trigger as it should. Differential Revision: https://phabricator.services.mozilla.com/D28037
mobile/android/base/AppConstants.java.in
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
--- a/mobile/android/base/AppConstants.java.in
+++ b/mobile/android/base/AppConstants.java.in
@@ -64,16 +64,17 @@ public class AppConstants {
          */
         public static final boolean preMarshmallow = MAX_SDK_VERSION < 23 || (MIN_SDK_VERSION < 23 && Build.VERSION.SDK_INT < 23);
         public static final boolean preLollipopMR1 = MAX_SDK_VERSION < 22 || (MIN_SDK_VERSION < 22 && Build.VERSION.SDK_INT < 22);
         public static final boolean preLollipop = MAX_SDK_VERSION < 21 || (MIN_SDK_VERSION < 21 && Build.VERSION.SDK_INT < 21);
         public static final boolean preJBMR2 = MAX_SDK_VERSION < 18 || (MIN_SDK_VERSION < 18 && Build.VERSION.SDK_INT < 18);
         public static final boolean preJBMR1 = MAX_SDK_VERSION < 17 || (MIN_SDK_VERSION < 17 && Build.VERSION.SDK_INT < 17);
         public static final boolean preJB = MAX_SDK_VERSION < 16 || (MIN_SDK_VERSION < 16 && Build.VERSION.SDK_INT < 16);
         public static final boolean preN = MAX_SDK_VERSION < 24 || (MIN_SDK_VERSION < 24 && Build.VERSION.SDK_INT < 24);
+        public static final boolean N = Build.VERSION.SDK_INT == 24 || Build.VERSION.SDK_INT == 25;
         public static final boolean preO = MAX_SDK_VERSION < 26 || (MIN_SDK_VERSION < 26 && Build.VERSION.SDK_INT < 26);
     }
 
     /**
      * The name of the Java class that represents the android application.
      */
     public static final String MOZ_ANDROID_APPLICATION_CLASS = "@MOZ_ANDROID_APPLICATION_CLASS@";
     /**
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -566,49 +566,49 @@ public class BrowserApp extends GeckoApp
             }
         }
 
         return false;
     }
 
     private Runnable mCheckLongPress;
     {
-        // Only initialise the runnable if we are >= N.
+        // Only initialise the runnable if we are = N.
         // See onKeyDown() for more details of the back-button long-press workaround
-        if (!Versions.preN) {
+        if (Versions.N) {
             mCheckLongPress = new Runnable() {
                 public void run() {
                     handleBackLongPress();
                 }
             };
         }
     }
 
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
         // Bug 1304688: Android N has broken passing onKeyLongPress events for the back button, so we
         // instead copy the long-press-handler technique from Android's KeyButtonView.
         // - For short presses, we cancel the callback in onKeyUp
         // - For long presses, the normal keypress is marked as cancelled, hence won't be handled elsewhere
         //   (but Android still provides the haptic feedback), and the runnable is run.
-        if (!Versions.preN &&
+        if (Versions.N &&
                 keyCode == KeyEvent.KEYCODE_BACK) {
             ThreadUtils.getUiHandler().removeCallbacks(mCheckLongPress);
             ThreadUtils.getUiHandler().postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout());
         }
 
         if (!mBrowserToolbar.isEditing() && onKey(null, keyCode, event)) {
             return true;
         }
         return super.onKeyDown(keyCode, event);
     }
 
     @Override
     public boolean onKeyUp(int keyCode, KeyEvent event) {
-        if (!Versions.preN &&
+        if (Versions.N &&
                 keyCode == KeyEvent.KEYCODE_BACK) {
             ThreadUtils.getUiHandler().removeCallbacks(mCheckLongPress);
         }
 
         if (AndroidGamepadManager.handleKeyEvent(event)) {
             return true;
         }
         return super.onKeyUp(keyCode, event);
@@ -3797,22 +3797,21 @@ public class BrowserApp extends GeckoApp
     /**
      * This will detect if the key pressed is back. If so, will show the history.
      */
     @Override
     public boolean onKeyLongPress(int keyCode, KeyEvent event) {
         // onKeyLongPress is broken in Android N, see onKeyDown() for more information. We add a version
         // check here to match our fallback code in order to avoid handling a long press twice (which
         // could happen if newer versions of android and/or other vendors were to  fix this problem).
-        if (Versions.preN &&
+        if (!Versions.N &&
                 keyCode == KeyEvent.KEYCODE_BACK) {
             if (handleBackLongPress()) {
                 return true;
             }
-
         }
         return super.onKeyLongPress(keyCode, event);
     }
 
     /*
      * If the app has been launched a certain number of times, and we haven't asked for feedback before,
      * open a new tab with about:feedback when launching the app from the icon shortcut.
      */