summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Onorato <joeo@android.com>2010-10-26 19:25:42 -0700
committerJoe Onorato <joeo@android.com>2010-10-26 19:27:21 -0700
commitec8345a13fe23db9f481d82bc14ce597c02c4e0f (patch)
tree11aa25fc16039ca1462399f7a2466286e0b2acc8
parent188eb40670f7ad68f7f595bd42e6196dd6ab8bf9 (diff)
downloadandroid_packages_apps_Trebuchet-ec8345a13fe23db9f481d82bc14ce597c02c4e0f.tar.gz
android_packages_apps_Trebuchet-ec8345a13fe23db9f481d82bc14ce597c02c4e0f.tar.bz2
android_packages_apps_Trebuchet-ec8345a13fe23db9f481d82bc14ce597c02c4e0f.zip
When the launcher is paused and we reload stuff in the background, we need to re-re-load it in onResume.
Otherwise we can load widgets and other resources from the wrong Configuration. This doesn't completely fix the bug, but it makes it much less likely. We tell the launcher once at the beginning of starting a reload because of SD cards coming back, and once when we bind. Bug: 3126698 Change-Id: I99ee6af38bef91e261832bad4dec978a5d4a8b3d
-rw-r--r--src/com/android/launcher2/Launcher.java40
-rw-r--r--src/com/android/launcher2/LauncherModel.java15
2 files changed, 51 insertions, 4 deletions
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 9626a2ec2..e61130305 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -194,6 +194,7 @@ public final class Launcher extends Activity
private boolean mPaused = true;
private boolean mRestoring;
private boolean mWaitingForResult;
+ private boolean mOnResumeNeedsLoad;
private Bundle mSavedInstanceState;
@@ -583,19 +584,19 @@ public final class Launcher extends Activity
@Override
protected void onResume() {
super.onResume();
-
mPaused = false;
-
- if (mRestoring) {
+ if (mRestoring || mOnResumeNeedsLoad) {
mWorkspaceLoading = true;
mModel.startLoader(this, true);
mRestoring = false;
+ mOnResumeNeedsLoad = false;
}
}
@Override
protected void onPause() {
super.onPause();
+ mPaused = true;
dismissPreview(mPreviousView);
dismissPreview(mNextView);
mDragController.cancelDrag();
@@ -2125,6 +2126,30 @@ public final class Launcher extends Activity
}
/**
+ * If the activity is currently paused, signal that we need to re-run the loader
+ * in onResume.
+ *
+ * This needs to be called from incoming places where resources might have been loaded
+ * while we are paused. That is becaues the Configuration might be wrong
+ * when we're not running, and if it comes back to what it was when we
+ * were paused, we are not restarted.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ *
+ * @return true if we are currently paused. The caller might be able to
+ * skip some work in that case since we will come back again.
+ */
+ public boolean setLoadOnResume() {
+ if (mPaused) {
+ Log.i(TAG, "setLoadOnResume");
+ mOnResumeNeedsLoad = true;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
* Implementation of the method from LauncherModel.Callbacks.
*/
public int getCurrentWorkspaceScreen() {
@@ -2168,6 +2193,8 @@ public final class Launcher extends Activity
*/
public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
+ setLoadOnResume();
+
final Workspace workspace = mWorkspace;
for (int i=start; i<end; i++) {
@@ -2205,6 +2232,7 @@ public final class Launcher extends Activity
* Implementation of the method from LauncherModel.Callbacks.
*/
public void bindFolders(HashMap<Long, FolderInfo> folders) {
+ setLoadOnResume();
sFolders.clear();
sFolders.putAll(folders);
}
@@ -2215,6 +2243,8 @@ public final class Launcher extends Activity
* Implementation of the method from LauncherModel.Callbacks.
*/
public void bindAppWidget(LauncherAppWidgetInfo item) {
+ setLoadOnResume();
+
final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
if (DEBUG_WIDGETS) {
Log.d(TAG, "bindAppWidget: " + item);
@@ -2251,6 +2281,8 @@ public final class Launcher extends Activity
* Implementation of the method from LauncherModel.Callbacks.
*/
public void finishBindingItems() {
+ setLoadOnResume();
+
if (mSavedState != null) {
if (!mWorkspace.hasFocus()) {
mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
@@ -2296,6 +2328,7 @@ public final class Launcher extends Activity
* Implementation of the method from LauncherModel.Callbacks.
*/
public void bindAppsAdded(ArrayList<ApplicationInfo> apps) {
+ setLoadOnResume();
removeDialog(DIALOG_CREATE_SHORTCUT);
mAllAppsGrid.addApps(apps);
}
@@ -2306,6 +2339,7 @@ public final class Launcher extends Activity
* Implementation of the method from LauncherModel.Callbacks.
*/
public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) {
+ setLoadOnResume();
removeDialog(DIALOG_CREATE_SHORTCUT);
mWorkspace.updateShortcuts(apps);
mAllAppsGrid.updateApps(apps);
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index cb19fe37f..b819510af 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -96,6 +96,7 @@ public class LauncherModel extends BroadcastReceiver {
private Bitmap mDefaultIcon;
public interface Callbacks {
+ public boolean setLoadOnResume();
public int getCurrentWorkspaceScreen();
public void startBinding();
public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end);
@@ -349,7 +350,19 @@ public class LauncherModel extends BroadcastReceiver {
String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
enqueuePackageUpdated(new PackageUpdatedTask(PackageUpdatedTask.OP_ADD, packages));
// Then, rebind everything.
- startLoader(mApp, false);
+ boolean runLoader = true;
+ if (mCallbacks != null) {
+ Callbacks callbacks = mCallbacks.get();
+ if (callbacks != null) {
+ // If they're paused, we can skip loading, because they'll do it again anyway
+ if (callbacks.setLoadOnResume()) {
+ runLoader = false;
+ }
+ }
+ }
+ if (runLoader) {
+ startLoader(mApp, false);
+ }
} else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
String[] packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);