Move Search dialog out of system process into current activity.
SearchManager now manages the SearchDialog, in-process.
Nuked SearchDialogWrapper
SearchManagerService now just holds the Searchables information.
Hitting Search when in the local Search dialog will launch the QSB.
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 1c3414d..ca15a99 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -39,6 +39,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
+import android.os.Looper;
import android.os.RemoteException;
import android.text.Selection;
import android.text.SpannableStringBuilder;
@@ -3449,17 +3450,7 @@
return;
}
- // uses super.getSystemService() since this.getSystemService() looks at the
- // mSearchManager field.
- mSearchManager = (SearchManager) super.getSystemService(Context.SEARCH_SERVICE);
- int ident = mIdent;
- if (ident == 0) {
- if (mParent != null) ident = mParent.mIdent;
- if (ident == 0) {
- throw new IllegalArgumentException("no ident");
- }
- }
- mSearchManager.setIdent(ident, getComponentName());
+ mSearchManager = new SearchManager(this, null);
}
@Override
diff --git a/core/java/android/app/ISearchManager.aidl b/core/java/android/app/ISearchManager.aidl
index 0920467..9ba7863 100644
--- a/core/java/android/app/ISearchManager.aidl
+++ b/core/java/android/app/ISearchManager.aidl
@@ -29,23 +29,4 @@
List<SearchableInfo> getSearchablesForWebSearch();
SearchableInfo getDefaultSearchableForWebSearch();
void setDefaultWebSearch(in ComponentName component);
- void startSearch(in String initialQuery,
- boolean selectInitialQuery,
- in ComponentName launchActivity,
- in Bundle appSearchData,
- boolean globalSearch,
- ISearchManagerCallback searchManagerCallback,
- int ident);
-
- void triggerSearch(in String query,
- in ComponentName launchActivity,
- in Bundle appSearchData,
- ISearchManagerCallback searchManagerCallback,
- int ident);
-
- void stopSearch();
-
-
- boolean isVisible();
-
}
diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java
index b396396..3dfbe71 100644
--- a/core/java/android/app/SearchDialog.java
+++ b/core/java/android/app/SearchDialog.java
@@ -73,8 +73,8 @@
import java.util.concurrent.atomic.AtomicLong;
/**
- * System search dialog. This is controlled by the
- * SearchManagerService and runs in the system process.
+ * Search dialog. This is controlled by the
+ * SearchManager and runs in the current foreground process.
*
* @hide
*/
@@ -118,6 +118,7 @@
private Bundle mAppSearchData;
private boolean mGlobalSearchMode;
private Context mActivityContext;
+ private SearchManager mSearchManager;
// Values we store to allow user to toggle between in-app search and global search.
private ComponentName mStoredComponentName;
@@ -157,7 +158,7 @@
*
* @param context Application Context we can use for system acess
*/
- public SearchDialog(Context context) {
+ public SearchDialog(Context context, SearchManager searchManager) {
super(context, com.android.internal.R.style.Theme_GlobalSearchBar);
// Save voice intent for later queries/launching
@@ -168,6 +169,7 @@
mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mSearchManager = searchManager;
}
/**
@@ -180,7 +182,6 @@
Window theWindow = getWindow();
WindowManager.LayoutParams lp = theWindow.getAttributes();
- lp.type = WindowManager.LayoutParams.TYPE_SEARCH_BAR;
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
// taking up the whole window (even when transparent) is less than ideal,
// but necessary to show the popup window until the window manager supports
@@ -291,8 +292,10 @@
//
// TODO: When the browser icon issue is reconciled in Eclair, remove this special case.
if (isBrowserSearch()) currentSearchText = "";
-
- return doShow(currentSearchText, false, null, mAppSearchData, true);
+
+ cancel();
+ mSearchManager.startGlobalSearch(currentSearchText, false, mStoredAppSearchData);
+ return true;
} else {
if (mStoredComponentName != null) {
// This means we should toggle *back* to an in-app search context from
@@ -1314,8 +1317,7 @@
}
/**
- * Launches an intent, including any special intent handling. Doesn't dismiss the dialog
- * since that will be handled in {@link SearchDialogWrapper#performActivityResuming}
+ * Launches an intent, including any special intent handling.
*/
private void launchIntent(Intent intent) {
if (intent == null) {
diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java
index d25d670..12a4347 100644
--- a/core/java/android/app/SearchManager.java
+++ b/core/java/android/app/SearchManager.java
@@ -1709,7 +1709,7 @@
/* package */ OnDismissListener mDismissListener = null;
/* package */ OnCancelListener mCancelListener = null;
- private final SearchManagerCallback mSearchManagerCallback = new SearchManagerCallback();
+ private SearchDialog mSearchDialog;
/*package*/ SearchManager(Context context, Handler handler) {
mContext = context;
@@ -1778,31 +1778,29 @@
ComponentName launchActivity,
Bundle appSearchData,
boolean globalSearch) {
- if (mIdent == 0) throw new IllegalArgumentException(
- "Called from outside of an Activity context");
+ ensureSearchDialog();
if (globalSearch) {
startGlobalSearch(initialQuery, selectInitialQuery, appSearchData);
return;
}
- if (!mAssociatedPackage.equals(launchActivity.getPackageName())) {
- Log.w(TAG, "invoking app search on a different package " +
- "not associated with this search manager");
- }
- try {
- // activate the search manager and start it up!
- mService.startSearch(initialQuery, selectInitialQuery, launchActivity, appSearchData,
- globalSearch, mSearchManagerCallback, mIdent);
- } catch (RemoteException ex) {
- Log.e(TAG, "startSearch() failed.", ex);
+ mSearchDialog.show(initialQuery, selectInitialQuery, launchActivity, appSearchData,
+ globalSearch);
+ }
+
+ private void ensureSearchDialog() {
+ if (mSearchDialog == null) {
+ mSearchDialog = new SearchDialog(mContext, this);
+ mSearchDialog.setOnCancelListener(this);
+ mSearchDialog.setOnDismissListener(this);
}
}
/**
* Starts the global search activity.
*/
- private void startGlobalSearch(String initialQuery, boolean selectInitialQuery,
+ /* package */ void startGlobalSearch(String initialQuery, boolean selectInitialQuery,
Bundle appSearchData) {
ComponentName globalSearchActivity = getGlobalSearchActivity();
if (globalSearchActivity == null) {
@@ -1876,8 +1874,6 @@
public void triggerSearch(String query,
ComponentName launchActivity,
Bundle appSearchData) {
- if (mIdent == 0) throw new IllegalArgumentException(
- "Called from outside of an Activity context");
if (!mAssociatedPackage.equals(launchActivity.getPackageName())) {
throw new IllegalArgumentException("invoking app search on a different package " +
"not associated with this search manager");
@@ -1886,12 +1882,8 @@
Log.w(TAG, "triggerSearch called with empty query, ignoring.");
return;
}
- try {
- mService.triggerSearch(query, launchActivity, appSearchData, mSearchManagerCallback,
- mIdent);
- } catch (RemoteException ex) {
- Log.e(TAG, "triggerSearch() failed.", ex);
- }
+ startSearch(query, false, launchActivity, appSearchData, false);
+ mSearchDialog.launchQuerySearch();
}
/**
@@ -1906,10 +1898,8 @@
* @see #startSearch
*/
public void stopSearch() {
- if (DBG) debug("stopSearch()");
- try {
- mService.stopSearch();
- } catch (RemoteException ex) {
+ if (mSearchDialog != null) {
+ mSearchDialog.cancel();
}
}
@@ -1923,13 +1913,7 @@
* @hide
*/
public boolean isVisible() {
- if (DBG) debug("isVisible()");
- try {
- return mService.isVisible();
- } catch (RemoteException e) {
- Log.e(TAG, "isVisible() failed: " + e);
- return false;
- }
+ return mSearchDialog == null? false : mSearchDialog.isShowing();
}
/**
@@ -1976,44 +1960,14 @@
mCancelListener = listener;
}
- private class SearchManagerCallback extends ISearchManagerCallback.Stub {
-
- private final Runnable mFireOnDismiss = new Runnable() {
- public void run() {
- if (DBG) debug("mFireOnDismiss");
- if (mDismissListener != null) {
- mDismissListener.onDismiss();
- }
- }
- };
-
- private final Runnable mFireOnCancel = new Runnable() {
- public void run() {
- if (DBG) debug("mFireOnCancel");
- if (mCancelListener != null) {
- mCancelListener.onCancel();
- }
- }
- };
-
- public void onDismiss() {
- if (DBG) debug("onDismiss()");
- mHandler.post(mFireOnDismiss);
- }
-
- public void onCancel() {
- if (DBG) debug("onCancel()");
- mHandler.post(mFireOnCancel);
- }
-
- }
-
/**
* @deprecated This method is an obsolete internal implementation detail. Do not use.
*/
@Deprecated
public void onCancel(DialogInterface dialog) {
- throw new UnsupportedOperationException();
+ if (mCancelListener != null) {
+ mCancelListener.onCancel();
+ }
}
/**
@@ -2021,7 +1975,9 @@
*/
@Deprecated
public void onDismiss(DialogInterface dialog) {
- throw new UnsupportedOperationException();
+ if (mDismissListener != null) {
+ mDismissListener.onDismiss();
+ }
}
/**
@@ -2208,4 +2164,4 @@
Thread thread = Thread.currentThread();
Log.d(TAG, msg + " (" + thread.getName() + "-" + thread.getId() + ")");
}
-}
\ No newline at end of file
+}