am cab997b2: Merge "Fix 6667238: allow market apps to support ACTION_ASSIST" into jb-dev

* commit 'cab997b2020ddb67158397dccadd28d91a7710d0':
  Fix 6667238: allow market apps to support ACTION_ASSIST
This commit is contained in:
Jim Miller
2012-06-19 15:24:45 -07:00
committed by Android Git Automerger
17 changed files with 253 additions and 115 deletions

View File

@ -840,29 +840,17 @@ public class SearchManager
}
/**
* Returns true if the global assist activity is available.
* @return True if the assistant is available.
*
* @hide
*/
public final boolean isAssistantAvailable() {
Intent intent = getAssistIntent();
return intent != null
&& mContext.getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}
/**
* Gets an intent to launch the global assist activity, or null if not available.
* Gets an intent for launching installed assistant activity, or null if not available.
* @return The assist intent.
*
* @hide
*/
public final Intent getAssistIntent() {
ComponentName globalSearchActivity = getGlobalSearchActivity();
if (globalSearchActivity != null) {
public static final Intent getAssistIntent(Context context) {
PackageManager pm = context.getPackageManager();
Intent intent = new Intent(Intent.ACTION_ASSIST);
intent.setPackage(globalSearchActivity.getPackageName());
ComponentName component = intent.resolveActivity(pm);
if (component != null) {
intent.setComponent(component);
return intent;
}
return null;

View File

@ -29,7 +29,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Vibrator;
@ -1209,6 +1208,8 @@ public class GlowPadView extends View {
int existingResId) {
if (existingResId == 0) return false;
boolean replaced = false;
if (component != null) {
try {
PackageManager packageManager = mContext.getPackageManager();
// Look for the search icon specified in the activity meta-data
@ -1218,7 +1219,7 @@ public class GlowPadView extends View {
int iconResId = metaData.getInt(name);
if (iconResId != 0) {
Resources res = packageManager.getResourcesForActivity(component);
return replaceTargetDrawables(res, existingResId, iconResId);
replaced = replaceTargetDrawables(res, existingResId, iconResId);
}
}
} catch (NameNotFoundException e) {
@ -1228,6 +1229,11 @@ public class GlowPadView extends View {
Log.w(TAG, "Failed to swap drawable from "
+ component.flattenToShortString(), nfe);
}
return false;
}
if (!replaced) {
// Restore the original drawable
replaceTargetDrawables(mContext.getResources(), existingResId, existingResId);
}
return replaced;
}
}

View File

@ -53,7 +53,6 @@ public class SearchPanelView extends FrameLayout implements
private static final String ASSIST_ICON_METADATA_NAME =
"com.android.systemui.action_assist_icon";
private final Context mContext;
private final SearchManager mSearchManager;
private BaseStatusBar mBar;
private StatusBarTouchProxy mStatusBarTouchProxy;
@ -68,25 +67,13 @@ public class SearchPanelView extends FrameLayout implements
public SearchPanelView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
if (mSearchManager == null) {
Slog.w(TAG, "Search manager not available");
}
}
public boolean isAssistantAvailable() {
return mSearchManager != null && mSearchManager.isAssistantAvailable();
}
private Intent getAssistIntent() {
return mSearchManager != null ? mSearchManager.getAssistIntent() : null;
}
private void startAssistActivity() {
// Close Recent Apps if needed
mBar.animateCollapse(CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL);
// Launch Assist
Intent intent = getAssistIntent();
Intent intent = SearchManager.getAssistIntent(mContext);
if (intent == null) return;
try {
ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext,
@ -150,19 +137,17 @@ public class SearchPanelView extends FrameLayout implements
// TODO: fetch views
mGlowPadView = (GlowPadView) findViewById(R.id.glow_pad_view);
mGlowPadView.setOnTriggerListener(mGlowPadViewListener);
if (mSearchManager != null) {
ComponentName component = mSearchManager.getGlobalSearchActivity();
if (component != null) {
if (!mGlowPadView.replaceTargetDrawablesIfPresent(component,
}
private void maybeSwapSearchIcon() {
Intent intent = SearchManager.getAssistIntent(mContext);
if (intent != null) {
ComponentName component = intent.getComponent();
if (component == null || !mGlowPadView.replaceTargetDrawablesIfPresent(component,
ASSIST_ICON_METADATA_NAME,
com.android.internal.R.drawable.ic_action_assist_generic)) {
Slog.w(TAG, "Couldn't grab icon from component " + component);
if (DEBUG) Slog.v(TAG, "Couldn't grab icon for component " + component);
}
} else {
Slog.w(TAG, "No search icon specified in component " + component);
}
} else {
Slog.w(TAG, "No SearchManager");
}
}
@ -210,6 +195,7 @@ public class SearchPanelView extends FrameLayout implements
}
mShowing = show;
if (show) {
maybeSwapSearchIcon();
if (getVisibility() != View.VISIBLE) {
setVisibility(View.VISIBLE);
// Don't start the animation until we've created the layer, which is done
@ -289,4 +275,8 @@ public class SearchPanelView extends FrameLayout implements
transitioner.setAnimator(LayoutTransition.DISAPPEARING, null);
return transitioner;
}
public boolean isAssistantAvailable() {
return SearchManager.getAssistIntent(mContext) != null;
}
}

View File

@ -83,7 +83,6 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
private View mUnlockWidget;
private boolean mCameraDisabled;
private boolean mSearchDisabled;
private SearchManager mSearchManager;
// Is there a vibrator
private final boolean mHasVibrator;
@ -253,23 +252,6 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
}
}
private boolean isAssistantAvailable() {
SearchManager searchManager = getSearchManager();
return searchManager != null && searchManager.isAssistantAvailable();
}
private Intent getAssistIntent() {
SearchManager searchManager = getSearchManager();
return searchManager != null ? searchManager.getAssistIntent() : null;
}
private SearchManager getSearchManager() {
if (mSearchManager == null) {
mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
}
return mSearchManager;
}
class GlowPadViewMethods implements GlowPadView.OnTriggerListener,
UnlockWidgetCommonMethods {
private final GlowPadView mGlowPadView;
@ -297,13 +279,12 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
// Update the search icon with drawable from the search .apk
if (!mSearchDisabled) {
SearchManager searchManager = getSearchManager();
if (searchManager != null) {
ComponentName component = searchManager.getGlobalSearchActivity();
if (component != null) {
Intent intent = SearchManager.getAssistIntent(mContext);
if (intent != null) {
// XXX Hack. We need to substitute the icon here but haven't formalized
// the public API. The "_google" metadata will be going away, so
// DON'T USE IT!
ComponentName component = intent.getComponent();
boolean replaced = mGlowPadView.replaceTargetDrawablesIfPresent(component,
ASSIST_ICON_METADATA_NAME + "_google",
com.android.internal.R.drawable.ic_action_assist_generic);
@ -313,11 +294,6 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
com.android.internal.R.drawable.ic_action_assist_generic)) {
Slog.w(TAG, "Couldn't grab icon from package " + component);
}
} else {
Slog.w(TAG, "No search icon specified in package " + component);
}
} else {
Slog.w(TAG, "No SearchManager");
}
}
@ -337,7 +313,7 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
final int resId = mGlowPadView.getResourceIdForTarget(target);
switch (resId) {
case com.android.internal.R.drawable.ic_action_assist_generic:
Intent assistIntent = getAssistIntent();
Intent assistIntent = SearchManager.getAssistIntent(mContext);
if (assistIntent != null) {
launchActivity(assistIntent);
} else {
@ -550,7 +526,7 @@ class LockScreen extends LinearLayout implements KeyguardScreen {
} else if (disabledBySimState) {
Log.v(TAG, "Camera disabled by Sim State");
}
boolean searchActionAvailable = isAssistantAvailable();
boolean searchActionAvailable = SearchManager.getAssistIntent(mContext) != null;
mCameraDisabled = disabledByAdmin || disabledBySimState || !cameraTargetPresent;
mSearchDisabled = disabledBySimState || !searchActionAvailable || !searchTargetPresent;
mUnlockWidgetMethods.updateResources();

View File

@ -2081,6 +2081,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
// TODO: This only stops the factory-installed search manager.
// Need to formalize an API to handle others
SearchManager searchManager = getSearchManager();
if (searchManager != null) {
searchManager.stopSearch();
@ -2093,10 +2095,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private void launchAssistAction() {
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
SearchManager searchManager = getSearchManager();
if (searchManager != null) {
Intent intent = searchManager.getAssistIntent();
Intent intent = SearchManager.getAssistIntent(mContext);
if (intent != null) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP
@ -2108,7 +2107,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
}
}
}
private SearchManager getSearchManager() {
if (mSearchManager == null) {

View File

@ -0,0 +1,11 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := Assistant
LOCAL_MODULE_TAGS := tests
LOCAL_CERTIFICATE := platform
include $(BUILD_PACKAGE)

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.test.assistant">
<application android:label="@string/activity_title">
<activity android:name=".AssistActivity"
android:theme="@android:style/Theme.NoTitleBar">
<!-- Handle assist intent -->
<intent-filter>
<action android:name="android.intent.action.ASSIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- Provide icon for search -->
<meta-data android:name="com.android.systemui.action_assist_icon"
android:resource="@drawable/ic_action_assist" />
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="true"
android:state_active="false"
android:state_focused="false"
android:drawable="@drawable/ic_action_assist_normal" />
<item
android:state_enabled="true"
android:state_active="true"
android:state_focused="false"
android:drawable="@drawable/ic_action_assist_activated" />
<item
android:state_enabled="true"
android:state_active="false"
android:state_focused="true"
android:drawable="@drawable/ic_action_assist_activated" />
</selector>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
**
** Copyright 2009, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License")
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<!-- This is the general lock screen which shows information about the
state of the device, as well as instructions on how to get past it
depending on the state of the device. It is the same for landscape
and portrait.-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/search_label"
/>
<EditText android:id="@+id/search_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<string name="activity_title">Assistant</string>
<string name="search_label">Orilla Search Engine</string>
</resources>

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.test.assistant;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.test.assistant.R;
public class AssistActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.assist_intent_activity);
}
}