diff options
Diffstat (limited to 'core/java/android/server/search')
-rw-r--r-- | core/java/android/server/search/Searchables.java | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/core/java/android/server/search/Searchables.java b/core/java/android/server/search/Searchables.java index c615957..a2add73 100644 --- a/core/java/android/server/search/Searchables.java +++ b/core/java/android/server/search/Searchables.java @@ -26,6 +26,7 @@ import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.content.pm.ApplicationInfo; import android.os.Bundle; import android.util.Log; @@ -230,14 +231,16 @@ public class Searchables { : webSearchInfoList.get(ii - search_count); ActivityInfo ai = info.activityInfo; // Check first to avoid duplicate entries. - if (newSearchablesMap.get(new ComponentName(ai.packageName, ai.name)) == null) { - SearchableInfo searchable = SearchableInfo.getActivityMetaData(mContext, ai); - if (searchable != null) { - newSearchablesList.add(searchable); - newSearchablesMap.put(searchable.getSearchActivity(), searchable); - if (searchable.shouldIncludeInGlobalSearch()) { - newSearchablesInGlobalSearchList.add(searchable); - } + if (newSearchablesMap.containsKey(new ComponentName(ai.packageName, ai.name))) { + continue; + } + SearchableInfo searchable = SearchableInfo.getActivityMetaData(mContext, ai); + if (searchable != null) { + newSearchablesList.add(searchable); + newSearchablesMap.put(searchable.getSearchActivity(), searchable); + if (searchable.shouldIncludeInGlobalSearch() + && isWhitelistedForGlobalSearch(pm, searchable.getSearchActivity())) { + newSearchablesInGlobalSearchList.add(searchable); } } } @@ -289,6 +292,25 @@ public class Searchables { } /** + * Determines whether an activity may be included in quick search box. For now this is + * restricted to system installed apps. + * + * TODO: remove when we are ready to enable global search for third party applications. + * + * @param pm The package manager. + * @param searchActivity The component of the search activity. + * @return True if the search activity may include its search suggestions in quick search box. + */ + private boolean isWhitelistedForGlobalSearch(PackageManager pm, ComponentName searchActivity) { + try { + ActivityInfo ai = pm.getActivityInfo(searchActivity, 0); + return ((ai.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + + /** * Checks if the given activity component is present in the system and if so makes it the * preferred activity for handling ACTION_WEB_SEARCH. * @param component Name of the component to check and set as preferred. |