Skip to content

Commit cab997b

Browse files
Jim MillerAndroid (Google) Code Review
authored andcommitted
Merge "Fix 6667238: allow market apps to support ACTION_ASSIST" into jb-dev
2 parents 5785e05 + 45308b1 commit cab997b

File tree

17 files changed

+254
-116
lines changed

17 files changed

+254
-116
lines changed

core/java/android/app/SearchManager.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -840,29 +840,17 @@ public List<SearchableInfo> getSearchablesInGlobalSearch() {
840840
}
841841

842842
/**
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.
843+
* Gets an intent for launching installed assistant activity, or null if not available.
857844
* @return The assist intent.
858845
*
859846
* @hide
860847
*/
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());
848+
public static final Intent getAssistIntent(Context context) {
849+
PackageManager pm = context.getPackageManager();
850+
Intent intent = new Intent(Intent.ACTION_ASSIST);
851+
ComponentName component = intent.resolveActivity(pm);
852+
if (component != null) {
853+
intent.setComponent(component);
866854
return intent;
867855
}
868856
return null;

core/java/com/android/internal/widget/multiwaveview/GlowPadView.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import android.content.res.Resources;
3030
import android.content.res.TypedArray;
3131
import android.graphics.Canvas;
32-
import android.graphics.RectF;
3332
import android.graphics.drawable.Drawable;
3433
import android.os.Bundle;
3534
import android.os.Vibrator;
@@ -1209,25 +1208,32 @@ public boolean replaceTargetDrawablesIfPresent(ComponentName component, String n
12091208
int existingResId) {
12101209
if (existingResId == 0) return false;
12111210

1212-
try {
1213-
PackageManager packageManager = mContext.getPackageManager();
1214-
// Look for the search icon specified in the activity meta-data
1215-
Bundle metaData = packageManager.getActivityInfo(
1216-
component, PackageManager.GET_META_DATA).metaData;
1217-
if (metaData != null) {
1218-
int iconResId = metaData.getInt(name);
1219-
if (iconResId != 0) {
1220-
Resources res = packageManager.getResourcesForActivity(component);
1221-
return replaceTargetDrawables(res, existingResId, iconResId);
1211+
boolean replaced = false;
1212+
if (component != null) {
1213+
try {
1214+
PackageManager packageManager = mContext.getPackageManager();
1215+
// Look for the search icon specified in the activity meta-data
1216+
Bundle metaData = packageManager.getActivityInfo(
1217+
component, PackageManager.GET_META_DATA).metaData;
1218+
if (metaData != null) {
1219+
int iconResId = metaData.getInt(name);
1220+
if (iconResId != 0) {
1221+
Resources res = packageManager.getResourcesForActivity(component);
1222+
replaced = replaceTargetDrawables(res, existingResId, iconResId);
1223+
}
12221224
}
1225+
} catch (NameNotFoundException e) {
1226+
Log.w(TAG, "Failed to swap drawable; "
1227+
+ component.flattenToShortString() + " not found", e);
1228+
} catch (Resources.NotFoundException nfe) {
1229+
Log.w(TAG, "Failed to swap drawable from "
1230+
+ component.flattenToShortString(), nfe);
12231231
}
1224-
} catch (NameNotFoundException e) {
1225-
Log.w(TAG, "Failed to swap drawable; "
1226-
+ component.flattenToShortString() + " not found", e);
1227-
} catch (Resources.NotFoundException nfe) {
1228-
Log.w(TAG, "Failed to swap drawable from "
1229-
+ component.flattenToShortString(), nfe);
12301232
}
1231-
return false;
1233+
if (!replaced) {
1234+
// Restore the original drawable
1235+
replaceTargetDrawables(mContext.getResources(), existingResId, existingResId);
1236+
}
1237+
return replaced;
12321238
}
12331239
}

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

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ 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;
5756
private BaseStatusBar mBar;
5857
private StatusBarTouchProxy mStatusBarTouchProxy;
5958

@@ -68,25 +67,13 @@ public SearchPanelView(Context context, AttributeSet attrs) {
6867
public SearchPanelView(Context context, AttributeSet attrs, int defStyle) {
6968
super(context, attrs, defStyle);
7069
mContext = context;
71-
mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
72-
if (mSearchManager == null) {
73-
Slog.w(TAG, "Search manager not available");
74-
}
75-
}
76-
77-
public boolean isAssistantAvailable() {
78-
return mSearchManager != null && mSearchManager.isAssistantAvailable();
79-
}
80-
81-
private Intent getAssistIntent() {
82-
return mSearchManager != null ? mSearchManager.getAssistIntent() : null;
8370
}
8471

8572
private void startAssistActivity() {
8673
// Close Recent Apps if needed
8774
mBar.animateCollapse(CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL);
8875
// Launch Assist
89-
Intent intent = getAssistIntent();
76+
Intent intent = SearchManager.getAssistIntent(mContext);
9077
if (intent == null) return;
9178
try {
9279
ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext,
@@ -150,19 +137,17 @@ protected void onFinishInflate() {
150137
// TODO: fetch views
151138
mGlowPadView = (GlowPadView) findViewById(R.id.glow_pad_view);
152139
mGlowPadView.setOnTriggerListener(mGlowPadViewListener);
153-
if (mSearchManager != null) {
154-
ComponentName component = mSearchManager.getGlobalSearchActivity();
155-
if (component != null) {
156-
if (!mGlowPadView.replaceTargetDrawablesIfPresent(component,
157-
ASSIST_ICON_METADATA_NAME,
158-
com.android.internal.R.drawable.ic_action_assist_generic)) {
159-
Slog.w(TAG, "Couldn't grab icon from component " + component);
160-
}
161-
} else {
162-
Slog.w(TAG, "No search icon specified in component " + component);
140+
}
141+
142+
private void maybeSwapSearchIcon() {
143+
Intent intent = SearchManager.getAssistIntent(mContext);
144+
if (intent != null) {
145+
ComponentName component = intent.getComponent();
146+
if (component == null || !mGlowPadView.replaceTargetDrawablesIfPresent(component,
147+
ASSIST_ICON_METADATA_NAME,
148+
com.android.internal.R.drawable.ic_action_assist_generic)) {
149+
if (DEBUG) Slog.v(TAG, "Couldn't grab icon for component " + component);
163150
}
164-
} else {
165-
Slog.w(TAG, "No SearchManager");
166151
}
167152
}
168153

@@ -210,6 +195,7 @@ public void show(final boolean show, boolean animate) {
210195
}
211196
mShowing = show;
212197
if (show) {
198+
maybeSwapSearchIcon();
213199
if (getVisibility() != View.VISIBLE) {
214200
setVisibility(View.VISIBLE);
215201
// Don't start the animation until we've created the layer, which is done
@@ -289,4 +275,8 @@ private LayoutTransition createLayoutTransitioner() {
289275
transitioner.setAnimator(LayoutTransition.DISAPPEARING, null);
290276
return transitioner;
291277
}
278+
279+
public boolean isAssistantAvailable() {
280+
return SearchManager.getAssistIntent(mContext) != null;
281+
}
292282
}

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

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
8383
private View mUnlockWidget;
8484
private boolean mCameraDisabled;
8585
private boolean mSearchDisabled;
86-
private SearchManager mSearchManager;
8786
// Is there a vibrator
8887
private final boolean mHasVibrator;
8988

@@ -253,23 +252,6 @@ public void cleanUp() {
253252
}
254253
}
255254

256-
private boolean isAssistantAvailable() {
257-
SearchManager searchManager = getSearchManager();
258-
return searchManager != null && searchManager.isAssistantAvailable();
259-
}
260-
261-
private Intent getAssistIntent() {
262-
SearchManager searchManager = getSearchManager();
263-
return searchManager != null ? searchManager.getAssistIntent() : null;
264-
}
265-
266-
private SearchManager getSearchManager() {
267-
if (mSearchManager == null) {
268-
mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
269-
}
270-
return mSearchManager;
271-
}
272-
273255
class GlowPadViewMethods implements GlowPadView.OnTriggerListener,
274256
UnlockWidgetCommonMethods {
275257
private final GlowPadView mGlowPadView;
@@ -297,27 +279,21 @@ public void updateResources() {
297279

298280
// Update the search icon with drawable from the search .apk
299281
if (!mSearchDisabled) {
300-
SearchManager searchManager = getSearchManager();
301-
if (searchManager != null) {
302-
ComponentName component = searchManager.getGlobalSearchActivity();
303-
if (component != null) {
304-
// XXX Hack. We need to substitute the icon here but haven't formalized
305-
// the public API. The "_google" metadata will be going away, so
306-
// DON'T USE IT!
307-
boolean replaced = mGlowPadView.replaceTargetDrawablesIfPresent(component,
308-
ASSIST_ICON_METADATA_NAME + "_google",
309-
com.android.internal.R.drawable.ic_action_assist_generic);
310-
311-
if (!replaced && !mGlowPadView.replaceTargetDrawablesIfPresent(component,
312-
ASSIST_ICON_METADATA_NAME,
313-
com.android.internal.R.drawable.ic_action_assist_generic)) {
314-
Slog.w(TAG, "Couldn't grab icon from package " + component);
315-
}
316-
} else {
317-
Slog.w(TAG, "No search icon specified in package " + component);
282+
Intent intent = SearchManager.getAssistIntent(mContext);
283+
if (intent != null) {
284+
// XXX Hack. We need to substitute the icon here but haven't formalized
285+
// the public API. The "_google" metadata will be going away, so
286+
// DON'T USE IT!
287+
ComponentName component = intent.getComponent();
288+
boolean replaced = mGlowPadView.replaceTargetDrawablesIfPresent(component,
289+
ASSIST_ICON_METADATA_NAME + "_google",
290+
com.android.internal.R.drawable.ic_action_assist_generic);
291+
292+
if (!replaced && !mGlowPadView.replaceTargetDrawablesIfPresent(component,
293+
ASSIST_ICON_METADATA_NAME,
294+
com.android.internal.R.drawable.ic_action_assist_generic)) {
295+
Slog.w(TAG, "Couldn't grab icon from package " + component);
318296
}
319-
} else {
320-
Slog.w(TAG, "No SearchManager");
321297
}
322298
}
323299

@@ -337,7 +313,7 @@ public void onTrigger(View v, int target) {
337313
final int resId = mGlowPadView.getResourceIdForTarget(target);
338314
switch (resId) {
339315
case com.android.internal.R.drawable.ic_action_assist_generic:
340-
Intent assistIntent = getAssistIntent();
316+
Intent assistIntent = SearchManager.getAssistIntent(mContext);
341317
if (assistIntent != null) {
342318
launchActivity(assistIntent);
343319
} else {
@@ -550,7 +526,7 @@ private void updateTargets() {
550526
} else if (disabledBySimState) {
551527
Log.v(TAG, "Camera disabled by Sim State");
552528
}
553-
boolean searchActionAvailable = isAssistantAvailable();
529+
boolean searchActionAvailable = SearchManager.getAssistIntent(mContext) != null;
554530
mCameraDisabled = disabledByAdmin || disabledBySimState || !cameraTargetPresent;
555531
mSearchDisabled = disabledBySimState || !searchActionAvailable || !searchTargetPresent;
556532
mUnlockWidgetMethods.updateResources();

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,8 @@ private void launchAssistLongPressAction() {
20812081
Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
20822082
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
20832083
try {
2084+
// TODO: This only stops the factory-installed search manager.
2085+
// Need to formalize an API to handle others
20842086
SearchManager searchManager = getSearchManager();
20852087
if (searchManager != null) {
20862088
searchManager.stopSearch();
@@ -2093,19 +2095,15 @@ private void launchAssistLongPressAction() {
20932095

20942096
private void launchAssistAction() {
20952097
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2096-
2097-
SearchManager searchManager = getSearchManager();
2098-
if (searchManager != null) {
2099-
Intent intent = searchManager.getAssistIntent();
2100-
if (intent != null) {
2101-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2102-
| Intent.FLAG_ACTIVITY_SINGLE_TOP
2103-
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
2104-
try {
2105-
mContext.startActivity(intent);
2106-
} catch (ActivityNotFoundException e) {
2107-
Slog.w(TAG, "No activity to handle assist action.", e);
2108-
}
2098+
Intent intent = SearchManager.getAssistIntent(mContext);
2099+
if (intent != null) {
2100+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2101+
| Intent.FLAG_ACTIVITY_SINGLE_TOP
2102+
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
2103+
try {
2104+
mContext.startActivity(intent);
2105+
} catch (ActivityNotFoundException e) {
2106+
Slog.w(TAG, "No activity to handle assist action.", e);
21092107
}
21102108
}
21112109
}

tests/Assistant/Android.mk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
LOCAL_PATH:= $(call my-dir)
2+
include $(CLEAR_VARS)
3+
4+
LOCAL_SRC_FILES := $(call all-subdir-java-files)
5+
6+
LOCAL_PACKAGE_NAME := Assistant
7+
8+
LOCAL_MODULE_TAGS := tests
9+
LOCAL_CERTIFICATE := platform
10+
11+
include $(BUILD_PACKAGE)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2008 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
18+
package="com.google.android.test.assistant">
19+
20+
<application android:label="@string/activity_title">
21+
22+
<activity android:name=".AssistActivity"
23+
android:theme="@android:style/Theme.NoTitleBar">
24+
25+
<!-- Handle assist intent -->
26+
<intent-filter>
27+
<action android:name="android.intent.action.ASSIST" />
28+
<category android:name="android.intent.category.DEFAULT" />
29+
</intent-filter>
30+
31+
<!-- Provide icon for search -->
32+
<meta-data android:name="com.android.systemui.action_assist_icon"
33+
android:resource="@drawable/ic_action_assist" />
34+
35+
</activity>
36+
37+
</application>
38+
39+
</manifest>
13.4 KB
Loading
5.6 KB
Loading
8.58 KB
Loading

0 commit comments

Comments
 (0)