Bug 1527666 - Handle long back press manually only on Android N. r=petru a=pascalc
authorVlad Baicu <vlad.baicu@softvision.ro>
Sun, 21 Apr 2019 03:16:25 +0300
changeset 526265 05d12183776b26907ebacbc9b0bbf282e148cc1a
parent 526264 b476772da6b0bcb6331b98cedfbdc3faae72388f
child 526266 53aff488b7f62eef3f90d7a7f81290374ccd2a45
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspetru, pascalc
bugs1527666
milestone67.0
Bug 1527666 - Handle long back press manually only on Android N. r=petru a=pascalc Summary: 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. Reviewers: petru Reviewed By: petru Bug #: 1527666 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.
      */