From 1e2efc8a6d355bb6c0fc75261eb819e250ddb8fb Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 6 Nov 2009 15:17:59 -0800 Subject: [PATCH] Start listening again after LauncherProvider clears widgets. After the LauncherProvider resets the database and wipes out the host info, the Launcher must tell the AppWidgetHost to listen again. Originally 87e688d8... in packages/apps/Launcher. Fixes http://b/2238470 --- src/com/android/launcher2/Launcher.java | 37 ++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 2c59b4c819..be1ee67bc4 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -26,6 +26,7 @@ import android.app.WallpaperInfo; import android.app.WallpaperManager; import android.content.ActivityNotFoundException; import android.content.ComponentName; +import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -36,9 +37,11 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; import android.content.res.Resources; +import android.database.ContentObserver; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.os.Handler; import android.os.Parcelable; import android.os.RemoteException; import android.os.ServiceManager; @@ -151,6 +154,8 @@ public final class Launcher extends Activity private static final Object sLock = new Object(); private static int sScreen = DEFAULT_SCREEN; + private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); + private LayoutInflater mInflater; private DragController mDragController; @@ -200,7 +205,6 @@ public final class Launcher extends Activity mInflater = getLayoutInflater(); mAppWidgetManager = AppWidgetManager.getInstance(this); - mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); mAppWidgetHost.startListening(); @@ -214,6 +218,8 @@ public final class Launcher extends Activity setContentView(R.layout.launcher); setupViews(); + registerContentObservers(); + lockAllApps(); mSavedState = savedInstanceState; @@ -903,6 +909,8 @@ public final class Launcher extends Activity unbindDesktopItems(); AppInfoCache.unbindDrawables(); + + getContentResolver().unregisterContentObserver(mWidgetObserver); } @Override @@ -1269,6 +1277,12 @@ public final class Launcher extends Activity startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); } + private void registerContentObservers() { + ContentResolver resolver = getContentResolver(); + resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, + true, mWidgetObserver); + } + @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { @@ -1318,6 +1332,13 @@ public final class Launcher extends Activity folder.onClose(); } + /** + * Re-listen when widgets are reset. + */ + private void onAppWidgetReset() { + mAppWidgetHost.startListening(); + } + /** * Go through the and disconnect any of the callbacks in the drawables and the views or we * leak the previous Home screen on orientation change. @@ -1763,6 +1784,20 @@ public final class Launcher extends Activity } } + /** + * Receives notifications whenever the appwidgets are reset. + */ + private class AppWidgetResetObserver extends ContentObserver { + public AppWidgetResetObserver() { + super(new Handler()); + } + + @Override + public void onChange(boolean selfChange) { + onAppWidgetReset(); + } + } + /** * Implementation of the method from LauncherModel.Callbacks. */