diff options
| author | Android (Google) Code Review <android-gerrit@google.com> | 2009-12-09 23:32:31 -0800 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-12-09 23:32:31 -0800 |
| commit | 45e77ce36ae1d26bcf35afb1f7662d7b6fb08212 (patch) | |
| tree | d2c1602c9739c62138a1e926cef31b9080c63cbe /core/java | |
| parent | 7cd4029473431c56100e52f631b9733829dc3171 (diff) | |
| parent | 3c50ef6f665ab22cdb50c76bb31283e6bac47fc6 (diff) | |
| download | frameworks_base-45e77ce36ae1d26bcf35afb1f7662d7b6fb08212.zip frameworks_base-45e77ce36ae1d26bcf35afb1f7662d7b6fb08212.tar.gz frameworks_base-45e77ce36ae1d26bcf35afb1f7662d7b6fb08212.tar.bz2 | |
Merge change I154386b1 into eclair-mr2
* changes:
Use unbundled QSB for global search
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/SearchManager.java | 88 | ||||
| -rw-r--r-- | core/java/android/content/Intent.java | 10 |
2 files changed, 97 insertions, 1 deletions
diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java index 1f17476..5d9034b 100644 --- a/core/java/android/app/SearchManager.java +++ b/core/java/android/app/SearchManager.java @@ -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; @@ -1326,6 +1332,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"); } @@ -1770,6 +1797,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. * diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index a96e896..dfdfa15 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -1102,6 +1102,16 @@ public class Intent implements Parcelable { 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 * the Market. |
