summaryrefslogtreecommitdiffstats
path: root/core/java/android/app
diff options
context:
space:
mode:
authorBjorn Bringert <bringert@android.com>2009-07-06 21:32:50 +0100
committerBjorn Bringert <bringert@android.com>2009-07-08 17:43:49 +0100
commit444c727e0eecf83e9d0b9c4e7af5cbf5fc4135f8 (patch)
tree5deb7155bf79ae9001f9d742c905fac2baf7fd9c /core/java/android/app
parente9ac96f76d513d2cee50dfea7d70b14669643ba9 (diff)
downloadframeworks_base-444c727e0eecf83e9d0b9c4e7af5cbf5fc4135f8.zip
frameworks_base-444c727e0eecf83e9d0b9c4e7af5cbf5fc4135f8.tar.gz
frameworks_base-444c727e0eecf83e9d0b9c4e7af5cbf5fc4135f8.tar.bz2
Run search UI on its own thread.
Details: - Add a new SearchDialogWrapper class that makes sure all access to the SearchDialog is run one a single thread other than the main ServerThread. - Don't save/restore seach dialog state in Activity. This resulted in lots of calls to the SearchManager throughout the life cycle of all activities, for the questionable benefit of restoring the search dialog in a few cases. - Remove search UI state save/restore, and the isVisible() method from SearchManagerService. They are no longer used, and were tricky to implement since they return values from the search UI thread to the service. - Handle configuration changes in searchDialogWrapper instead of calling through from Activity. Fixes http://b/issue?id=1938101 TODO: - Activity.performPause() calls stopSearch(). This call may not happen until the new activity has been started. If the new activity starts a search immediately, this search could be cancelled by the old activity's call top stopSearch().
Diffstat (limited to 'core/java/android/app')
-rw-r--r--core/java/android/app/Activity.java37
-rw-r--r--core/java/android/app/ISearchManager.aidl4
-rw-r--r--core/java/android/app/SearchDialog.java81
-rw-r--r--core/java/android/app/SearchManager.java54
4 files changed, 18 insertions, 158 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index ca9632a..df50f77 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -606,7 +606,6 @@ public class Activity extends ContextThemeWrapper
private static final String SAVED_DIALOG_IDS_KEY = "android:savedDialogIds";
private static final String SAVED_DIALOGS_TAG = "android:savedDialogs";
private static final String SAVED_DIALOG_KEY_PREFIX = "android:dialog_";
- private static final String SAVED_SEARCH_DIALOG_KEY = "android:search_dialog";
private SparseArray<Dialog> mManagedDialogs;
@@ -630,7 +629,6 @@ public class Activity extends ContextThemeWrapper
/*package*/ int mConfigChangeFlags;
/*package*/ Configuration mCurrentConfig;
private SearchManager mSearchManager;
- private Bundle mSearchDialogState = null;
private Window mWindow;
@@ -808,13 +806,6 @@ public class Activity extends ContextThemeWrapper
final void performRestoreInstanceState(Bundle savedInstanceState) {
onRestoreInstanceState(savedInstanceState);
restoreManagedDialogs(savedInstanceState);
-
- // Also restore the state of a search dialog (if any)
- // TODO more generic than just this manager
- Bundle searchState = savedInstanceState.getBundle(SAVED_SEARCH_DIALOG_KEY);
- if (searchState != null) {
- mSearchManager.restoreSearchDialog(searchState);
- }
}
/**
@@ -1030,14 +1021,6 @@ public class Activity extends ContextThemeWrapper
final void performSaveInstanceState(Bundle outState) {
onSaveInstanceState(outState);
saveManagedDialogs(outState);
-
- // Also save the state of a search dialog (if any)
- // TODO more generic than just this manager
- // onPause() should always be called before this method, so mSearchManagerState
- // should be up to date.
- if (mSearchDialogState != null) {
- outState.putBundle(SAVED_SEARCH_DIALOG_KEY, mSearchDialogState);
- }
}
/**
@@ -1317,10 +1300,6 @@ public class Activity extends ContextThemeWrapper
c.mCursor.close();
}
}
-
- // Clear any search state saved in performPause(). If the state may be needed in the
- // future, it will have been saved by performSaveInstanceState()
- mSearchDialogState = null;
}
/**
@@ -1341,11 +1320,7 @@ public class Activity extends ContextThemeWrapper
*/
public void onConfigurationChanged(Configuration newConfig) {
mCalled = true;
-
- // also update search dialog if showing
- // TODO more generic than just this manager
- mSearchManager.onConfigurationChanged(newConfig);
-
+
if (mWindow != null) {
// Pass the configuration changed event to the window
mWindow.onConfigurationChanged(newConfig);
@@ -3575,20 +3550,12 @@ public class Activity extends ContextThemeWrapper
"Activity " + mComponent.toShortString() +
" did not call through to super.onPostResume()");
}
-
- // restore search dialog, if any
- if (mSearchDialogState != null) {
- mSearchManager.restoreSearchDialog(mSearchDialogState);
- }
- mSearchDialogState = null;
}
final void performPause() {
onPause();
- // save search dialog state if the search dialog is open,
- // and then dismiss the search dialog
- mSearchDialogState = mSearchManager.saveSearchDialog();
+ // dismiss the search dialog if it is open
mSearchManager.stopSearch();
}
diff --git a/core/java/android/app/ISearchManager.aidl b/core/java/android/app/ISearchManager.aidl
index e8bd60a..5b62192 100644
--- a/core/java/android/app/ISearchManager.aidl
+++ b/core/java/android/app/ISearchManager.aidl
@@ -36,8 +36,4 @@ interface ISearchManager {
boolean globalSearch,
ISearchManagerCallback searchManagerCallback);
void stopSearch();
- boolean isVisible();
- Bundle onSaveInstanceState();
- void onRestoreInstanceState(in Bundle savedInstanceState);
- void onConfigurationChanged(in Configuration newConfig);
}
diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java
index 2bcc9c3..022a9d9 100644
--- a/core/java/android/app/SearchDialog.java
+++ b/core/java/android/app/SearchDialog.java
@@ -19,13 +19,11 @@ package android.app;
import static android.app.SuggestionsAdapter.getColumnString;
import android.content.ActivityNotFoundException;
-import android.content.BroadcastReceiver;
import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
import android.content.ContentResolver;
import android.content.ContentValues;
+import android.content.Context;
+import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@@ -33,8 +31,8 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
-import android.graphics.drawable.Drawable;
import android.graphics.drawable.Animatable;
+import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
@@ -95,11 +93,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
private static final int SEARCH_PLATE_LEFT_PADDING_GLOBAL = 12;
private static final int SEARCH_PLATE_LEFT_PADDING_NON_GLOBAL = 7;
-
- // interaction with runtime
- private IntentFilter mCloseDialogsFilter;
- private IntentFilter mPackageFilter;
-
+
// views & widgets
private TextView mBadgeLabel;
private ImageView mAppIcon;
@@ -210,15 +204,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
// Touching outside of the search dialog will dismiss it
setCanceledOnTouchOutside(true);
-
- // Set up broadcast filters
- mCloseDialogsFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
- mPackageFilter = new IntentFilter();
- mPackageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
- mPackageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
- mPackageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
- mPackageFilter.addDataScheme("package");
-
+
// Save voice intent for later queries/launching
mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -382,15 +368,6 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
return true;
}
-
- @Override
- protected void onStart() {
- super.onStart();
-
- // receive broadcasts
- getContext().registerReceiver(mBroadcastReceiver, mCloseDialogsFilter);
- getContext().registerReceiver(mBroadcastReceiver, mPackageFilter);
- }
/**
* The search dialog is being dismissed, so handle all of the local shutdown operations.
@@ -401,14 +378,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
@Override
public void onStop() {
super.onStop();
-
- // stop receiving broadcasts (throws exception if none registered)
- try {
- getContext().unregisterReceiver(mBroadcastReceiver);
- } catch (RuntimeException e) {
- // This is OK - it just means we didn't have any registered
- }
-
+
closeSuggestionsAdapter();
// dump extra memory we're hanging on to
@@ -455,12 +425,15 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
/**
* Save the minimal set of data necessary to recreate the search
*
- * @return A bundle with the state of the dialog.
+ * @return A bundle with the state of the dialog, or {@code null} if the search
+ * dialog is not showing.
*/
@Override
public Bundle onSaveInstanceState() {
+ if (!isShowing()) return null;
+
Bundle bundle = new Bundle();
-
+
// setup info so I can recreate this particular search
bundle.putParcelable(INSTANCE_KEY_COMPONENT, mLaunchComponent);
bundle.putBundle(INSTANCE_KEY_APPDATA, mAppSearchData);
@@ -483,6 +456,8 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
*/
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
+ if (savedInstanceState == null) return;
+
ComponentName launchComponent = savedInstanceState.getParcelable(INSTANCE_KEY_COMPONENT);
Bundle appSearchData = savedInstanceState.getBundle(INSTANCE_KEY_APPDATA);
boolean globalSearch = savedInstanceState.getBoolean(INSTANCE_KEY_GLOBALSEARCH);
@@ -509,7 +484,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
/**
* Called after resources have changed, e.g. after screen rotation or locale change.
*/
- public void onConfigurationChanged(Configuration newConfig) {
+ public void onConfigurationChanged() {
if (isShowing()) {
// Redraw (resources may have changed)
updateSearchButton();
@@ -1014,35 +989,11 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
return false;
}
};
-
- /**
- * When the ACTION_CLOSE_SYSTEM_DIALOGS intent is received, we should close ourselves
- * immediately, in order to allow a higher-priority UI to take over
- * (e.g. phone call received).
- *
- * When a package is added, removed or changed, our current context
- * may no longer be valid. This would only happen if a package is installed/removed exactly
- * when the search bar is open. So for now we're just going to close the search
- * bar.
- * Anything fancier would require some checks to see if the user's context was still valid.
- * Which would be messier.
- */
- private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
- cancel();
- } else if (Intent.ACTION_PACKAGE_ADDED.equals(action)
- || Intent.ACTION_PACKAGE_REMOVED.equals(action)
- || Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
- cancel();
- }
- }
- };
@Override
public void cancel() {
+ if (!isShowing()) return;
+
// We made sure the IME was displayed, so also make sure it is closed
// when we go away.
InputMethodManager imm = (InputMethodManager)getContext()
diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java
index e5ba6a4..5d25f10 100644
--- a/core/java/android/app/SearchManager.java
+++ b/core/java/android/app/SearchManager.java
@@ -20,7 +20,6 @@ import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.res.Configuration;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
@@ -1730,59 +1729,6 @@ public class SearchManager
}
/**
- * Saves the state of the search UI.
- *
- * @return A Bundle containing the state of the search dialog, or {@code null}
- * if the search UI is not visible.
- *
- * @hide
- */
- public Bundle saveSearchDialog() {
- if (DBG) debug("saveSearchDialog(), mIsShowing=" + mIsShowing);
- if (!mIsShowing) return null;
- try {
- return mService.onSaveInstanceState();
- } catch (RemoteException ex) {
- Log.e(TAG, "onSaveInstanceState() failed: " + ex);
- return null;
- }
- }
-
- /**
- * Restores the state of the search dialog.
- *
- * @param searchDialogState Bundle to read the state from.
- *
- * @hide
- */
- public void restoreSearchDialog(Bundle searchDialogState) {
- if (DBG) debug("restoreSearchDialog(" + searchDialogState + ")");
- if (searchDialogState == null) return;
- try {
- mService.onRestoreInstanceState(searchDialogState);
- } catch (RemoteException ex) {
- Log.e(TAG, "onRestoreInstanceState() failed: " + ex);
- }
- }
-
- /**
- * Update the search dialog after a configuration change.
- *
- * @param newConfig The new configuration.
- *
- * @hide
- */
- public void onConfigurationChanged(Configuration newConfig) {
- if (DBG) debug("onConfigurationChanged(" + newConfig + "), mIsShowing=" + mIsShowing);
- if (!mIsShowing) return;
- try {
- mService.onConfigurationChanged(newConfig);
- } catch (RemoteException ex) {
- Log.e(TAG, "onConfigurationChanged() failed:" + ex);
- }
- }
-
- /**
* Gets information about a searchable activity. This method is static so that it can
* be used from non-Activity contexts.
*