Removing ContentObserver in launcher
> Using callback insted of using a content observer > Setting the listener in LauncherAppState to prevent resource leak Change-Id: Id23a4d5c8812e86178997e536226e09ec3740f84
This commit is contained in:
parent
c332934e27
commit
383c507c47
|
@ -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.
|
||||
|
|
|
@ -84,7 +84,7 @@ public class LauncherAppState {
|
|||
|
||||
mInvariantDeviceProfile = new InvariantDeviceProfile(sContext);
|
||||
mIconCache = new IconCache(sContext, mInvariantDeviceProfile);
|
||||
mWidgetCache = new WidgetPreviewLoader(sContext, mInvariantDeviceProfile, mIconCache);
|
||||
mWidgetCache = new WidgetPreviewLoader(sContext, mIconCache);
|
||||
|
||||
mAppFilter = AppFilter.loadByName(sContext.getString(R.string.app_filter_class));
|
||||
mBuildInfo = BuildInfo.loadByName(sContext.getString(R.string.build_info_class));
|
||||
|
@ -125,6 +125,7 @@ public class LauncherAppState {
|
|||
}
|
||||
|
||||
LauncherModel setLauncher(Launcher launcher) {
|
||||
getLauncherProvider().setLauncherProviderChangeListener(launcher);
|
||||
mModel.initialize(launcher);
|
||||
mAccessibilityDelegate = ((launcher != null) && Utilities.isLmpOrAbove()) ?
|
||||
new LauncherAccessibilityDelegate(launcher) : null;
|
||||
|
|
|
@ -80,16 +80,7 @@ public class LauncherProvider extends ContentProvider {
|
|||
|
||||
private static final String RESTRICTION_PACKAGE_NAME = "workspace.configuration.package.name";
|
||||
|
||||
private LauncherProviderChangeListener mListener;
|
||||
|
||||
/**
|
||||
* {@link Uri} triggered at any registered {@link android.database.ContentObserver} when
|
||||
* {@link AppWidgetHost#deleteHost()} is called during database creation.
|
||||
* Use this to recall {@link AppWidgetHost#startListening()} if needed.
|
||||
*/
|
||||
static final Uri CONTENT_APPWIDGET_RESET_URI =
|
||||
Uri.parse("content://" + AUTHORITY + "/appWidgetReset");
|
||||
|
||||
@Thunk LauncherProviderChangeListener mListener;
|
||||
@Thunk DatabaseHelper mOpenHelper;
|
||||
|
||||
@Override
|
||||
|
@ -279,6 +270,18 @@ public class LauncherProvider extends ContentProvider {
|
|||
}
|
||||
}
|
||||
|
||||
@Thunk void notifyAppWidgetHostReset() {
|
||||
new MainThreadExecutor().execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (mListener != null) {
|
||||
mListener.onAppWidgetHostReset();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Thunk static void addModifiedTime(ContentValues values) {
|
||||
values.put(LauncherSettings.ChangeLogColumns.MODIFIED, System.currentTimeMillis());
|
||||
}
|
||||
|
@ -455,17 +458,6 @@ public class LauncherProvider extends ContentProvider {
|
|||
return mNewDbCreated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification that we've deleted the {@link AppWidgetHost},
|
||||
* probably as part of the initial database creation. The receiver may
|
||||
* want to re-call {@link AppWidgetHost#startListening()} to ensure
|
||||
* callbacks are correctly set.
|
||||
*/
|
||||
private void sendAppWidgetResetNotify() {
|
||||
final ContentResolver resolver = mContext.getContentResolver();
|
||||
resolver.notifyChange(CONTENT_APPWIDGET_RESET_URI, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
if (LOGD) Log.d(TAG, "creating new launcher database");
|
||||
|
@ -509,7 +501,14 @@ public class LauncherProvider extends ContentProvider {
|
|||
// Database was just created, so wipe any previous widgets
|
||||
if (mAppWidgetHost != null) {
|
||||
mAppWidgetHost.deleteHost();
|
||||
sendAppWidgetResetNotify();
|
||||
|
||||
/**
|
||||
* Send notification that we've deleted the {@link AppWidgetHost},
|
||||
* probably as part of the initial database creation. The receiver may
|
||||
* want to re-call {@link AppWidgetHost#startListening()} to ensure
|
||||
* callbacks are correctly set.
|
||||
*/
|
||||
LauncherAppState.getLauncherProvider().notifyAppWidgetHostReset();
|
||||
}
|
||||
|
||||
// Fresh and clean launcher DB.
|
||||
|
@ -517,7 +516,7 @@ public class LauncherProvider extends ContentProvider {
|
|||
setFlagEmptyDbCreated();
|
||||
|
||||
// When a new DB is created, remove all previously stored managed profile information.
|
||||
ManagedProfileHeuristic.processAllUsers(Collections.EMPTY_LIST, mContext);
|
||||
ManagedProfileHeuristic.processAllUsers(Collections.<UserHandleCompat>emptyList(), mContext);
|
||||
}
|
||||
|
||||
private void addWorkspacesTable(SQLiteDatabase db) {
|
||||
|
|
|
@ -10,4 +10,6 @@ public interface LauncherProviderChangeListener {
|
|||
public void onLauncherProviderChange();
|
||||
|
||||
public void onSettingsChanged(String settings, boolean value);
|
||||
|
||||
public void onAppWidgetHostReset();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.os.AsyncTask;
|
|||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.util.LongSparseArray;
|
||||
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.compat.UserHandleCompat;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
|
@ -69,7 +70,7 @@ public class WidgetPreviewLoader {
|
|||
private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
|
||||
@Thunk final Handler mWorkerHandler;
|
||||
|
||||
public WidgetPreviewLoader(Context context, InvariantDeviceProfile inv, IconCache iconCache) {
|
||||
public WidgetPreviewLoader(Context context, IconCache iconCache) {
|
||||
mContext = context;
|
||||
mIconCache = iconCache;
|
||||
mManager = AppWidgetManagerCompat.getInstance(context);
|
||||
|
|
|
@ -56,7 +56,7 @@ final class DefaultAppSearchController extends AllAppsSearchBarController
|
|||
private View mDismissSearchButtonView;
|
||||
@Thunk AllAppsSearchEditView mSearchBarEditView;
|
||||
@Thunk AllAppsRecyclerView mAppsRecyclerView;
|
||||
private Runnable mFocusRecyclerViewRunnable = new Runnable() {
|
||||
@Thunk Runnable mFocusRecyclerViewRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mAppsRecyclerView.requestFocus();
|
||||
|
|
Loading…
Reference in New Issue