|
19 | 19 | import android.app.ActivityManagerNative; |
20 | 20 | import android.app.IUiModeManager; |
21 | 21 | import android.app.ProgressDialog; |
| 22 | +import android.app.SearchManager; |
22 | 23 | import android.app.UiModeManager; |
23 | 24 | import android.content.ActivityNotFoundException; |
24 | 25 | import android.content.BroadcastReceiver; |
@@ -235,6 +236,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { |
235 | 236 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
236 | 237 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
237 | 238 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
| 239 | + static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
238 | 240 |
|
239 | 241 | /** |
240 | 242 | * These are the system UI flags that, when changing, can cause the layout |
@@ -279,6 +281,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { |
279 | 281 | LocalPowerManager mPowerManager; |
280 | 282 | IStatusBarService mStatusBarService; |
281 | 283 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
| 284 | + SearchManager mSearchManager; |
282 | 285 |
|
283 | 286 | // Vibrator pattern for haptic feedback of a long press. |
284 | 287 | long[] mLongPressVibePattern; |
@@ -462,6 +465,7 @@ public void onInputEvent(InputEvent event) { |
462 | 465 | Intent mDeskDockIntent; |
463 | 466 | boolean mSearchKeyShortcutPending; |
464 | 467 | boolean mConsumeSearchKeyUp; |
| 468 | + boolean mAssistKeyLongPressed; |
465 | 469 |
|
466 | 470 | // support for activating the lock screen while the screen is on |
467 | 471 | boolean mAllowLockscreenWhenOn; |
@@ -1860,6 +1864,26 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p |
1860 | 1864 | showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS); |
1861 | 1865 | } |
1862 | 1866 | return -1; |
| 1867 | + } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 1868 | + if (down) { |
| 1869 | + if (repeatCount == 0) { |
| 1870 | + mAssistKeyLongPressed = false; |
| 1871 | + } else if (repeatCount == 1) { |
| 1872 | + mAssistKeyLongPressed = true; |
| 1873 | + if (!keyguardOn) { |
| 1874 | + launchAssistLongPressAction(); |
| 1875 | + } |
| 1876 | + } |
| 1877 | + } else { |
| 1878 | + if (mAssistKeyLongPressed) { |
| 1879 | + mAssistKeyLongPressed = false; |
| 1880 | + } else { |
| 1881 | + if (!keyguardOn) { |
| 1882 | + launchAssistAction(); |
| 1883 | + } |
| 1884 | + } |
| 1885 | + } |
| 1886 | + return -1; |
1863 | 1887 | } |
1864 | 1888 |
|
1865 | 1889 | // Shortcuts are invoked through Search+key, so intercept those here |
@@ -2050,6 +2074,50 @@ private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int p |
2050 | 2074 | return false; |
2051 | 2075 | } |
2052 | 2076 |
|
| 2077 | + private void launchAssistLongPressAction() { |
| 2078 | + performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2079 | + sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2080 | + |
| 2081 | + // launch the search activity |
| 2082 | + Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2083 | + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2084 | + try { |
| 2085 | + SearchManager searchManager = getSearchManager(); |
| 2086 | + if (searchManager != null) { |
| 2087 | + searchManager.stopSearch(); |
| 2088 | + } |
| 2089 | + mContext.startActivity(intent); |
| 2090 | + } catch (ActivityNotFoundException e) { |
| 2091 | + Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2092 | + } |
| 2093 | + } |
| 2094 | + |
| 2095 | + private void launchAssistAction() { |
| 2096 | + sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2097 | + |
| 2098 | + SearchManager searchManager = getSearchManager(); |
| 2099 | + if (searchManager != null) { |
| 2100 | + Intent intent = searchManager.getAssistIntent(); |
| 2101 | + if (intent != null) { |
| 2102 | + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2103 | + | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2104 | + | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2105 | + try { |
| 2106 | + mContext.startActivity(intent); |
| 2107 | + } catch (ActivityNotFoundException e) { |
| 2108 | + Slog.w(TAG, "No activity to handle assist action.", e); |
| 2109 | + } |
| 2110 | + } |
| 2111 | + } |
| 2112 | + } |
| 2113 | + |
| 2114 | + private SearchManager getSearchManager() { |
| 2115 | + if (mSearchManager == null) { |
| 2116 | + mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 2117 | + } |
| 2118 | + return mSearchManager; |
| 2119 | + } |
| 2120 | + |
2053 | 2121 | /** |
2054 | 2122 | * A home key -> launch home action was detected. Take the appropriate action |
2055 | 2123 | * given the situation with the keyguard. |
|
0 commit comments