Merge change 4914 into donut

* changes:
  Make all static methods in SearchManager non-static.
This commit is contained in:
Android (Google) Code Review
2009-06-22 07:19:49 -07:00
4 changed files with 38 additions and 49 deletions

View File

@@ -310,15 +310,17 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
+ appSearchData + ", " + globalSearch + ")"); + appSearchData + ", " + globalSearch + ")");
} }
SearchManager searchManager = (SearchManager)
mContext.getSystemService(Context.SEARCH_SERVICE);
// Try to get the searchable info for the provided component (or for global search, // Try to get the searchable info for the provided component (or for global search,
// if globalSearch == true). // if globalSearch == true).
mSearchable = SearchManager.getSearchableInfo(componentName, globalSearch); mSearchable = searchManager.getSearchableInfo(componentName, globalSearch);
// If we got back nothing, and it wasn't a request for global search, then try again // If we got back nothing, and it wasn't a request for global search, then try again
// for global search, as we'll try to launch that in lieu of any component-specific search. // for global search, as we'll try to launch that in lieu of any component-specific search.
if (!globalSearch && mSearchable == null) { if (!globalSearch && mSearchable == null) {
globalSearch = true; globalSearch = true;
mSearchable = SearchManager.getSearchableInfo(componentName, globalSearch); mSearchable = searchManager.getSearchableInfo(componentName, globalSearch);
// If we still get back null (i.e., there's not even a searchable info available // If we still get back null (i.e., there's not even a searchable info available
// for global search), then really give up. // for global search), then really give up.
@@ -333,7 +335,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
mAppSearchData = appSearchData; mAppSearchData = appSearchData;
// Using globalSearch here is just an optimization, just calling // Using globalSearch here is just an optimization, just calling
// isDefaultSearchable() should always give the same result. // isDefaultSearchable() should always give the same result.
mGlobalSearchMode = globalSearch || SearchManager.isDefaultSearchable(mSearchable); mGlobalSearchMode = globalSearch || searchManager.isDefaultSearchable(mSearchable);
mActivityContext = mSearchable.getActivityContext(getContext()); mActivityContext = mSearchable.getActivityContext(getContext());
// show the dialog. this will call onStart(). // show the dialog. this will call onStart().

View File

@@ -1514,7 +1514,7 @@ public class SearchManager
/** /**
* Reference to the shared system search service. * Reference to the shared system search service.
*/ */
private static ISearchManager sService = getSearchManagerService(); private static ISearchManager mService;
private final Context mContext; private final Context mContext;
@@ -1529,6 +1529,8 @@ public class SearchManager
/*package*/ SearchManager(Context context, Handler handler) { /*package*/ SearchManager(Context context, Handler handler) {
mContext = context; mContext = context;
mHandler = handler; mHandler = handler;
mService = ISearchManager.Stub.asInterface(
ServiceManager.getService(Context.SEARCH_SERVICE));
} }
/** /**
@@ -1581,7 +1583,7 @@ public class SearchManager
try { try {
mIsShowing = true; mIsShowing = true;
// activate the search manager and start it up! // activate the search manager and start it up!
sService.startSearch(initialQuery, selectInitialQuery, launchActivity, appSearchData, mService.startSearch(initialQuery, selectInitialQuery, launchActivity, appSearchData,
globalSearch, mSearchManagerCallback); globalSearch, mSearchManagerCallback);
} catch (RemoteException ex) { } catch (RemoteException ex) {
Log.e(TAG, "startSearch() failed: " + ex); Log.e(TAG, "startSearch() failed: " + ex);
@@ -1603,7 +1605,7 @@ public class SearchManager
if (DBG) debug("stopSearch(), mIsShowing=" + mIsShowing); if (DBG) debug("stopSearch(), mIsShowing=" + mIsShowing);
if (!mIsShowing) return; if (!mIsShowing) return;
try { try {
sService.stopSearch(); mService.stopSearch();
// onDismiss will also clear this, but we do it here too since onDismiss() is // onDismiss will also clear this, but we do it here too since onDismiss() is
// called asynchronously. // called asynchronously.
mIsShowing = false; mIsShowing = false;
@@ -1725,7 +1727,7 @@ public class SearchManager
if (DBG) debug("saveSearchDialog(), mIsShowing=" + mIsShowing); if (DBG) debug("saveSearchDialog(), mIsShowing=" + mIsShowing);
if (!mIsShowing) return null; if (!mIsShowing) return null;
try { try {
return sService.onSaveInstanceState(); return mService.onSaveInstanceState();
} catch (RemoteException ex) { } catch (RemoteException ex) {
Log.e(TAG, "onSaveInstanceState() failed: " + ex); Log.e(TAG, "onSaveInstanceState() failed: " + ex);
return null; return null;
@@ -1743,7 +1745,7 @@ public class SearchManager
if (DBG) debug("restoreSearchDialog(" + searchDialogState + ")"); if (DBG) debug("restoreSearchDialog(" + searchDialogState + ")");
if (searchDialogState == null) return; if (searchDialogState == null) return;
try { try {
sService.onRestoreInstanceState(searchDialogState); mService.onRestoreInstanceState(searchDialogState);
} catch (RemoteException ex) { } catch (RemoteException ex) {
Log.e(TAG, "onRestoreInstanceState() failed: " + ex); Log.e(TAG, "onRestoreInstanceState() failed: " + ex);
} }
@@ -1760,17 +1762,12 @@ public class SearchManager
if (DBG) debug("onConfigurationChanged(" + newConfig + "), mIsShowing=" + mIsShowing); if (DBG) debug("onConfigurationChanged(" + newConfig + "), mIsShowing=" + mIsShowing);
if (!mIsShowing) return; if (!mIsShowing) return;
try { try {
sService.onConfigurationChanged(newConfig); mService.onConfigurationChanged(newConfig);
} catch (RemoteException ex) { } catch (RemoteException ex) {
Log.e(TAG, "onConfigurationChanged() failed:" + ex); Log.e(TAG, "onConfigurationChanged() failed:" + ex);
} }
} }
private static ISearchManager getSearchManagerService() {
return ISearchManager.Stub.asInterface(
ServiceManager.getService(Context.SEARCH_SERVICE));
}
/** /**
* Gets information about a searchable activity. This method is static so that it can * Gets information about a searchable activity. This method is static so that it can
* be used from non-Activity contexts. * be used from non-Activity contexts.
@@ -1782,10 +1779,10 @@ public class SearchManager
* *
* @hide because SearchableInfo is not part of the API. * @hide because SearchableInfo is not part of the API.
*/ */
public static SearchableInfo getSearchableInfo(ComponentName componentName, public SearchableInfo getSearchableInfo(ComponentName componentName,
boolean globalSearch) { boolean globalSearch) {
try { try {
return sService.getSearchableInfo(componentName, globalSearch); return mService.getSearchableInfo(componentName, globalSearch);
} catch (RemoteException ex) { } catch (RemoteException ex) {
Log.e(TAG, "getSearchableInfo() failed: " + ex); Log.e(TAG, "getSearchableInfo() failed: " + ex);
return null; return null;
@@ -1797,8 +1794,8 @@ public class SearchManager
* *
* @hide because SearchableInfo is not part of the API. * @hide because SearchableInfo is not part of the API.
*/ */
public static boolean isDefaultSearchable(SearchableInfo searchable) { public boolean isDefaultSearchable(SearchableInfo searchable) {
SearchableInfo defaultSearchable = SearchManager.getSearchableInfo(null, true); SearchableInfo defaultSearchable = getSearchableInfo(null, true);
return defaultSearchable != null return defaultSearchable != null
&& defaultSearchable.getSearchActivity().equals(searchable.getSearchActivity()); && defaultSearchable.getSearchActivity().equals(searchable.getSearchActivity());
} }
@@ -1813,20 +1810,6 @@ public class SearchManager
* @hide because SearchableInfo is not part of the API. * @hide because SearchableInfo is not part of the API.
*/ */
public Cursor getSuggestions(SearchableInfo searchable, String query) { public Cursor getSuggestions(SearchableInfo searchable, String query) {
return getSuggestions(mContext, searchable, query);
}
/**
* Gets a cursor with search suggestions. This method is static so that it can
* be used from non-Activity context.
*
* @param searchable Information about how to get the suggestions.
* @param query The search text entered (so far).
* @return a cursor with suggestions, or <code>null</null> the suggestion query failed.
*
* @hide because SearchableInfo is not part of the API.
*/
public static Cursor getSuggestions(Context context, SearchableInfo searchable, String query) {
if (searchable == null) { if (searchable == null) {
return null; return null;
} }
@@ -1865,7 +1848,7 @@ public class SearchManager
.build(); .build();
// finally, make the query // finally, make the query
return context.getContentResolver().query(uri, null, selection, selArgs, null); return mContext.getContentResolver().query(uri, null, selection, selArgs, null);
} }
/** /**
@@ -1877,9 +1860,9 @@ public class SearchManager
* *
* @hide because SearchableInfo is not part of the API. * @hide because SearchableInfo is not part of the API.
*/ */
public static List<SearchableInfo> getSearchablesInGlobalSearch() { public List<SearchableInfo> getSearchablesInGlobalSearch() {
try { try {
return sService.getSearchablesInGlobalSearch(); return mService.getSearchablesInGlobalSearch();
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "getSearchablesInGlobalSearch() failed: " + e); Log.e(TAG, "getSearchablesInGlobalSearch() failed: " + e);
return null; return null;
@@ -1894,9 +1877,9 @@ public class SearchManager
* *
* @hide because SearchableInfo is not part of the API. * @hide because SearchableInfo is not part of the API.
*/ */
public static List<SearchableInfo> getSearchablesForWebSearch() { public List<SearchableInfo> getSearchablesForWebSearch() {
try { try {
return sService.getSearchablesForWebSearch(); return mService.getSearchablesForWebSearch();
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "getSearchablesForWebSearch() failed: " + e); Log.e(TAG, "getSearchablesForWebSearch() failed: " + e);
return null; return null;
@@ -1910,9 +1893,9 @@ public class SearchManager
* *
* @hide because SearchableInfo is not part of the API. * @hide because SearchableInfo is not part of the API.
*/ */
public static SearchableInfo getDefaultSearchableForWebSearch() { public SearchableInfo getDefaultSearchableForWebSearch() {
try { try {
return sService.getDefaultSearchableForWebSearch(); return mService.getDefaultSearchableForWebSearch();
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "getDefaultSearchableForWebSearch() failed: " + e); Log.e(TAG, "getDefaultSearchableForWebSearch() failed: " + e);
return null; return null;
@@ -1926,9 +1909,9 @@ public class SearchManager
* *
* @hide * @hide
*/ */
public static void setDefaultWebSearch(ComponentName component) { public void setDefaultWebSearch(ComponentName component) {
try { try {
sService.setDefaultWebSearch(component); mService.setDefaultWebSearch(component);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "setDefaultWebSearch() failed: " + e); Log.e(TAG, "setDefaultWebSearch() failed: " + e);
} }

View File

@@ -54,6 +54,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
private static final boolean DBG = false; private static final boolean DBG = false;
private static final String LOG_TAG = "SuggestionsAdapter"; private static final String LOG_TAG = "SuggestionsAdapter";
private SearchManager mSearchManager;
private SearchDialog mSearchDialog; private SearchDialog mSearchDialog;
private SearchableInfo mSearchable; private SearchableInfo mSearchable;
private Context mProviderContext; private Context mProviderContext;
@@ -92,6 +93,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
com.android.internal.R.layout.search_dropdown_item_icons_2line, com.android.internal.R.layout.search_dropdown_item_icons_2line,
null, // no initial cursor null, // no initial cursor
true); // auto-requery true); // auto-requery
mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
mSearchDialog = searchDialog; mSearchDialog = searchDialog;
mSearchable = searchable; mSearchable = searchable;
@@ -142,7 +144,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
mSearchDialog.getWindow().getDecorView().post(mStartSpinnerRunnable); mSearchDialog.getWindow().getDecorView().post(mStartSpinnerRunnable);
} }
try { try {
final Cursor cursor = SearchManager.getSuggestions(mContext, mSearchable, query); final Cursor cursor = mSearchManager.getSuggestions(mSearchable, query);
// trigger fill window so the spinner stays up until the results are copied over and // trigger fill window so the spinner stays up until the results are copied over and
// closer to being ready // closer to being ready
if (!mGlobalSearchMode) cursor.getCount(); if (!mGlobalSearchMode) cursor.getCount();

View File

@@ -163,17 +163,19 @@ public class SearchManagerTest extends ActivityInstrumentationTestCase2<LocalAct
@MediumTest @MediumTest
public void testSearchables() { public void testSearchables() {
SearchManager searchManager = (SearchManager)
mContext.getSystemService(Context.SEARCH_SERVICE);
SearchableInfo si; SearchableInfo si;
si = SearchManager.getSearchableInfo(SEARCHABLE_ACTIVITY, false); si = searchManager.getSearchableInfo(SEARCHABLE_ACTIVITY, false);
assertNotNull(si); assertNotNull(si);
assertFalse(SearchManager.isDefaultSearchable(si)); assertFalse(searchManager.isDefaultSearchable(si));
si = SearchManager.getSearchableInfo(SEARCHABLE_ACTIVITY, true); si = searchManager.getSearchableInfo(SEARCHABLE_ACTIVITY, true);
assertNotNull(si); assertNotNull(si);
assertTrue(SearchManager.isDefaultSearchable(si)); assertTrue(searchManager.isDefaultSearchable(si));
si = SearchManager.getSearchableInfo(null, true); si = searchManager.getSearchableInfo(null, true);
assertNotNull(si); assertNotNull(si);
assertTrue(SearchManager.isDefaultSearchable(si)); assertTrue(searchManager.isDefaultSearchable(si));
} }
/** /**