Skip to content

Commit 9e19714

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Add new ASSIST key and map it to the global assist intent." into jb-dev
2 parents f9b7f9f + de7a8ea commit 9e19714

File tree

8 files changed

+116
-53
lines changed

8 files changed

+116
-53
lines changed

api/16.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23186,6 +23186,7 @@ package android.view {
2318623186
field public static final int KEYCODE_ALT_RIGHT = 58; // 0x3a
2318723187
field public static final int KEYCODE_APOSTROPHE = 75; // 0x4b
2318823188
field public static final int KEYCODE_APP_SWITCH = 187; // 0xbb
23189+
field public static final int KEYCODE_ASSIST = 219; // 0xdb
2318923190
field public static final int KEYCODE_AT = 77; // 0x4d
2319023191
field public static final int KEYCODE_AVR_INPUT = 182; // 0xb6
2319123192
field public static final int KEYCODE_AVR_POWER = 181; // 0xb5

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23197,6 +23197,7 @@ package android.view {
2319723197
field public static final int KEYCODE_ALT_RIGHT = 58; // 0x3a
2319823198
field public static final int KEYCODE_APOSTROPHE = 75; // 0x4b
2319923199
field public static final int KEYCODE_APP_SWITCH = 187; // 0xbb
23200+
field public static final int KEYCODE_ASSIST = 219; // 0xdb
2320023201
field public static final int KEYCODE_AT = 77; // 0x4d
2320123202
field public static final int KEYCODE_AVR_INPUT = 182; // 0xb6
2320223203
field public static final int KEYCODE_AVR_POWER = 181; // 0xb5

core/java/android/app/SearchManager.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.content.Context;
2323
import android.content.DialogInterface;
2424
import android.content.Intent;
25+
import android.content.pm.PackageManager;
2526
import android.content.pm.ResolveInfo;
2627
import android.database.Cursor;
2728
import android.graphics.Rect;
@@ -32,6 +33,7 @@
3233
import android.os.ServiceManager;
3334
import android.text.TextUtils;
3435
import android.util.Log;
36+
import android.util.Slog;
3537
import android.view.KeyEvent;
3638

3739
import java.util.List;
@@ -837,4 +839,32 @@ public List<SearchableInfo> getSearchablesInGlobalSearch() {
837839
}
838840
}
839841

842+
/**
843+
* Returns true if the global assist activity is available.
844+
* @return True if the assistant is available.
845+
*
846+
* @hide
847+
*/
848+
public final boolean isAssistantAvailable() {
849+
Intent intent = getAssistIntent();
850+
return intent != null
851+
&& mContext.getPackageManager().queryIntentActivities(intent,
852+
PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
853+
}
854+
855+
/**
856+
* Gets an intent to launch the global assist activity, or null if not available.
857+
* @return The assist intent.
858+
*
859+
* @hide
860+
*/
861+
public final Intent getAssistIntent() {
862+
ComponentName globalSearchActivity = getGlobalSearchActivity();
863+
if (globalSearchActivity != null) {
864+
Intent intent = new Intent(Intent.ACTION_ASSIST);
865+
intent.setPackage(globalSearchActivity.getPackageName());
866+
return intent;
867+
}
868+
return null;
869+
}
840870
}

core/java/android/view/KeyEvent.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,11 @@ public class KeyEvent extends InputEvent implements Parcelable {
620620
public static final int KEYCODE_RO = 217;
621621
/** Key code constant: Japanese kana key. */
622622
public static final int KEYCODE_KANA = 218;
623+
/** Key code constant: Assist key.
624+
* Launches the global assist activity. Not delivered to applications. */
625+
public static final int KEYCODE_ASSIST = 219;
623626

624-
private static final int LAST_KEYCODE = KEYCODE_KANA;
627+
private static final int LAST_KEYCODE = KEYCODE_ASSIST;
625628

626629
// NOTE: If you add a new keycode here you must also add it to:
627630
// isSystem()
@@ -862,6 +865,7 @@ private static void populateKeycodeSymbolicNames() {
862865
names.append(KEYCODE_YEN, "KEYCODE_YEN");
863866
names.append(KEYCODE_RO, "KEYCODE_RO");
864867
names.append(KEYCODE_KANA, "KEYCODE_KANA");
868+
names.append(KEYCODE_ASSIST, "KEYCODE_ASSIST");
865869
};
866870

867871
// Symbolic names of all metakeys in bit order from least significant to most significant.

include/androidfw/KeycodeLabels.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ static const KeycodeLabel KEYCODES[] = {
243243
{ "YEN", 216 },
244244
{ "RO", 217 },
245245
{ "KANA", 218 },
246+
{ "ASSIST", 219 },
246247

247248
// NOTE: If you add a new keycode here you must also add it to several other files.
248249
// Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.

packages/SystemUI/src/com/android/systemui/SearchPanelView.java

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import android.content.ComponentName;
2424
import android.content.Context;
2525
import android.content.Intent;
26-
import android.content.pm.PackageManager;
2726
import android.content.res.Resources;
2827
import android.os.Vibrator;
2928
import android.provider.Settings;
@@ -35,6 +34,7 @@
3534
import android.view.ViewTreeObserver;
3635
import android.view.ViewTreeObserver.OnPreDrawListener;
3736
import android.widget.FrameLayout;
37+
3838
import com.android.internal.widget.multiwaveview.GlowPadView;
3939
import com.android.internal.widget.multiwaveview.GlowPadView.OnTriggerListener;
4040
import com.android.systemui.R;
@@ -53,6 +53,7 @@ public class SearchPanelView extends FrameLayout implements
5353
private static final String ASSIST_ICON_METADATA_NAME =
5454
"com.android.systemui.action_assist_icon";
5555
private final Context mContext;
56+
private final SearchManager mSearchManager;
5657
private BaseStatusBar mBar;
5758
private StatusBarTouchProxy mStatusBarTouchProxy;
5859

@@ -73,38 +74,12 @@ public SearchPanelView(Context context, AttributeSet attrs, int defStyle) {
7374
}
7475
}
7576

76-
private SearchManager mSearchManager;
77-
78-
// This code should be the same as that used in LockScreen.java
7977
public boolean isAssistantAvailable() {
80-
Intent intent = getAssistIntent();
81-
return intent == null ? false
82-
: mContext.getPackageManager().queryIntentActivities(intent,
83-
PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
78+
return mSearchManager != null && mSearchManager.isAssistantAvailable();
8479
}
8580

8681
private Intent getAssistIntent() {
87-
Intent intent = null;
88-
SearchManager searchManager = getSearchManager();
89-
if (searchManager != null) {
90-
ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
91-
if (globalSearchActivity != null) {
92-
intent = new Intent(Intent.ACTION_ASSIST);
93-
intent.setPackage(globalSearchActivity.getPackageName());
94-
} else {
95-
Slog.w(TAG, "No global search activity");
96-
}
97-
} else {
98-
Slog.w(TAG, "No SearchManager");
99-
}
100-
return intent;
101-
}
102-
103-
private SearchManager getSearchManager() {
104-
if (mSearchManager == null) {
105-
mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
106-
}
107-
return mSearchManager;
82+
return mSearchManager != null ? mSearchManager.getAssistIntent() : null;
10883
}
10984

11085
private void startAssistActivity() {
@@ -175,9 +150,8 @@ protected void onFinishInflate() {
175150
// TODO: fetch views
176151
mGlowPadView = (GlowPadView) findViewById(R.id.glow_pad_view);
177152
mGlowPadView.setOnTriggerListener(mGlowPadViewListener);
178-
SearchManager searchManager = getSearchManager();
179-
if (searchManager != null) {
180-
ComponentName component = searchManager.getGlobalSearchActivity();
153+
if (mSearchManager != null) {
154+
ComponentName component = mSearchManager.getGlobalSearchActivity();
181155
if (component != null) {
182156
if (!mGlowPadView.replaceTargetDrawablesIfPresent(component,
183157
ASSIST_ICON_METADATA_NAME,

policy/src/com/android/internal/policy/impl/LockScreen.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import android.content.ComponentName;
3333
import android.content.Context;
3434
import android.content.Intent;
35-
import android.content.pm.PackageManager;
3635
import android.content.res.Configuration;
3736
import android.content.res.Resources;
3837
import android.os.Vibrator;
@@ -254,29 +253,14 @@ public void cleanUp() {
254253
}
255254
}
256255

257-
// This code should be the same as that in SearchPanelView
258-
public boolean isAssistantAvailable() {
259-
Intent intent = getAssistIntent();
260-
return intent == null ? false
261-
: mContext.getPackageManager().queryIntentActivities(intent,
262-
PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
256+
private boolean isAssistantAvailable() {
257+
SearchManager searchManager = getSearchManager();
258+
return searchManager != null && searchManager.isAssistantAvailable();
263259
}
264260

265261
private Intent getAssistIntent() {
266-
Intent intent = null;
267262
SearchManager searchManager = getSearchManager();
268-
if (searchManager != null) {
269-
ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
270-
if (globalSearchActivity != null) {
271-
intent = new Intent(Intent.ACTION_ASSIST);
272-
intent.setPackage(globalSearchActivity.getPackageName());
273-
} else {
274-
Slog.w(TAG, "No global search activity");
275-
}
276-
} else {
277-
Slog.w(TAG, "No SearchManager");
278-
}
279-
return intent;
263+
return searchManager != null ? searchManager.getAssistIntent() : null;
280264
}
281265

282266
private SearchManager getSearchManager() {

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.app.ActivityManagerNative;
2020
import android.app.IUiModeManager;
2121
import android.app.ProgressDialog;
22+
import android.app.SearchManager;
2223
import android.app.UiModeManager;
2324
import android.content.ActivityNotFoundException;
2425
import android.content.BroadcastReceiver;
@@ -235,6 +236,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
235236
static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
236237
static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
237238
static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
239+
static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
238240

239241
/**
240242
* These are the system UI flags that, when changing, can cause the layout
@@ -279,6 +281,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
279281
LocalPowerManager mPowerManager;
280282
IStatusBarService mStatusBarService;
281283
Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
284+
SearchManager mSearchManager;
282285

283286
// Vibrator pattern for haptic feedback of a long press.
284287
long[] mLongPressVibePattern;
@@ -462,6 +465,7 @@ public void onInputEvent(InputEvent event) {
462465
Intent mDeskDockIntent;
463466
boolean mSearchKeyShortcutPending;
464467
boolean mConsumeSearchKeyUp;
468+
boolean mAssistKeyLongPressed;
465469

466470
// support for activating the lock screen while the screen is on
467471
boolean mAllowLockscreenWhenOn;
@@ -1860,6 +1864,26 @@ public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int p
18601864
showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
18611865
}
18621866
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;
18631887
}
18641888

18651889
// Shortcuts are invoked through Search+key, so intercept those here
@@ -2050,6 +2074,50 @@ private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int p
20502074
return false;
20512075
}
20522076

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+
20532121
/**
20542122
* A home key -> launch home action was detected. Take the appropriate action
20552123
* given the situation with the keyguard.

0 commit comments

Comments
 (0)