Loading src/com/android/launcher3/LauncherModel.java +51 −10 Original line number Diff line number Diff line Loading @@ -107,6 +107,7 @@ public class LauncherModel extends BroadcastReceiver @Thunk DeferredHandler mHandler = new DeferredHandler(); @Thunk LoaderTask mLoaderTask; @Thunk boolean mIsLoaderTaskRunning; @Thunk boolean mHasLoaderCompletedOnce; private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings"; Loading @@ -128,6 +129,12 @@ public class LauncherModel extends BroadcastReceiver // a normal load, we also clear this set of Runnables. static final ArrayList<Runnable> mDeferredBindRunnables = new ArrayList<Runnable>(); /** * Set of runnables to be called on the background thread after the workspace binding * is complete. */ static final ArrayList<Runnable> mBindCompleteRunnables = new ArrayList<Runnable>(); @Thunk WeakReference<Callbacks> mCallbacks; // < only access in worker thread > Loading Loading @@ -263,6 +270,19 @@ public class LauncherModel extends BroadcastReceiver } } /** * Runs the specified runnable after the loader is complete */ private void runAfterBindCompletes(Runnable r) { if (isLoadingWorkspace() || !mHasLoaderCompletedOnce) { synchronized (mBindCompleteRunnables) { mBindCompleteRunnables.add(r); } } else { runOnWorkerThread(r); } } boolean canMigrateFromOldLauncherDb(Launcher launcher) { return mOldContentProviderExists && !launcher.isLauncherPreinstalled() ; } Loading Loading @@ -424,7 +444,7 @@ public class LauncherModel extends BroadcastReceiver * Find a position on the screen for the given size or adds a new screen. * @return screenId and the coordinates for the item. */ @Thunk static Pair<Long, int[]> findSpaceForItem( @Thunk Pair<Long, int[]> findSpaceForItem( Context context, ArrayList<Long> workspaceScreens, ArrayList<Long> addedWorkspaceScreensFinal, Loading @@ -432,7 +452,7 @@ public class LauncherModel extends BroadcastReceiver LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>(); // Use sBgItemsIdMap as all the items are already loaded. // TODO: Throw exception is above condition is not met. assertWorkspaceLoaded(); synchronized (sBgLock) { for (ItemInfo info : sBgItemsIdMap) { if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { Loading Loading @@ -875,12 +895,18 @@ public class LauncherModel extends BroadcastReceiver updateItemInDatabaseHelper(context, values, item, "updateItemInDatabase"); } private void assertWorkspaceLoaded() { if (LauncherAppState.isDogfoodBuild() && (isLoadingWorkspace() || !mHasLoaderCompletedOnce)) { throw new RuntimeException("Trying to add shortcut while loader is running"); } } /** * Returns true if the shortcuts already exists on the workspace. This must be called after * the workspace has been loaded. We identify a shortcut by its intent. * TODO: Throw exception is above condition is not met. */ @Thunk static boolean shortcutExists(Context context, Intent intent, UserHandleCompat user) { @Thunk boolean shortcutExists(Context context, Intent intent, UserHandleCompat user) { assertWorkspaceLoaded(); final String intentWithPkg, intentWithoutPkg; final String packageName; if (intent.getComponent() != null) { Loading Loading @@ -1390,6 +1416,16 @@ public class LauncherModel extends BroadcastReceiver mHandler.post(r); } } // Run all the bind complete runnables after workspace is bound. if (!mBindCompleteRunnables.isEmpty()) { synchronized (mBindCompleteRunnables) { for (final Runnable r : mBindCompleteRunnables) { runOnWorkerThread(r); } mBindCompleteRunnables.clear(); } } } public void stopLoader() { Loading Loading @@ -1615,6 +1651,7 @@ public class LauncherModel extends BroadcastReceiver mLoaderTask = null; } mIsLoaderTaskRunning = false; mHasLoaderCompletedOnce = true; } } Loading Loading @@ -2794,7 +2831,7 @@ public class LauncherModel extends BroadcastReceiver for (UserHandleCompat user : profiles) { // Query for the set of apps final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user); final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user); if (DEBUG_LOADERS) { Log.d(TAG, "getActivityList took " + (SystemClock.uptimeMillis()-qiaTime) + "ms for user " + user); Loading Loading @@ -2849,11 +2886,15 @@ public class LauncherModel extends BroadcastReceiver mBgAllAppsList.add(new AppInfo(mContext, app, user, mIconCache)); } if (!user.equals(UserHandleCompat.myUserHandle())) { ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext, user); final ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext, user); if (heuristic != null) { runAfterBindCompletes(new Runnable() { @Override public void run() { heuristic.processUserApps(apps); } }); } } // Huh? Shouldn't this be inside the Runnable below? Loading Loading
src/com/android/launcher3/LauncherModel.java +51 −10 Original line number Diff line number Diff line Loading @@ -107,6 +107,7 @@ public class LauncherModel extends BroadcastReceiver @Thunk DeferredHandler mHandler = new DeferredHandler(); @Thunk LoaderTask mLoaderTask; @Thunk boolean mIsLoaderTaskRunning; @Thunk boolean mHasLoaderCompletedOnce; private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings"; Loading @@ -128,6 +129,12 @@ public class LauncherModel extends BroadcastReceiver // a normal load, we also clear this set of Runnables. static final ArrayList<Runnable> mDeferredBindRunnables = new ArrayList<Runnable>(); /** * Set of runnables to be called on the background thread after the workspace binding * is complete. */ static final ArrayList<Runnable> mBindCompleteRunnables = new ArrayList<Runnable>(); @Thunk WeakReference<Callbacks> mCallbacks; // < only access in worker thread > Loading Loading @@ -263,6 +270,19 @@ public class LauncherModel extends BroadcastReceiver } } /** * Runs the specified runnable after the loader is complete */ private void runAfterBindCompletes(Runnable r) { if (isLoadingWorkspace() || !mHasLoaderCompletedOnce) { synchronized (mBindCompleteRunnables) { mBindCompleteRunnables.add(r); } } else { runOnWorkerThread(r); } } boolean canMigrateFromOldLauncherDb(Launcher launcher) { return mOldContentProviderExists && !launcher.isLauncherPreinstalled() ; } Loading Loading @@ -424,7 +444,7 @@ public class LauncherModel extends BroadcastReceiver * Find a position on the screen for the given size or adds a new screen. * @return screenId and the coordinates for the item. */ @Thunk static Pair<Long, int[]> findSpaceForItem( @Thunk Pair<Long, int[]> findSpaceForItem( Context context, ArrayList<Long> workspaceScreens, ArrayList<Long> addedWorkspaceScreensFinal, Loading @@ -432,7 +452,7 @@ public class LauncherModel extends BroadcastReceiver LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>(); // Use sBgItemsIdMap as all the items are already loaded. // TODO: Throw exception is above condition is not met. assertWorkspaceLoaded(); synchronized (sBgLock) { for (ItemInfo info : sBgItemsIdMap) { if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { Loading Loading @@ -875,12 +895,18 @@ public class LauncherModel extends BroadcastReceiver updateItemInDatabaseHelper(context, values, item, "updateItemInDatabase"); } private void assertWorkspaceLoaded() { if (LauncherAppState.isDogfoodBuild() && (isLoadingWorkspace() || !mHasLoaderCompletedOnce)) { throw new RuntimeException("Trying to add shortcut while loader is running"); } } /** * Returns true if the shortcuts already exists on the workspace. This must be called after * the workspace has been loaded. We identify a shortcut by its intent. * TODO: Throw exception is above condition is not met. */ @Thunk static boolean shortcutExists(Context context, Intent intent, UserHandleCompat user) { @Thunk boolean shortcutExists(Context context, Intent intent, UserHandleCompat user) { assertWorkspaceLoaded(); final String intentWithPkg, intentWithoutPkg; final String packageName; if (intent.getComponent() != null) { Loading Loading @@ -1390,6 +1416,16 @@ public class LauncherModel extends BroadcastReceiver mHandler.post(r); } } // Run all the bind complete runnables after workspace is bound. if (!mBindCompleteRunnables.isEmpty()) { synchronized (mBindCompleteRunnables) { for (final Runnable r : mBindCompleteRunnables) { runOnWorkerThread(r); } mBindCompleteRunnables.clear(); } } } public void stopLoader() { Loading Loading @@ -1615,6 +1651,7 @@ public class LauncherModel extends BroadcastReceiver mLoaderTask = null; } mIsLoaderTaskRunning = false; mHasLoaderCompletedOnce = true; } } Loading Loading @@ -2794,7 +2831,7 @@ public class LauncherModel extends BroadcastReceiver for (UserHandleCompat user : profiles) { // Query for the set of apps final long qiaTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user); final List<LauncherActivityInfoCompat> apps = mLauncherApps.getActivityList(null, user); if (DEBUG_LOADERS) { Log.d(TAG, "getActivityList took " + (SystemClock.uptimeMillis()-qiaTime) + "ms for user " + user); Loading Loading @@ -2849,11 +2886,15 @@ public class LauncherModel extends BroadcastReceiver mBgAllAppsList.add(new AppInfo(mContext, app, user, mIconCache)); } if (!user.equals(UserHandleCompat.myUserHandle())) { ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext, user); final ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext, user); if (heuristic != null) { runAfterBindCompletes(new Runnable() { @Override public void run() { heuristic.processUserApps(apps); } }); } } // Huh? Shouldn't this be inside the Runnable below? Loading