Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2b7df368 authored by Jim Miller's avatar Jim Miller Committed by Android Git Automerger
Browse files

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

* commit 'cab997b2':
  Fix 6667238: allow market apps to support ACTION_ASSIST
parents 9a5a8aaf cab997b2
Loading
Loading
Loading
Loading
+7 −19
Original line number Diff line number Diff line
@@ -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;
+24 −18
Original line number Diff line number Diff line
@@ -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;
    }
}
+16 −26
Original line number Diff line number Diff line
@@ -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);
                }
            } else {
                Slog.w(TAG, "No search icon specified in component " + component);
                if (DEBUG) Slog.v(TAG, "Couldn't grab icon for 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;
    }
}
+16 −40
Original line number Diff line number Diff line
@@ -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();
+11 −13
Original line number Diff line number Diff line
@@ -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) {
Loading