FileDocCategorySizeDatePackage
SearchManagerService.javaAPI DocAndroid 5.1 API11113Thu Mar 12 22:22:42 GMT 2015com.android.server.search

SearchManagerService

public class SearchManagerService extends ISearchManager.Stub
The search manager service handles the search UI, and maintains a registry of searchable activities.

Fields Summary
private static final String
TAG
private final android.content.Context
mContext
private final android.util.SparseArray
mSearchables
Constructors Summary
public SearchManagerService(android.content.Context context)
Initializes the Search Manager service in the provided system context. Only one instance of this object should be created!

param
context to use for accessing DB, window manager, etc.


                                      
        
        mContext = context;
        IntentFilter filter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        mContext.registerReceiver(new BootCompletedReceiver(), filter);
        mContext.registerReceiver(new UserReceiver(),
                new IntentFilter(Intent.ACTION_USER_REMOVED));
        new MyPackageMonitor().register(context, null, UserHandle.ALL, true);
    
Methods Summary
public voiddump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)

        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);

        IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ");
        synchronized (mSearchables) {
            for (int i = 0; i < mSearchables.size(); i++) {
                ipw.print("\nUser: "); ipw.println(mSearchables.keyAt(i));
                ipw.increaseIndent();
                mSearchables.valueAt(i).dump(fd, ipw, args);
                ipw.decreaseIndent();
            }
        }
    
public android.content.ComponentNamegetAssistIntent(int userHandle)

        try {
            userHandle = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
                    Binder.getCallingUid(), userHandle, true, false, "getAssistIntent", null);
            IPackageManager pm = AppGlobals.getPackageManager();
            Intent assistIntent = new Intent(Intent.ACTION_ASSIST);
            ResolveInfo info =
                    pm.resolveIntent(assistIntent,
                    assistIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
                    PackageManager.MATCH_DEFAULT_ONLY, userHandle);
            if (info != null) {
                return new ComponentName(
                        info.activityInfo.applicationInfo.packageName,
                        info.activityInfo.name);
            }
        } catch (RemoteException re) {
            // Local call
            Log.e(TAG, "RemoteException in getAssistIntent: " + re);
        } catch (Exception e) {
            Log.e(TAG, "Exception in getAssistIntent: " + e);
        }
        return null;
    
public java.util.ListgetGlobalSearchActivities()

        return getSearchables(UserHandle.getCallingUserId()).getGlobalSearchActivities();
    
public android.content.ComponentNamegetGlobalSearchActivity()
Gets the name of the global search activity.

        return getSearchables(UserHandle.getCallingUserId()).getGlobalSearchActivity();
    
public android.app.SearchableInfogetSearchableInfo(android.content.ComponentName launchActivity)
Returns the SearchableInfo for a given activity.

param
launchActivity The activity from which we're launching this search.
return
Returns a SearchableInfo record describing the parameters of the search, or null if no searchable metadata was available.

        if (launchActivity == null) {
            Log.e(TAG, "getSearchableInfo(), activity == null");
            return null;
        }
        return getSearchables(UserHandle.getCallingUserId()).getSearchableInfo(launchActivity);
    
private SearchablesgetSearchables(int userId)

        long origId = Binder.clearCallingIdentity();
        try {
            boolean userExists = ((UserManager) mContext.getSystemService(Context.USER_SERVICE))
                    .getUserInfo(userId) != null;
            if (!userExists) return null;
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
        synchronized (mSearchables) {
            Searchables searchables = mSearchables.get(userId);

            if (searchables == null) {
                //Log.i(TAG, "Building list of searchable activities for userId=" + userId);
                searchables = new Searchables(mContext, userId);
                searchables.buildSearchableList();
                mSearchables.append(userId, searchables);
            }
            return searchables;
        }
    
public java.util.ListgetSearchablesInGlobalSearch()
Returns a list of the searchable activities that can be included in global search.

        return getSearchables(UserHandle.getCallingUserId()).getSearchablesInGlobalSearchList();
    
public android.content.ComponentNamegetWebSearchActivity()
Gets the name of the web search activity.

        return getSearchables(UserHandle.getCallingUserId()).getWebSearchActivity();
    
public booleanlaunchAssistAction(int requestType, java.lang.String hint, int userHandle)

        ComponentName comp = getAssistIntent(userHandle);
        if (comp == null) {
            return false;
        }
        long ident = Binder.clearCallingIdentity();
        try {
            Intent intent = new Intent(Intent.ACTION_ASSIST);
            intent.setComponent(comp);
            IActivityManager am = ActivityManagerNative.getDefault();
            return am.launchAssistIntent(intent, requestType, hint, userHandle);
        } catch (RemoteException e) {
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
        return true;
    
private voidonUserRemoved(int userId)

        if (userId != UserHandle.USER_OWNER) {
            synchronized (mSearchables) {
                mSearchables.remove(userId);
            }
        }