Merge change 6907 into donut
* changes: Initialize searchmanager on demand
This commit is contained in:
@@ -43,13 +43,13 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
// Context that the service is running in.
|
// Context that the service is running in.
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
// This field is initialized in initialize(), and then never modified.
|
// This field is initialized in ensureSearchablesCreated(), and then never modified.
|
||||||
// It is volatile since it can be accessed by multiple threads.
|
// Only accessed by ensureSearchablesCreated() and getSearchables()
|
||||||
private volatile Searchables mSearchables;
|
private Searchables mSearchables;
|
||||||
|
|
||||||
// This field is initialized in initialize(), and then never modified.
|
// This field is initialized in ensureSearchDialogCreated(), and then never modified.
|
||||||
// It is volatile since it can be accessed by multiple threads.
|
// Only accessed by ensureSearchDialogCreated() and getSearchDialog()
|
||||||
private volatile SearchDialogWrapper mSearchDialog;
|
private SearchDialogWrapper mSearchDialog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the Search Manager service in the provided system context.
|
* Initializes the Search Manager service in the provided system context.
|
||||||
@@ -68,16 +68,18 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the search UI and the list of searchable activities.
|
* Initializes the list of searchable activities and the search UI.
|
||||||
*/
|
*/
|
||||||
void initialize() {
|
void initialize() {
|
||||||
mSearchables = createSearchables();
|
ensureSearchablesCreated();
|
||||||
mSearchDialog = new SearchDialogWrapper(mContext);
|
ensureSearchDialogCreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Searchables createSearchables() {
|
private synchronized void ensureSearchablesCreated() {
|
||||||
Searchables searchables = new Searchables(mContext);
|
if (mSearchables != null) return; // already created
|
||||||
searchables.buildSearchableList();
|
|
||||||
|
mSearchables = new Searchables(mContext);
|
||||||
|
mSearchables.buildSearchableList();
|
||||||
|
|
||||||
IntentFilter packageFilter = new IntentFilter();
|
IntentFilter packageFilter = new IntentFilter();
|
||||||
packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
|
||||||
@@ -85,8 +87,22 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
||||||
packageFilter.addDataScheme("package");
|
packageFilter.addDataScheme("package");
|
||||||
mContext.registerReceiver(mPackageChangedReceiver, packageFilter);
|
mContext.registerReceiver(mPackageChangedReceiver, packageFilter);
|
||||||
|
}
|
||||||
|
|
||||||
return searchables;
|
private synchronized void ensureSearchDialogCreated() {
|
||||||
|
if (mSearchDialog != null) return;
|
||||||
|
|
||||||
|
mSearchDialog = new SearchDialogWrapper(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized Searchables getSearchables() {
|
||||||
|
ensureSearchablesCreated();
|
||||||
|
return mSearchables;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized SearchDialogWrapper getSearchDialog() {
|
||||||
|
ensureSearchDialogCreated();
|
||||||
|
return mSearchDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,9 +118,9 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
|
Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
|
||||||
if (DBG) Log.d(TAG, "Got " + action);
|
if (DBG) Log.d(TAG, "Got " + action);
|
||||||
// Dismiss search dialog, since the search context may no longer be valid
|
// Dismiss search dialog, since the search context may no longer be valid
|
||||||
mSearchDialog.stopSearch();
|
getSearchDialog().stopSearch();
|
||||||
// Update list of searchable activities
|
// Update list of searchable activities
|
||||||
mSearchables.buildSearchableList();
|
getSearchables().buildSearchableList();
|
||||||
broadcastSearchablesChanged();
|
broadcastSearchablesChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,15 +151,14 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
*/
|
*/
|
||||||
public SearchableInfo getSearchableInfo(final ComponentName launchActivity,
|
public SearchableInfo getSearchableInfo(final ComponentName launchActivity,
|
||||||
final boolean globalSearch) {
|
final boolean globalSearch) {
|
||||||
if (mSearchables == null) return null;
|
|
||||||
if (globalSearch) {
|
if (globalSearch) {
|
||||||
return mSearchables.getDefaultSearchable();
|
return getSearchables().getDefaultSearchable();
|
||||||
} else {
|
} else {
|
||||||
if (launchActivity == null) {
|
if (launchActivity == null) {
|
||||||
Log.e(TAG, "getSearchableInfo(), activity == null");
|
Log.e(TAG, "getSearchableInfo(), activity == null");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return mSearchables.getSearchableInfo(launchActivity);
|
return getSearchables().getSearchableInfo(launchActivity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,8 +166,7 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
* Returns a list of the searchable activities that can be included in global search.
|
* Returns a list of the searchable activities that can be included in global search.
|
||||||
*/
|
*/
|
||||||
public List<SearchableInfo> getSearchablesInGlobalSearch() {
|
public List<SearchableInfo> getSearchablesInGlobalSearch() {
|
||||||
if (mSearchables == null) return null;
|
return getSearchables().getSearchablesInGlobalSearchList();
|
||||||
return mSearchables.getSearchablesInGlobalSearchList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,8 +174,7 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
* Can be called from any thread.
|
* Can be called from any thread.
|
||||||
*/
|
*/
|
||||||
public List<SearchableInfo> getSearchablesForWebSearch() {
|
public List<SearchableInfo> getSearchablesForWebSearch() {
|
||||||
if (mSearchables == null) return null;
|
return getSearchables().getSearchablesForWebSearchList();
|
||||||
return mSearchables.getSearchablesForWebSearchList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,8 +182,7 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
* Can be called from any thread.
|
* Can be called from any thread.
|
||||||
*/
|
*/
|
||||||
public SearchableInfo getDefaultSearchableForWebSearch() {
|
public SearchableInfo getDefaultSearchableForWebSearch() {
|
||||||
if (mSearchables == null) return null;
|
return getSearchables().getDefaultSearchableForWebSearch();
|
||||||
return mSearchables.getDefaultSearchableForWebSearch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,8 +190,7 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
* Can be called from any thread.
|
* Can be called from any thread.
|
||||||
*/
|
*/
|
||||||
public void setDefaultWebSearch(final ComponentName component) {
|
public void setDefaultWebSearch(final ComponentName component) {
|
||||||
if (mSearchables == null) return;
|
getSearchables().setDefaultWebSearch(component);
|
||||||
mSearchables.setDefaultWebSearch(component);
|
|
||||||
broadcastSearchablesChanged();
|
broadcastSearchablesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,8 +207,7 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
Bundle appSearchData,
|
Bundle appSearchData,
|
||||||
boolean globalSearch,
|
boolean globalSearch,
|
||||||
ISearchManagerCallback searchManagerCallback) {
|
ISearchManagerCallback searchManagerCallback) {
|
||||||
if (mSearchDialog == null) return;
|
getSearchDialog().startSearch(initialQuery,
|
||||||
mSearchDialog.startSearch(initialQuery,
|
|
||||||
selectInitialQuery,
|
selectInitialQuery,
|
||||||
launchActivity,
|
launchActivity,
|
||||||
appSearchData,
|
appSearchData,
|
||||||
@@ -209,8 +219,7 @@ public class SearchManagerService extends ISearchManager.Stub {
|
|||||||
* Cancels the search dialog. Can be called from any thread.
|
* Cancels the search dialog. Can be called from any thread.
|
||||||
*/
|
*/
|
||||||
public void stopSearch() {
|
public void stopSearch() {
|
||||||
if (mSearchDialog == null) return;
|
getSearchDialog().stopSearch();
|
||||||
mSearchDialog.stopSearch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user