FileDocCategorySizeDatePackage
SearchManagerService.javaAPI DocAndroid 1.5 API6116Wed May 06 22:41:56 BST 2009android.server.search

SearchManagerService

public class SearchManagerService extends ISearchManager.Stub
This is a simplified version of the Search Manager service. It no longer handles presentation (UI). Its function is to maintain the map & list of "searchable" items, which provides a mapping from individual activities (where a user might have invoked search) to specific searchable activities (where the search will be dispatched).

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final boolean
localLOGV
private static final boolean
IMMEDIATE_SEARCHABLES_UPDATE
private final android.content.Context
mContext
private final android.os.Handler
mHandler
private boolean
mSearchablesDirty
private android.content.BroadcastReceiver
mIntentReceiver
Listens for intent broadcasts. The primary purpose here is to refresh the "searchables" list if packages are added/removed.
private Runnable
mRunUpdateSearchable
This runnable (for the main handler / UI thread) will update the searchables list.
Constructors Summary
public SearchManagerService(android.content.Context context)
Initialize 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;
        mHandler = new Handler();
        
        // Setup the infrastructure for updating and maintaining the list
        // of searchable activities.
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        filter.addDataScheme("package");
        mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
        mSearchablesDirty = true;
        
        // After startup settles down, preload the searchables list,
        // which will reduce the delay when the search UI is invoked.
        if (IMMEDIATE_SEARCHABLES_UPDATE) {
            mHandler.post(mRunUpdateSearchable);
        }
    
Methods Summary
public SearchableInfogetSearchableInfo(android.content.ComponentName launchActivity, boolean globalSearch)
Return 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.
param
globalSearch If false, this will only launch the search that has been specifically defined by the application (which is usually defined as a local search). If no default search is defined in the current application or activity, no search will be launched. If true, this will always launch a platform-global (e.g. web-based) search instead.

        // final check.  however we should try to avoid this, because
        // it slows down the entry into the UI.
        if (mSearchablesDirty) {
            updateSearchables();
        }
        SearchableInfo si = null;
        if (globalSearch) {
            si = SearchableInfo.getDefaultSearchable();
        } else {
            si = SearchableInfo.getSearchableInfo(mContext, launchActivity);
        }

        return si;
    
private voidupdateSearchables()
Update the list of searchables, either at startup or in response to a package add/remove broadcast message.


                          
       
        SearchableInfo.buildSearchableList(mContext);
        mSearchablesDirty = false;
        
        // TODO This is a hack.  This shouldn't be hardcoded here, it's probably
        // a policy.
//      ComponentName defaultSearch = new ComponentName( 
//              "com.android.contacts", 
//              "com.android.contacts.ContactsListActivity" );
        ComponentName defaultSearch = new ComponentName( 
                "com.android.googlesearch", 
                "com.android.googlesearch.GoogleSearch" );
        SearchableInfo.setDefaultSearchable(mContext, defaultSearch);