Skip to content

Commit 516c25b

Browse files
Jim MillerAndroid (Google) Code Review
authored andcommitted
Merge "Fix 6414061: Add new ACTION_ASSIST intent." into jb-dev
2 parents df35aa4 + 0799440 commit 516c25b

File tree

5 files changed

+60
-24
lines changed

5 files changed

+60
-24
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5661,6 +5661,7 @@ package android.content {
56615661
field public static final java.lang.String ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
56625662
field public static final java.lang.String ACTION_ANSWER = "android.intent.action.ANSWER";
56635663
field public static final java.lang.String ACTION_APP_ERROR = "android.intent.action.APP_ERROR";
5664+
field public static final java.lang.String ACTION_ASSIST = "android.intent.action.ASSIST";
56645665
field public static final java.lang.String ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
56655666
field public static final java.lang.String ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
56665667
field public static final java.lang.String ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";

core/java/android/content/Intent.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,14 @@ public static Intent createChooser(Intent target, CharSequence title) {
10981098
*/
10991099
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
11001100
public static final String ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
1101+
/**
1102+
* Activity Action: Perform assist action.
1103+
* <p>
1104+
* Input: nothing
1105+
* Output: nothing.
1106+
*/
1107+
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
1108+
public static final String ACTION_ASSIST = "android.intent.action.ASSIST";
11011109
/**
11021110
* Activity Action: List all available applications
11031111
* <p>Input: Nothing.

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

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public class SearchPanelView extends FrameLayout implements
5252
private boolean mShowing;
5353
private View mSearchTargetsContainer;
5454
private MultiWaveView mMultiWaveView;
55-
private SearchManager mSearchManager;
5655

5756
public SearchPanelView(Context context, AttributeSet attrs) {
5857
this(context, attrs, 0);
@@ -67,10 +66,30 @@ public SearchPanelView(Context context, AttributeSet attrs, int defStyle) {
6766
}
6867
}
6968

70-
public boolean isSearchAvailable() {
69+
private SearchManager mSearchManager;
70+
71+
public boolean isAssistantAvailable() {
7172
return mSearchManager != null && mSearchManager.getGlobalSearchActivity() != null;
7273
}
7374

75+
private void startAssistActivity() {
76+
if (mSearchManager != null) {
77+
ComponentName globalSearchActivity = mSearchManager.getGlobalSearchActivity();
78+
if (globalSearchActivity != null) {
79+
Intent intent = new Intent(Intent.ACTION_ASSIST);
80+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
81+
intent.setPackage(globalSearchActivity.getPackageName());
82+
try {
83+
mContext.startActivity(intent);
84+
} catch (ActivityNotFoundException e) {
85+
Slog.w(TAG, "Activity not found for " + intent.getAction());
86+
}
87+
} else {
88+
Slog.w(TAG, "No global search activity");
89+
}
90+
}
91+
}
92+
7493
final MultiWaveView.OnTriggerListener mMultiWaveViewListener
7594
= new MultiWaveView.OnTriggerListener() {
7695

@@ -90,29 +109,11 @@ public void onTrigger(View v, int target) {
90109
final int resId = mMultiWaveView.getResourceIdForTarget(target);
91110
switch (resId) {
92111
case com.android.internal.R.drawable.ic_lockscreen_search:
93-
startGlobalSearch();
112+
startAssistActivity();
94113
break;
95114
}
96115
mBar.hideSearchPanel();
97116
}
98-
99-
private void startGlobalSearch() {
100-
if (mSearchManager != null) {
101-
ComponentName globalSearchActivity = mSearchManager.getGlobalSearchActivity();
102-
if (globalSearchActivity != null) {
103-
Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
104-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
105-
intent.setComponent(globalSearchActivity);
106-
try {
107-
mContext.startActivity(intent);
108-
} catch (ActivityNotFoundException e) {
109-
Slog.w(TAG, "Application not found for action " + intent.getAction());
110-
}
111-
} else {
112-
Slog.w(TAG, "No global search activity");
113-
}
114-
}
115-
}
116117
};
117118

118119
@Override

packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public void handleMessage(Message m) {
397397
break;
398398
case MSG_OPEN_SEARCH_PANEL:
399399
if (DEBUG) Slog.d(TAG, "opening search panel");
400-
if (mSearchPanelView != null && mSearchPanelView.isSearchAvailable()) {
400+
if (mSearchPanelView != null && mSearchPanelView.isAssistantAvailable()) {
401401
mSearchPanelView.show(true, true);
402402
}
403403
break;

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import android.app.ActivityManagerNative;
3030
import android.app.SearchManager;
3131
import android.content.ActivityNotFoundException;
32+
import android.content.ComponentName;
3233
import android.content.Context;
3334
import android.content.Intent;
3435
import android.content.res.Configuration;
@@ -38,8 +39,8 @@
3839
import android.view.View;
3940
import android.view.ViewGroup;
4041
import android.widget.*;
41-
import android.speech.RecognizerIntent;
4242
import android.util.Log;
43+
import android.util.Slog;
4344
import android.media.AudioManager;
4445
import android.os.RemoteException;
4546
import android.provider.MediaStore;
@@ -80,6 +81,7 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
8081
private View mUnlockWidget;
8182
private boolean mCameraDisabled;
8283
private boolean mSearchDisabled;
84+
private SearchManager mSearchManager;
8385

8486
InfoCallbackImpl mInfoCallback = new InfoCallbackImpl() {
8587

@@ -237,6 +239,25 @@ public int getTargetPosition(int resourceId) {
237239
}
238240
}
239241

242+
private Intent getAssistIntent() {
243+
Intent intent = null;
244+
if (mSearchManager == null) {
245+
mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
246+
}
247+
if (mSearchManager != null) {
248+
ComponentName globalSearchActivity = mSearchManager.getGlobalSearchActivity();
249+
if (globalSearchActivity != null) {
250+
intent = new Intent(Intent.ACTION_ASSIST);
251+
intent.setPackage(globalSearchActivity.getPackageName());
252+
} else {
253+
Slog.w(TAG, "No global search activity");
254+
}
255+
} else {
256+
Slog.w(TAG, "No SearchManager");
257+
}
258+
return intent;
259+
}
260+
240261
class MultiWaveViewMethods implements MultiWaveView.OnTriggerListener,
241262
UnlockWidgetCommonMethods {
242263
private final MultiWaveView mMultiWaveView;
@@ -279,7 +300,12 @@ public void onTrigger(View v, int target) {
279300
final int resId = mMultiWaveView.getResourceIdForTarget(target);
280301
switch (resId) {
281302
case com.android.internal.R.drawable.ic_lockscreen_search:
282-
launchActivity(new Intent(RecognizerIntent.ACTION_WEB_SEARCH));
303+
Intent assistIntent = getAssistIntent();
304+
if (assistIntent != null) {
305+
launchActivity(assistIntent);
306+
} else {
307+
Log.w(TAG, "Failed to get intent for assist activity");
308+
}
283309
mCallback.pokeWakelock();
284310
break;
285311

0 commit comments

Comments
 (0)