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
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user