diff options
| author | Phil Tunstall <ptunstall@gmail.com> | 2012-07-27 12:00:44 +0100 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@review.cyanogenmod.com> | 2012-12-10 16:50:22 -0800 |
| commit | b055725d0b1df2f23ecfa95bff940aa8b57f97df (patch) | |
| tree | 582b3ee8a9dadda15505bbcae960f4badec1eacc | |
| parent | f84e114527b5c4761026b34a8d08f0284d6c2f34 (diff) | |
| download | frameworks_base-b055725d0b1df2f23ecfa95bff940aa8b57f97df.zip frameworks_base-b055725d0b1df2f23ecfa95bff940aa8b57f97df.tar.gz frameworks_base-b055725d0b1df2f23ecfa95bff940aa8b57f97df.tar.bz2 | |
Hardware key custom rebinding (1/2)
Framework changes to allow rebinding of the actions performed on the following
key press events: Home long-press, menu press, menu long-press, search press,
search long-press, app-switch press and app-switch long-press.
The available actions are: Nothing, open/close menu, recent apps switcher,
search assistant, voice search and in-app search.
Patch Set 1: Initial port from ICS [done by Konstantin Koslowski]
Patch Set 2: Added 'assist' (search) key customisation
Option for ICS-style in-app search, in addition to jellybean-style
search assistant.
Fixed double haptic feedback on virtual key press.
Patch Set 3: Checkbox to enable/disable all custom bindings.
Home long-press defaults to no action on devices with
an app-switch key.
Patch Set 4: The recent apps list will be preloaded on the initial down press
of whichever key to which it is bound.
Patch Set 5: Fixed menu virtual key press sometimes performing the custom
action bound to the menu key instead of just opening or closing
the menu as it should.
Conflicts:
core/res/res/values/public.xml
policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
Change-Id: I72c0d220a09d79230bfa299e0521ed693e5c25f1
| -rw-r--r-- | core/java/android/provider/Settings.java | 70 | ||||
| -rw-r--r-- | core/java/android/view/ViewConfiguration.java | 17 | ||||
| -rwxr-xr-x | core/res/res/values/config.xml | 12 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 3 | ||||
| -rwxr-xr-x | policy/src/com/android/internal/policy/impl/PhoneWindowManager.java | 407 |
5 files changed, 415 insertions, 94 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index db2598f..9f66bc7 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -2896,6 +2896,76 @@ public final class Settings { public static final String LOCKSCREEN_VIBRATE_ENABLED = "lockscreen.vibrate_enabled"; /** + * Whether to enable custom rebindings of the actions performed on + * certain key press events. + * @hide + */ + public static final String HARDWARE_KEY_REBINDING = "hardware_key_rebinding"; + + /** + * Action to perform when the home key is long-pressed. (Default is 2) + * 0 - Nothing + * 1 - Menu + * 2 - App-switch + * 3 - Search + * 4 - Voice search + * 5 - In-app search + * @hide + */ + public static final String KEY_HOME_LONG_PRESS_ACTION = "key_home_long_press_action"; + + /** + * Action to perform when the menu key is pressed. (Default is 1) + * (See KEY_HOME_LONG_PRESS_ACTION for valid values) + * @hide + */ + public static final String KEY_MENU_ACTION = "key_menu_action"; + + /** + * Action to perform when the menu key is long-pressed. + * (Default is 0 on devices with a search key, 3 on devices without) + * (See KEY_HOME_LONG_PRESS_ACTION for valid values) + * @hide + */ + public static final String KEY_MENU_LONG_PRESS_ACTION = "key_menu_long_press_action"; + + /** + * Action to perform when the assistant (search) key is pressed. (Default is 3) + * (See KEY_HOME_LONG_PRESS_ACTION for valid values) + * @hide + */ + public static final String KEY_ASSIST_ACTION = "key_assist_action"; + + /** + * Action to perform when the assistant (search) key is long-pressed. (Default is 4) + * (See KEY_HOME_LONG_PRESS_ACTION for valid values) + * @hide + */ + public static final String KEY_ASSIST_LONG_PRESS_ACTION = "key_assist_long_press_action"; + + /** + * Action to perform when the app switch key is pressed. (Default is 2) + * (See KEY_HOME_LONG_PRESS_ACTION for valid values) + * @hide + */ + public static final String KEY_APP_SWITCH_ACTION = "key_app_switch_action"; + + /** + * Action to perform when the app switch key is long-pressed. (Default is 0) + * (See KEY_HOME_LONG_PRESS_ACTION for valid values) + * @hide + */ + public static final String KEY_APP_SWITCH_LONG_PRESS_ACTION = "key_app_switch_long_press_action"; + + /** + * Control the display of the action overflow button within app UI. + * 0 = use system default + * 1 = force on + * @hide + */ + public static final String UI_FORCE_OVERFLOW_BUTTON = "ui_force_overflow_button"; + + /** * Settings to backup. This is here so that it's in the same place as the settings * keys and easy to update. * diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index 499075e..73295a2 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -223,6 +223,8 @@ public class ViewConfiguration { private boolean sHasPermanentMenuKey; private boolean sHasPermanentMenuKeySet; + private Context mContext; + static final SparseArray<ViewConfiguration> sConfigurations = new SparseArray<ViewConfiguration>(2); @@ -270,6 +272,8 @@ public class ViewConfiguration { sizeAndDensity = density; } + mContext = context; + mEdgeSlop = (int) (sizeAndDensity * EDGE_SLOP + 0.5f); mFadingEdgeLength = (int) (sizeAndDensity * FADING_EDGE_LENGTH + 0.5f); mMinimumFlingVelocity = (int) (density * MINIMUM_FLING_VELOCITY + 0.5f); @@ -678,7 +682,18 @@ public class ViewConfiguration { * @return true if a permanent menu key is present, false otherwise. */ public boolean hasPermanentMenuKey() { - return sHasPermanentMenuKey; + // The action overflow button within app UI can + // be controlled with a system setting + int showOverflowButton = Settings.System.getInt( + mContext.getContentResolver(), + Settings.System.UI_FORCE_OVERFLOW_BUTTON, 0); + if (showOverflowButton == 1) { + // Force overflow button on by reporting that + // the device has no permanent menu key + return false; + } else { + return sHasPermanentMenuKey; + } } /** diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 54b3416..6be97b2 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1057,4 +1057,16 @@ <!-- Disable the home key unlock setting --> <bool name="config_disableHomeUnlockSetting">true</bool> + <!-- Hardware 'face' keys present on the device, stored as a bit field. + This integer should equal the sum of the corresponding value for each + of the following keys present: + 1 - Home + 2 - Back + 4 - Menu + 8 - Assistant (search) + 16 - App switch + For example, a device with Home, Back and Menu keys would set this + config to 7. --> + <integer name="config_deviceHardwareKeys">15</integer> + </resources> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 7faa65c..f6b8c10 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1837,6 +1837,9 @@ <java-symbol type="bool" name="config_smsSamsungCdmaAlternateMessageIDEncoding" /> <java-symbol type="bool" name="config_samsung_stk" /> + <!-- Hardware Key ReMapping --> + <java-symbol type="integer" name="config_deviceHardwareKeys" /> + <!-- Notification and battery light --> <java-symbol type="bool" name="config_intrusiveBatteryLed" /> <java-symbol type="bool" name="config_multiColorBatteryLed" /> diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 582aac0..022501b 100755 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -41,6 +41,7 @@ import android.content.res.TypedArray; import android.database.ContentObserver; import android.graphics.PixelFormat; import android.graphics.Rect; +import android.hardware.input.InputManager; import android.media.AudioManager; import android.media.IAudioService; import android.media.Ringtone; @@ -205,6 +206,24 @@ public class PhoneWindowManager implements WindowManagerPolicy { static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; + // Available custom actions to perform on a key press. + // Must match values for KEY_HOME_LONG_PRESS_ACTION in: + // core/java/android/provider/Settings.java + private static final int KEY_ACTION_NOTHING = 0; + private static final int KEY_ACTION_MENU = 1; + private static final int KEY_ACTION_APP_SWITCH = 2; + private static final int KEY_ACTION_SEARCH = 3; + private static final int KEY_ACTION_VOICE_SEARCH = 4; + private static final int KEY_ACTION_IN_APP_SEARCH = 5; + + // Masks for checking presence of hardware keys. + // Must match values in core/res/res/values/config.xml + private static final int KEY_MASK_HOME = 0x01; + private static final int KEY_MASK_BACK = 0x02; + private static final int KEY_MASK_MENU = 0x04; + private static final int KEY_MASK_ASSIST = 0x08; + private static final int KEY_MASK_APP_SWITCH = 0x10; + /** * These are the system UI flags that, when changing, can cause the layout * of the screen to change. @@ -333,6 +352,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mHasSoftInput = false; int mBackKillTimeout; int mPointerLocationMode = 0; // guarded by mLock + int mDeviceHardwareKeys; + boolean mHasHomeKey; + boolean mHasMenuKey; + boolean mHasAssistKey; + boolean mHasAppSwitchKey; // The last window we were told about in focusChanged. WindowState mFocusedWindow; @@ -447,8 +471,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mShowingLockscreen; boolean mShowingDream; boolean mDreamingLockscreen; - boolean mHomePressed; boolean mHomeLongPressed; + boolean mAppSwitchLongPressed; Intent mHomeIntent; Intent mCarDockIntent; Intent mDeskDockIntent; @@ -456,6 +480,25 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mConsumeSearchKeyUp; boolean mAssistKeyLongPressed; + // Used when key is pressed and performing non-default action + boolean mMenuDoCustomAction; + + // Tracks user-customisable behavior for certain key events + private int mLongPressOnHomeBehavior = -1; + private int mPressOnMenuBehavior = -1; + private int mLongPressOnMenuBehavior = -1; + private int mPressOnAssistBehavior = -1; + private int mLongPressOnAssistBehavior = -1; + private int mPressOnAppSwitchBehavior = -1; + private int mLongPressOnAppSwitchBehavior = -1; + + // To identify simulated keypresses, so we can perform + // the default action for that key + private boolean mIsVirtualKeypress; + + // Tracks preloading of the recent apps screen + private boolean mRecentAppsPreloaded; + // support for activating the lock screen while the screen is on boolean mAllowLockscreenWhenOn; int mLockScreenTimeout; @@ -475,9 +518,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { int mPortraitRotation = 0; // default portrait rotation int mUpsideDownRotation = 0; // "other" portrait rotation - // What we do when the user long presses on home - private int mLongPressOnHomeBehavior = -1; - // Screenshot trigger states // Time to volume and power must be pressed within this interval of each other. private static final long ACTION_CHORD_DEBOUNCE_DELAY_MILLIS = 150; @@ -578,6 +618,22 @@ public class PhoneWindowManager implements WindowManagerPolicy { resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.ACCELEROMETER_ROTATION_ANGLES), false, this, UserHandle.USER_ALL); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.KEY_HOME_LONG_PRESS_ACTION), false, this); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.KEY_MENU_ACTION), false, this); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.KEY_MENU_LONG_PRESS_ACTION), false, this); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.KEY_ASSIST_ACTION), false, this); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.KEY_ASSIST_LONG_PRESS_ACTION), false, this); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.KEY_APP_SWITCH_ACTION), false, this); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.KEY_APP_SWITCH_LONG_PRESS_ACTION), false, this); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.HARDWARE_KEY_REBINDING), false, this); updateSettings(); } @@ -934,39 +990,85 @@ public class PhoneWindowManager implements WindowManagerPolicy { mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; } - private void handleLongPressOnHome() { - // We can't initialize this in init() since the configuration hasn't been loaded yet. - if (mLongPressOnHomeBehavior < 0) { - mLongPressOnHomeBehavior - = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior); - if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || - mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) { - mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; + private void triggerVirtualKeypress(final int keyCode) { + new Thread(new Runnable() { + public void run() { + InputManager im = InputManager.getInstance(); + long now = SystemClock.uptimeMillis(); + + final KeyEvent downEvent = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, + keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, + KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD); + final KeyEvent upEvent = KeyEvent.changeAction(downEvent, KeyEvent.ACTION_UP); + + mIsVirtualKeypress = true; + im.injectInputEvent(downEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT); + im.injectInputEvent(upEvent, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT); + mIsVirtualKeypress = false; } - } + }).start(); + } - if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { - performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); - sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); + private void performKeyAction(int behavior) { + switch (behavior) { + case KEY_ACTION_NOTHING: + break; + case KEY_ACTION_MENU: + triggerVirtualKeypress(KeyEvent.KEYCODE_MENU); + break; + case KEY_ACTION_APP_SWITCH: + sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); + try { + IStatusBarService statusbar = getStatusBarService(); + if (statusbar != null) { + statusbar.toggleRecentApps(); + mRecentAppsPreloaded = false; + } + } catch (RemoteException e) { + Slog.e(TAG, "RemoteException when showing recent apps", e); + // re-acquire status bar service next time it is needed. + mStatusBarService = null; + } + break; + case KEY_ACTION_SEARCH: + launchAssistAction(); + break; + case KEY_ACTION_VOICE_SEARCH: + launchAssistLongPressAction(); + break; + case KEY_ACTION_IN_APP_SEARCH: + triggerVirtualKeypress(KeyEvent.KEYCODE_SEARCH); + break; + default: + break; + } + } - // Eat the longpress so it won't dismiss the recent apps dialog when - // the user lets go of the home key - mHomeLongPressed = true; + private void preloadRecentApps() { + try { + IStatusBarService statusbar = getStatusBarService(); + if (statusbar != null) { + statusbar.preloadRecentApps(); + mRecentAppsPreloaded = true; + } + } catch (RemoteException e) { + Slog.e(TAG, "RemoteException when preloading recent apps", e); + // re-acquire status bar service next time it is needed. + mStatusBarService = null; } + } - if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) { - showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS); - } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { - try { - IStatusBarService statusbar = getStatusBarService(); - if (statusbar != null) { - statusbar.toggleRecentApps(); - } - } catch (RemoteException e) { - Slog.e(TAG, "RemoteException when showing recent apps", e); - // re-acquire status bar service next time it is needed. - mStatusBarService = null; + private void cancelPreloadRecentApps() { + try { + IStatusBarService statusbar = getStatusBarService(); + if (statusbar != null) { + statusbar.cancelPreloadRecentApps(); + mRecentAppsPreloaded = false; } + } catch (RemoteException e) { + Slog.e(TAG, "RemoteException when showing recent apps", e); + // re-acquire status bar service next time it is needed. + mStatusBarService = null; } } @@ -1071,6 +1173,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { com.android.internal.R.bool.config_lidControlsSleep); mBackKillTimeout = mContext.getResources().getInteger( com.android.internal.R.integer.config_backKillTimeout); + mDeviceHardwareKeys = mContext.getResources().getInteger( + com.android.internal.R.integer.config_deviceHardwareKeys); + mHasHomeKey = ((mDeviceHardwareKeys & KEY_MASK_HOME) != 0); + mHasMenuKey = ((mDeviceHardwareKeys & KEY_MASK_MENU) != 0); + mHasAssistKey = ((mDeviceHardwareKeys & KEY_MASK_ASSIST) != 0); + mHasAppSwitchKey = ((mDeviceHardwareKeys & KEY_MASK_APP_SWITCH) != 0); // register for dock events IntentFilter filter = new IntentFilter(); @@ -1250,6 +1358,68 @@ public class PhoneWindowManager implements WindowManagerPolicy { mVolBtnMusicControls = (Settings.System.getIntForUser(resolver, Settings.System.VOLBTN_MUSIC_CONTROLS, 1, UserHandle.USER_CURRENT) == 1); + boolean keyRebindingEnabled = Settings.System.getInt(resolver, + Settings.System.HARDWARE_KEY_REBINDING, 0) == 1; + + if (!keyRebindingEnabled) { + if (mHasHomeKey) { + if (mHasAppSwitchKey) { + mLongPressOnHomeBehavior = KEY_ACTION_NOTHING; + } else { + mLongPressOnHomeBehavior = KEY_ACTION_APP_SWITCH; + } + } + if (mHasMenuKey) { + mPressOnMenuBehavior = KEY_ACTION_MENU; + if (mHasAssistKey) { + mLongPressOnMenuBehavior = KEY_ACTION_NOTHING; + } else { + mLongPressOnMenuBehavior = KEY_ACTION_SEARCH; + } + } + if (mHasAssistKey) { + mPressOnAssistBehavior = KEY_ACTION_SEARCH; + mLongPressOnAssistBehavior = KEY_ACTION_VOICE_SEARCH; + } + if (mHasAppSwitchKey) { + mPressOnAppSwitchBehavior = KEY_ACTION_APP_SWITCH; + mLongPressOnAppSwitchBehavior = KEY_ACTION_NOTHING; + } + } else { + if (mHasHomeKey) { + if (mHasAppSwitchKey) { + mLongPressOnHomeBehavior = Settings.System.getInt(resolver, + Settings.System.KEY_HOME_LONG_PRESS_ACTION, KEY_ACTION_NOTHING); + } else { + mLongPressOnHomeBehavior = Settings.System.getInt(resolver, + Settings.System.KEY_HOME_LONG_PRESS_ACTION, KEY_ACTION_APP_SWITCH); + } + } + if (mHasMenuKey) { + mPressOnMenuBehavior = Settings.System.getInt(resolver, + Settings.System.KEY_MENU_ACTION, KEY_ACTION_MENU); + if (mHasAssistKey) { + mLongPressOnMenuBehavior = Settings.System.getInt(resolver, + Settings.System.KEY_MENU_LONG_PRESS_ACTION, KEY_ACTION_NOTHING); + } else { + mLongPressOnMenuBehavior = Settings.System.getInt(resolver, + Settings.System.KEY_MENU_LONG_PRESS_ACTION, KEY_ACTION_SEARCH); + } + } + if (mHasAssistKey) { + mPressOnAssistBehavior = Settings.System.getInt(resolver, + Settings.System.KEY_ASSIST_ACTION, KEY_ACTION_SEARCH); + mLongPressOnAssistBehavior = Settings.System.getInt(resolver, + Settings.System.KEY_ASSIST_LONG_PRESS_ACTION, KEY_ACTION_VOICE_SEARCH); + } + if (mHasAppSwitchKey) { + mPressOnAppSwitchBehavior = Settings.System.getInt(resolver, + Settings.System.KEY_APP_SWITCH_ACTION, KEY_ACTION_APP_SWITCH); + mLongPressOnAppSwitchBehavior = Settings.System.getInt(resolver, + Settings.System.KEY_APP_SWITCH_LONG_PRESS_ACTION, KEY_ACTION_NOTHING); + } + } + // Configure rotation lock. int userRotation = Settings.System.getIntForUser(resolver, Settings.System.USER_ROTATION, Surface.ROTATION_0, @@ -1975,11 +2145,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { final int flags = event.getFlags(); final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; final boolean canceled = event.isCanceled(); + final boolean longPress = (flags & KeyEvent.FLAG_LONG_PRESS) != 0; if (DEBUG_INPUT) { Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" - + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed - + " canceled=" + canceled); + + repeatCount + " keyguardOn=" + keyguardOn + " canceled=" + canceled); } // If we think we might have a volume down & power/volume-up key chord on the way @@ -2027,25 +2197,13 @@ public class PhoneWindowManager implements WindowManagerPolicy { // If we have released the home key, and didn't do anything else // while it was pressed, then it is time to go home! - if (!down && mHomePressed) { + if (!down) { final boolean homeWasLongPressed = mHomeLongPressed; - mHomePressed = false; mHomeLongPressed = false; if (!homeWasLongPressed) { - if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { - try { - IStatusBarService statusbar = getStatusBarService(); - if (statusbar != null) { - statusbar.cancelPreloadRecentApps(); - } - } catch (RemoteException e) { - Slog.e(TAG, "RemoteException when showing recent apps", e); - // re-acquire status bar service next time it is needed. - mStatusBarService = null; - } + if (mRecentAppsPreloaded) { + cancelPreloadRecentApps(); } - - mHomePressed = false; if (!canceled) { // If an incoming call is ringing, HOME is totally disabled. // (The user is already on the InCallScreen at this point, @@ -2091,23 +2249,15 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } if (down) { - if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { - try { - IStatusBarService statusbar = getStatusBarService(); - if (statusbar != null) { - statusbar.preloadRecentApps(); - } - } catch (RemoteException e) { - Slog.e(TAG, "RemoteException when preloading recent apps", e); - // re-acquire status bar service next time it is needed. - mStatusBarService = null; - } + if (!mRecentAppsPreloaded && mLongPressOnHomeBehavior == KEY_ACTION_APP_SWITCH) { + preloadRecentApps(); } - if (repeatCount == 0) { - mHomePressed = true; - } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { - if (!keyguardOn) { - handleLongPressOnHome(); + if (longPress) { + if (!keyguardOn && mLongPressOnHomeBehavior != KEY_ACTION_NOTHING) { + performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); + performKeyAction(mLongPressOnHomeBehavior); + // Eat the long-press so it won't take us home when the key is released + mHomeLongPressed = true; } } } @@ -2116,27 +2266,58 @@ public class PhoneWindowManager implements WindowManagerPolicy { // Hijack modified menu keys for debugging features final int chordBug = KeyEvent.META_SHIFT_ON; - if (down && repeatCount == 0) { - if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { - Intent intent = new Intent(Intent.ACTION_BUG_REPORT); - mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, - null, null, null, 0, null, null); - return -1; - } else if (SHOW_PROCESSES_ON_ALT_MENU && - (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { - Intent service = new Intent(); - service.setClassName(mContext, "com.android.server.LoadAverageService"); - ContentResolver res = mContext.getContentResolver(); - boolean shown = Settings.Global.getInt( - res, Settings.Global.SHOW_PROCESSES, 0) != 0; - if (!shown) { - mContext.startService(service); - } else { - mContext.stopService(service); + if (down) { + if (!mRecentAppsPreloaded && (mPressOnMenuBehavior == KEY_ACTION_APP_SWITCH || + mLongPressOnMenuBehavior == KEY_ACTION_APP_SWITCH)) { + preloadRecentApps(); + } + if (repeatCount == 0) { + if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { + Intent intent = new Intent(Intent.ACTION_BUG_REPORT); + mContext.sendOrderedBroadcast(intent, null); + return -1; + } else if (SHOW_PROCESSES_ON_ALT_MENU && + (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { + Intent service = new Intent(); + service.setClassName(mContext, "com.android.server.LoadAverageService"); + ContentResolver res = mContext.getContentResolver(); + boolean shown = Settings.System.getInt( + res, Settings.System.SHOW_PROCESSES, 0) != 0; + if (!shown) { + mContext.startService(service); + } else { + mContext.stopService(service); + } + Settings.System.putInt( + res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1); + return -1; + } else if (mPressOnMenuBehavior != KEY_ACTION_MENU && !mIsVirtualKeypress) { + mMenuDoCustomAction = true; + return -1; + } + } else if (longPress) { + if (mRecentAppsPreloaded && + mLongPressOnMenuBehavior != KEY_ACTION_APP_SWITCH) { + cancelPreloadRecentApps(); + } + if (!keyguardOn && mLongPressOnMenuBehavior != KEY_ACTION_NOTHING) { + performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); + performKeyAction(mLongPressOnMenuBehavior); + // Do not perform action when key is released + mMenuDoCustomAction = false; + return -1; + } + } + } else { + if (mRecentAppsPreloaded && mPressOnMenuBehavior != KEY_ACTION_APP_SWITCH) { + cancelPreloadRecentApps(); + } + if (mMenuDoCustomAction) { + mMenuDoCustomAction = false; + if (!canceled && !keyguardOn) { + performKeyAction(mPressOnMenuBehavior); + return -1; } - Settings.Global.putInt( - res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); - return -1; } } } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { @@ -2154,26 +2335,68 @@ public class PhoneWindowManager implements WindowManagerPolicy { } return 0; } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { - if (down && repeatCount == 0 && !keyguardOn) { - showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS); + if (down) { + if (!mRecentAppsPreloaded && (mPressOnAppSwitchBehavior == KEY_ACTION_APP_SWITCH || + mLongPressOnAppSwitchBehavior == KEY_ACTION_APP_SWITCH)) { + preloadRecentApps(); + } + if (repeatCount == 0) { + mAppSwitchLongPressed = false; + } else if (longPress) { + if (mRecentAppsPreloaded && + mLongPressOnAppSwitchBehavior != KEY_ACTION_APP_SWITCH) { + cancelPreloadRecentApps(); + } + if (!keyguardOn && mLongPressOnAppSwitchBehavior != KEY_ACTION_NOTHING) { + performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); + performKeyAction(mLongPressOnAppSwitchBehavior); + mAppSwitchLongPressed = true; + } + } + } else { + if (mAppSwitchLongPressed) { + mAppSwitchLongPressed = false; + } else { + if (mRecentAppsPreloaded && + mPressOnAppSwitchBehavior != KEY_ACTION_APP_SWITCH) { + cancelPreloadRecentApps(); + } + if (!canceled && !keyguardOn) { + performKeyAction(mPressOnAppSwitchBehavior); + } + return -1; + } } return -1; } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { if (down) { + if (!mRecentAppsPreloaded && (mPressOnAssistBehavior == KEY_ACTION_APP_SWITCH || + mLongPressOnAssistBehavior == KEY_ACTION_APP_SWITCH)) { + preloadRecentApps(); + } if (repeatCount == 0) { mAssistKeyLongPressed = false; - } else if (repeatCount == 1) { - mAssistKeyLongPressed = true; - if (!keyguardOn) { - launchAssistLongPressAction(); + } else if (longPress) { + if (mRecentAppsPreloaded && + mLongPressOnAssistBehavior != KEY_ACTION_APP_SWITCH) { + cancelPreloadRecentApps(); + } + if (!keyguardOn && mLongPressOnAssistBehavior != KEY_ACTION_NOTHING) { + performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); + performKeyAction(mLongPressOnAssistBehavior); + mAssistKeyLongPressed = true; } } } else { if (mAssistKeyLongPressed) { mAssistKeyLongPressed = false; } else { + if (mRecentAppsPreloaded && + mPressOnAssistBehavior != KEY_ACTION_APP_SWITCH) { + cancelPreloadRecentApps(); + } if (!keyguardOn) { - launchAssistAction(); + performKeyAction(mPressOnAssistBehavior); } } } @@ -2376,7 +2599,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { } private void launchAssistLongPressAction() { - performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); // launch the search activity @@ -4932,7 +5154,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { pw.println(mForceStatusBarFromKeyguard); pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); - pw.print(" mHomePressed="); pw.println(mHomePressed); pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
