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

Commit 3c50ef6f authored by Bjorn Bringert's avatar Bjorn Bringert
Browse files

Use unbundled QSB for global search

This obsoletes the following:
- The need to run SearchDialog in the system process.
- The global search mode code in SearchDialog.
- The GlobalSearch package.
- The search widget built into Launcher.

I will remove these in future changes.

Change-Id: I154386b1d6be73cfeab8376b6959a1dc5483e5f0
parent 9fbb534e
Loading
Loading
Loading
Loading
+87 −1
Original line number Diff line number Diff line
@@ -16,10 +16,16 @@

package android.app;

import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
@@ -1325,6 +1331,21 @@ public class SearchManager
     */
    public final static String EXTRA_DATA_KEY = "intent_extra_data_key";

    /**
     * String extra data key for {@link Intent#ACTION_GLOBAL_SEARCH} intents. Contains the initial
     * query to show in the global search activity.
     *
     * @hide Pending API council approval
     */
    public final static String INITIAL_QUERY = "initial_query";

    /**
     * Boolean extra data key for {@link Intent#ACTION_GLOBAL_SEARCH} intents. If {@code true},
     * the initial query should be selected.
     *
     * @hide Pending API council approval
     */
    public final static String SELECT_INITIAL_QUERY = "select_initial_query";
    /**
     * Defines the constants used in the communication between {@link android.app.SearchDialog} and
     * the global search provider via {@link Cursor#respond(android.os.Bundle)}.
@@ -1756,7 +1777,13 @@ public class SearchManager
                            boolean globalSearch) {
        if (mIdent == 0) throw new IllegalArgumentException(
                "Called from outside of an Activity context");
        if (!globalSearch && !mAssociatedPackage.equals(launchActivity.getPackageName())) {

        if (globalSearch) {
            startGlobalSearch(initialQuery, selectInitialQuery, appSearchData);
            return;
        }

        if (!mAssociatedPackage.equals(launchActivity.getPackageName())) {
            Log.w(TAG, "invoking app search on a different package " +
                    "not associated with this search manager");
        }
@@ -1769,6 +1796,65 @@ public class SearchManager
        }
    }

    /**
     * Starts the global search activity.
     */
    private void startGlobalSearch(String initialQuery, boolean selectInitialQuery,
            Bundle appSearchData) {
        ComponentName globalSearchActivity = getGlobalSearchActivity();
        if (globalSearchActivity == null) {
            Log.w(TAG, "No global search activity found.");
            return;
        }
        Intent intent = new Intent(Intent.ACTION_GLOBAL_SEARCH);
        intent.setComponent(globalSearchActivity);
        // TODO: Always pass name of calling package as an extra?
        if (appSearchData != null) {
            intent.putExtra(APP_DATA, appSearchData);
        }
        if (!TextUtils.isEmpty(initialQuery)) {
            intent.putExtra(INITIAL_QUERY, initialQuery);
        }
        if (selectInitialQuery) {
            intent.putExtra(SELECT_INITIAL_QUERY, selectInitialQuery);
        }
        try {
            if (DBG) Log.d(TAG, "Starting global search: " + intent.toUri(0));
            mContext.startActivity(intent);
        } catch (ActivityNotFoundException ex) {
            Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
        }
    }

    /**
     * Gets the name of the global search activity.
     *
     * This is currently implemented by returning the first activity that handles
     * the GLOBAL_SEARCH intent and has the GLOBAL_SEARCH permission. If we allow
     * more than one global search acitivity to be installed, this code must be changed.
     *
     * TODO: Doing this every time we start global search is inefficient. Will fix that once
     * we have settled on the right mechanism for finding the global search activity.
     */
    private ComponentName getGlobalSearchActivity() {
        Intent intent = new Intent(Intent.ACTION_GLOBAL_SEARCH);
        PackageManager pm = mContext.getPackageManager();
        List<ResolveInfo> activities =
                pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        int count = activities.size();
        for (int i = 0; i < count; i++) {
            ActivityInfo ai = activities.get(i).activityInfo;
            if (pm.checkPermission(Manifest.permission.GLOBAL_SEARCH,
                    ai.packageName) == PackageManager.PERMISSION_GRANTED) {
                return new ComponentName(ai.packageName, ai.name);
            } else {
                Log.w(TAG, "Package " + ai.packageName + " wants to handle GLOBAL_SEARCH, "
                        + "but does not have the GLOBAL_SEARCH permission.");
            }
        }
        return null;
    }

    /**
     * Similar to {@link #startSearch} but actually fires off the search query after invoking
     * the search dialog.  Made available for testing purposes.
+10 −0
Original line number Diff line number Diff line
@@ -1101,6 +1101,16 @@ public class Intent implements Parcelable {
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_SEARCH_LONG_PRESS = "android.intent.action.SEARCH_LONG_PRESS";

    /**
     * Activity Action: Start the global search activity.
     * <p>Input: Nothing.
     * <p>Output: Nothing.
     *
     * @hide Pending API council approval
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_GLOBAL_SEARCH = "android.intent.action.GLOBAL_SEARCH";

    /**
     * Activity Action: The user pressed the "Report" button in the crash/ANR dialog.
     * This intent is delivered to the package which installed the application, usually