Revert "[1/2] SystemUI: arrow keys while typing resurrection"

This reverts commit b867cdecf3039c602f948ffa3e8201b32ec2fb38.

Moved to Launcher3 taskbar app

Change-Id: I30e9003b98e738b88c9035d6a8daf3613555ab8c
Signed-off-by: micky387 <mickaelsaibi@free.fr>
diff --git a/packages/SystemUI/res/drawable/ic_navbar_chevron_left.xml b/packages/SystemUI/res/drawable/ic_navbar_chevron_left.xml
deleted file mode 100644
index c6329f0..0000000
--- a/packages/SystemUI/res/drawable/ic_navbar_chevron_left.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
-  ~ Copyright (C) 2014 The Android Open Source Project
-  ~
-  ~ Licensed under the Apache License, Version 2.0 (the "License");
-  ~ you may not use this file except in compliance with the License.
-  ~ You may obtain a copy of the License at
-  ~
-  ~      http://www.apache.org/licenses/LICENSE-2.0
-  ~
-  ~ Unless required by applicable law or agreed to in writing, software
-  ~ distributed under the License is distributed on an "AS IS" BASIS,
-  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  ~ See the License for the specific language governing permissions and
-  ~ limitations under the License
-  -->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-        android:height="24dp"
-        android:width="24dp"
-        android:viewportWidth="24"
-        android:viewportHeight="24">
-    <path
-        android:fillColor="?attr/singleToneColor"
-        android:pathData="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z" />
-</vector>
diff --git a/packages/SystemUI/res/drawable/ic_navbar_chevron_right.xml b/packages/SystemUI/res/drawable/ic_navbar_chevron_right.xml
deleted file mode 100644
index 86d20cb..0000000
--- a/packages/SystemUI/res/drawable/ic_navbar_chevron_right.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
-  ~ Copyright (C) 2014 The Android Open Source Project
-  ~
-  ~ Licensed under the Apache License, Version 2.0 (the "License");
-  ~ you may not use this file except in compliance with the License.
-  ~ You may obtain a copy of the License at
-  ~
-  ~      http://www.apache.org/licenses/LICENSE-2.0
-  ~
-  ~ Unless required by applicable law or agreed to in writing, software
-  ~ distributed under the License is distributed on an "AS IS" BASIS,
-  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  ~ See the License for the specific language governing permissions and
-  ~ limitations under the License
-  -->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-        android:height="24dp"
-        android:width="24dp"
-        android:viewportWidth="24"
-        android:viewportHeight="24">
-    <path
-        android:fillColor="?attr/singleToneColor"
-        android:pathData="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z" />
-</vector>
diff --git a/packages/SystemUI/res/layout/nav_buttons_dpad_group.xml b/packages/SystemUI/res/layout/nav_buttons_dpad_group.xml
deleted file mode 100644
index 6afc9de..0000000
--- a/packages/SystemUI/res/layout/nav_buttons_dpad_group.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 The CyanogenMod Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<RelativeLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:systemui="http://schemas.android.com/apk/res-auto"
-    android:id="@+id/dpad_group"
-    android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
-    android:clipChildren="false">
-
-        <com.android.systemui.navigationbar.views.buttons.KeyButtonView
-            android:id="@+id/dpad_left"
-            android:layout_width="@dimen/navigation_extra_key_width"
-            android:layout_height="match_parent"
-            android:layout_alignParentLeft="true"
-            systemui:keyCode="21"
-            android:visibility="gone"
-            android:scaleType="center"
-            android:contentDescription="@string/accessibility_dpad_left" />
-
-        <com.android.systemui.navigationbar.views.buttons.KeyButtonView
-            android:id="@+id/dpad_right"
-            android:layout_width="@dimen/navigation_extra_key_width"
-            android:layout_height="match_parent"
-            android:layout_alignParentRight="true"
-            systemui:keyCode="22"
-            android:visibility="gone"
-            android:scaleType="center"
-            android:contentDescription="@string/accessibility_dpad_right" />
-
-</RelativeLayout>
diff --git a/packages/SystemUI/res/layout/nav_buttons_dpad_group_vertical.xml b/packages/SystemUI/res/layout/nav_buttons_dpad_group_vertical.xml
deleted file mode 100644
index 7139368..0000000
--- a/packages/SystemUI/res/layout/nav_buttons_dpad_group_vertical.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 The CyanogenMod Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<RelativeLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:systemui="http://schemas.android.com/apk/res-auto"
-    android:id="@+id/dpad_group"
-    android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
-    android:clipChildren="false">
-
-        <com.android.systemui.navigationbar.views.buttons.KeyButtonView
-            android:id="@+id/dpad_left"
-            android:layout_width="match_parent"
-            android:layout_height="@dimen/navigation_extra_key_width"
-            android:layout_alignParentTop="true"
-            systemui:keyCode="21"
-            android:visibility="gone"
-            android:scaleType="center"
-            android:contentDescription="@string/accessibility_dpad_left" />
-
-        <com.android.systemui.navigationbar.views.buttons.KeyButtonView
-            android:id="@+id/dpad_right"
-            android:layout_width="match_parent"
-            android:layout_height="@dimen/navigation_extra_key_width"
-            android:layout_alignParentBottom="true"
-            systemui:keyCode="22"
-            android:visibility="gone"
-            android:scaleType="center"
-            android:contentDescription="@string/accessibility_dpad_right" />
-
-</RelativeLayout>
diff --git a/packages/SystemUI/res/layout/navigation_layout.xml b/packages/SystemUI/res/layout/navigation_layout.xml
index fb79645..5c6c9a4 100644
--- a/packages/SystemUI/res/layout/navigation_layout.xml
+++ b/packages/SystemUI/res/layout/navigation_layout.xml
@@ -53,8 +53,6 @@
             android:clipToPadding="false"
             android:clipChildren="false" />
 
-        <include layout="@layout/nav_buttons_dpad_group" />
-
     </com.android.systemui.navigationbar.views.buttons.NearestTouchFrame>
 
 </FrameLayout>
diff --git a/packages/SystemUI/res/layout/navigation_layout_vertical.xml b/packages/SystemUI/res/layout/navigation_layout_vertical.xml
index 773de3c..c64e3f7 100644
--- a/packages/SystemUI/res/layout/navigation_layout_vertical.xml
+++ b/packages/SystemUI/res/layout/navigation_layout_vertical.xml
@@ -50,8 +50,6 @@
             android:clipToPadding="false"
             android:clipChildren="false" />
 
-        <include layout="@layout/nav_buttons_dpad_group_vertical" />
-
     </com.android.systemui.navigationbar.views.buttons.NearestTouchFrame>
 
 </FrameLayout>
diff --git a/packages/SystemUI/res/values/custom_config.xml b/packages/SystemUI/res/values/custom_config.xml
index 6f0bebf..cab106ab 100644
--- a/packages/SystemUI/res/values/custom_config.xml
+++ b/packages/SystemUI/res/values/custom_config.xml
@@ -39,9 +39,6 @@
     <!-- The CPUs to display in CPUInfoService view -->
     <string name="config_displayCpus" translatable="false"></string>
 
-    <!-- Navigation bar dpad -->
-    <string name="config_navBarLayoutHandleArrows" translatable="false">back[1.7WC];home_handle;ime_switcher[1.7WC]</string>
-
     <!-- qs columns count settings -->
     <bool name="qs_tile_vertical_layout">false</bool>
 
diff --git a/packages/SystemUI/res/values/custom_dimens.xml b/packages/SystemUI/res/values/custom_dimens.xml
index dcbb0d3..6168cae 100644
--- a/packages/SystemUI/res/values/custom_dimens.xml
+++ b/packages/SystemUI/res/values/custom_dimens.xml
@@ -21,9 +21,6 @@
 <resources>
     <dimen name="cpu_info_text_height">12dp</dimen>
 
-    <!-- Navigation bar dpad -->
-    <dimen name="navigation_extra_key_width">36dp</dimen>
-
     <!-- Brightness and volume slider-->
     <dimen name="rounded_slider_progress_width">8dp</dimen>
     <dimen name="rounded_slider_progress_corner_radius">4dp</dimen>
diff --git a/packages/SystemUI/res/values/custom_strings.xml b/packages/SystemUI/res/values/custom_strings.xml
index 1124ee3..38c0fa2 100644
--- a/packages/SystemUI/res/values/custom_strings.xml
+++ b/packages/SystemUI/res/values/custom_strings.xml
@@ -43,10 +43,6 @@
     <!-- Keyguard -->
     <string name="keyguard_slice_dnd">Do Not Disturb</string>
 
-    <!-- Navigation bar dpad -->
-    <string name="accessibility_dpad_left">Cursor left</string>
-    <string name="accessibility_dpad_right">Cursor right</string>
-
     <!-- Power menu reboot -->
     <string name="global_action_reboot">Restart</string>
     <string name="global_action_reboot_more">Restart\u2026</string>
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBar.java b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBar.java
index 5f856ca..c895732 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBar.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBar.java
@@ -1933,8 +1933,6 @@
         updateButtonLocation(
                 region, touchRegionCache, mView.getAccessibilityButton(), inScreenSpace,
                 useNearestRegion);
-        updateButtonLocation(region, mView.getKeyButtonViewById(R.id.dpad_left), inScreenSpace);
-        updateButtonLocation(region, mView.getKeyButtonViewById(R.id.dpad_right), inScreenSpace);
         if (mView.getFloatingRotationButton().isVisible()) {
             // Note: this button is floating so the nearest region doesn't apply
             updateButtonLocation(
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarInflaterView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarInflaterView.java
index 0cac696..c179c6d 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarInflaterView.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarInflaterView.java
@@ -23,7 +23,6 @@
 import android.content.Context;
 import android.content.res.Configuration;
 import android.graphics.drawable.Icon;
-import android.os.UserHandle;
 import android.provider.Settings;
 import android.util.AttributeSet;
 import android.util.Log;
@@ -43,19 +42,15 @@
 import com.android.systemui.navigationbar.views.buttons.KeyButtonView;
 import com.android.systemui.navigationbar.views.buttons.ReverseLinearLayout;
 import com.android.systemui.navigationbar.views.buttons.ReverseLinearLayout.ReverseRelativeLayout;
-import com.android.systemui.omni.OmniSettingsService;
 import com.android.systemui.recents.OverviewProxyService;
 import com.android.systemui.res.R;
 import com.android.systemui.shared.system.QuickStepContract;
 
-import org.omnirom.omnilib.utils.OmniSettings;
-
 import java.io.PrintWriter;
 import java.lang.ref.WeakReference;
 import java.util.Objects;
 
-public class NavigationBarInflaterView extends FrameLayout
-        implements OmniSettingsService.OmniSettingsObserver {
+public class NavigationBarInflaterView extends FrameLayout {
 
     private static final String TAG = "NavBarInflater";
 
@@ -165,8 +160,7 @@
 
     protected String getDefaultLayout() {
         final int defaultResource = QuickStepContract.isGesturalMode(mNavBarMode)
-                        ? (showDpadArrowKeys() ? R.string.config_navBarLayoutHandleArrows
-                        : R.string.config_navBarLayoutHandle)
+                ? R.string.config_navBarLayoutHandle
                 : mOverviewProxyService.shouldShowSwipeUpUI()
                         ? R.string.config_navBarLayoutQuickstep
                         : R.string.config_navBarLayout;
@@ -180,17 +174,9 @@
     @Override
     protected void onDetachedFromWindow() {
         Dependency.get(NavigationModeController.class).removeListener(mListener);
-        Dependency.get(OmniSettingsService.class).removeObserver(this);
         super.onDetachedFromWindow();
     }
 
-    @Override
-    protected void onAttachedToWindow() {
-        super.onAttachedToWindow();
-        Dependency.get(OmniSettingsService.class).addIntObserver(this,
-            OmniSettings.OMNI_NAVIGATION_BAR_ARROW_KEYS);
-    }
-
     public void onLikelyDefaultLayoutChange() {
         // Reevaluate new layout
         final String newValue = getDefaultLayout();
@@ -505,9 +491,7 @@
 
     private void clearAllChildren(ViewGroup group) {
         for (int i = 0; i < group.getChildCount(); i++) {
-            if (group.getChildAt(i).getId() != R.id.dpad_group) {
-                ((ViewGroup) group.getChildAt(i)).removeAllViews();
-            }
+            ((ViewGroup) group.getChildAt(i)).removeAllViews();
         }
     }
 
@@ -515,16 +499,6 @@
         return dp * context.getResources().getDisplayMetrics().density;
     }
 
-    private boolean showDpadArrowKeys() {
-        return Settings.System.getIntForUser(getContext().getContentResolver(),
-                OmniSettings.OMNI_NAVIGATION_BAR_ARROW_KEYS, 0, UserHandle.USER_CURRENT) != 0;
-    }
-
-    @Override
-    public void onIntSettingChanged(String key, Integer newValue) {
-        onLikelyDefaultLayoutChange();
-    }
-
     public void dump(PrintWriter pw) {
         pw.println("NavigationBarInflaterView");
         pw.println("  mCurrentLayout: " + mCurrentLayout);
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarTransitions.java b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarTransitions.java
index 735337d..251745d 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarTransitions.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarTransitions.java
@@ -191,7 +191,6 @@
             buttonDispatchers.valueAt(i).setDarkIntensity(darkIntensity);
         }
         mView.getRotationButtonController().setDarkIntensity(darkIntensity);
-        mView.setDpadDarkIntensity(darkIntensity);
 
         for (DarkIntensityListener listener : mDarkIntensityListeners) {
             listener.onDarkIntensity(darkIntensity);
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarView.java
index 1dffbd1..c4abcd2 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/views/NavigationBarView.java
@@ -39,8 +39,6 @@
 import android.graphics.Rect;
 import android.os.Bundle;
 import android.os.RemoteException;
-import android.os.UserHandle;
-import android.provider.Settings;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.util.SparseArray;
@@ -73,7 +71,6 @@
 import com.android.systemui.navigationbar.views.buttons.ContextualButtonGroup;
 import com.android.systemui.navigationbar.views.buttons.DeadZone;
 import com.android.systemui.navigationbar.views.buttons.KeyButtonDrawable;
-import com.android.systemui.navigationbar.views.buttons.KeyButtonView;
 import com.android.systemui.navigationbar.views.buttons.NearestTouchFrame;
 import com.android.systemui.recents.Recents;
 import com.android.systemui.res.R;
@@ -90,8 +87,6 @@
 import com.android.wm.shell.back.BackAnimation;
 import com.android.wm.shell.pip.Pip;
 
-import org.omnirom.omnilib.utils.OmniSettings;
-
 import java.io.PrintWriter;
 import java.util.Map;
 import java.util.Optional;
@@ -122,8 +117,6 @@
     private int mNavBarMode;
     private boolean mImeDrawsImeNavBar;
 
-    private KeyButtonDrawable mArrowLeftIcon;
-    private KeyButtonDrawable mArrowRightIcon;
     private KeyButtonDrawable mBackIcon;
     private KeyButtonDrawable mHomeDefaultIcon;
     private KeyButtonDrawable mRecentIcon;
@@ -461,10 +454,6 @@
         return mShowSwipeUpUi && isOverviewEnabled();
     }
 
-    public KeyButtonView getKeyButtonViewById(int id) {
-        return (KeyButtonView) getCurrentView().findViewById(id);
-    }
-
     private void reloadNavIcons() {
         updateIcons(Configuration.EMPTY);
     }
@@ -485,8 +474,6 @@
         if (orientationChange || densityChange || dirChange) {
             mBackIcon = getBackDrawable();
         }
-        mArrowLeftIcon = getDrawable(R.drawable.ic_navbar_chevron_left);
-        mArrowRightIcon = getDrawable(R.drawable.ic_navbar_chevron_right);
     }
 
     /**
@@ -613,23 +600,12 @@
 
         updateRecentsIcon();
 
-        if (showDpadArrowKeys) {
-            getKeyButtonViewById(R.id.dpad_left).setImageDrawable(mArrowLeftIcon);
-            getKeyButtonViewById(R.id.dpad_right).setImageDrawable(mArrowRightIcon);
-            updateDpadKeys();
-        }
-
         // Update IME button visibility, a11y and rotate button always overrides the appearance
         boolean disableImeSwitcher =
                 (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SWITCHER_SHOWN) == 0
                 || isImeRenderingNavButtons();
         mContextualButtonGroup.setButtonVisibility(R.id.ime_switcher, !disableImeSwitcher);
 
-        // right arrow overrules ime in 3 button mode cause there is not enough space
-        if (QuickStepContract.isLegacyMode(mNavBarMode) && showDpadArrowKeys) {
-            mContextualButtonGroup.setButtonVisibility(R.id.ime_switcher, false);
-        }
-
         mBarTransitions.reapplyDarkIntensity();
 
         boolean disableHome = isGesturalMode(mNavBarMode)
@@ -1226,21 +1202,4 @@
     interface UpdateActiveTouchRegionsCallback {
         void update();
     }
-
-    private void updateDpadKeys() {
-        final int visibility = showDpadArrowKeys && (mNavigationIconHints
-                & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0 ? View.VISIBLE : View.GONE;
-        getKeyButtonViewById(R.id.dpad_left).setVisibility(visibility);
-        getKeyButtonViewById(R.id.dpad_right).setVisibility(visibility);
-    }
-    public void setDpadDarkIntensity(float darkIntensity) {
-        if (showDpadArrowKeys) {
-            getKeyButtonViewById(R.id.dpad_left).setDarkIntensity(darkIntensity);
-            getKeyButtonViewById(R.id.dpad_right).setDarkIntensity(darkIntensity);
-        }
-    }
-    private boolean showDpadArrowKeys() {
-        return Settings.System.getIntForUser(getContext().getContentResolver(),
-                OmniSettings.OMNI_NAVIGATION_BAR_ARROW_KEYS, 0, UserHandle.USER_CURRENT) != 0;
-    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/views/buttons/KeyButtonView.java b/packages/SystemUI/src/com/android/systemui/navigationbar/views/buttons/KeyButtonView.java
index 74fffbd..111a2d4 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/views/buttons/KeyButtonView.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/views/buttons/KeyButtonView.java
@@ -69,9 +69,6 @@
 public class KeyButtonView extends ImageView implements ButtonInterface {
     private static final String TAG = KeyButtonView.class.getSimpleName();
 
-    public static final int CURSOR_REPEAT_FLAGS = KeyEvent.FLAG_SOFT_KEYBOARD
-            | KeyEvent.FLAG_KEEP_TOUCH_MODE;
-
     private final boolean mPlaySounds;
     private final UiEventLogger mUiEventLogger;
     private int mContentDescriptionRes;
@@ -137,13 +134,7 @@
         public void run() {
             if (isPressed()) {
                 // Log.d("KeyButtonView", "longpressed: " + this);
-                if (mCode == KeyEvent.KEYCODE_DPAD_LEFT || mCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
-                    sendEvent(KeyEvent.ACTION_UP, CURSOR_REPEAT_FLAGS,
-                            System.currentTimeMillis(), false);
-                    sendEvent(KeyEvent.ACTION_DOWN, CURSOR_REPEAT_FLAGS,
-                            System.currentTimeMillis(), false);
-                    postDelayed(mCheckLongPress, ViewConfiguration.getKeyRepeatDelay());
-                } else if (isLongClickable()) {
+                if (isLongClickable()) {
                     // Just an old-fashioned ImageView
                     performLongClick();
                     mLongClicked = true;
@@ -310,10 +301,7 @@
 
                 mTouchDownX = (int) ev.getX();
                 mTouchDownY = (int) ev.getY();
-                if (mCode == KeyEvent.KEYCODE_DPAD_LEFT || mCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
-                    sendEvent(KeyEvent.ACTION_DOWN, KeyEvent.FLAG_VIRTUAL_HARD_KEY
-                            | KeyEvent.FLAG_KEEP_TOUCH_MODE, mDownTime, false);
-                } else if (mCode != KEYCODE_UNKNOWN) {
+                if (mCode != KEYCODE_UNKNOWN) {
                     sendEvent(KeyEvent.ACTION_DOWN, 0, mDownTime);
                 } else {
                     // Provide the same haptic feedback that the system offers for virtual keys.
@@ -450,10 +438,6 @@
     }
 
     private void sendEvent(int action, int flags, long when) {
-        sendEvent(action, flags, when, true);
-    }
-
-    private void sendEvent(int action, int flags, long when, boolean applyDefaultFlags) {
         mMetricsLogger.write(new LogMaker(MetricsEvent.ACTION_NAV_BUTTON_EVENT)
                 .setType(MetricsEvent.TYPE_ACTION)
                 .setSubtype(mCode)
@@ -464,12 +448,9 @@
             Log.i(TAG, "Back button event: " + KeyEvent.actionToString(action));
         }
         final int repeatCount = (flags & KeyEvent.FLAG_LONG_PRESS) != 0 ? 1 : 0;
-        if (applyDefaultFlags) {
-            flags |= KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY;
-        }
         final KeyEvent ev = new KeyEvent(mDownTime, when, action, mCode, repeatCount,
                 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
-                flags,
+                flags | KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY,
                 InputDevice.SOURCE_KEYBOARD);
 
         int displayId = INVALID_DISPLAY;