From 383c507c47a5abf3258fc04220f37c366f983a97 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 12 Jun 2015 21:18:53 -0700 Subject: Removing ContentObserver in launcher > Using callback insted of using a content observer > Setting the listener in LauncherAppState to prevent resource leak Change-Id: Id23a4d5c8812e86178997e536226e09ec3740f84 --- src/com/android/launcher3/Launcher.java | 38 ++++----------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'src/com/android/launcher3/Launcher.java') diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index ce0f304c1..9989abb6d 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -36,7 +36,6 @@ import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.ComponentCallbacks2; import android.content.ComponentName; -import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -48,7 +47,6 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; -import android.database.ContentObserver; import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -241,7 +239,6 @@ public class Launcher extends Activity private final BroadcastReceiver mCloseSystemDialogsReceiver = new CloseSystemDialogsIntentReceiver(); - private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); private LayoutInflater mInflater; @@ -438,7 +435,6 @@ public class Launcher extends Activity LauncherAppState.setApplicationContext(getApplicationContext()); LauncherAppState app = LauncherAppState.getInstance(); - LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this); // Load configuration-specific DeviceProfile mDeviceProfile = getResources().getConfiguration().orientation @@ -478,8 +474,6 @@ public class Launcher extends Activity setupViews(); mDeviceProfile.layout(this); - registerContentObservers(); - lockAllApps(); mSavedState = savedInstanceState; @@ -2017,7 +2011,6 @@ public class Launcher extends Activity TextKeyListener.getInstance().release(); - getContentResolver().unregisterContentObserver(mWidgetObserver); unregisterReceiver(mCloseSystemDialogsReceiver); mDragLayer.clearAllResizeFrames(); @@ -2386,16 +2379,6 @@ public class Launcher extends Activity sFolders.remove(folder.id); } - /** - * Registers various content observers. The current implementation registers - * only a favorites observer to keep track of the favorites applications. - */ - 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) { @@ -2452,9 +2435,10 @@ public class Launcher extends Activity } /** - * Re-listen when widgets are reset. + * Re-listen when widget host is reset. */ - @Thunk void onAppWidgetReset() { + @Override + public void onAppWidgetHostReset() { if (mAppWidgetHost != null) { mAppWidgetHost.startListening(); } @@ -2939,7 +2923,7 @@ public class Launcher extends Activity return false; } - private boolean startActivitySafely(View v, Intent intent, Object tag) { + @Thunk boolean startActivitySafely(View v, Intent intent, Object tag) { boolean success = false; if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); @@ -3561,20 +3545,6 @@ public 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(); - } - } - /** * If the activity is currently paused, signal that we need to run the passed Runnable * in onResume. -- cgit v1.2.3