From 1e92b1fd0582adeea533b05d9423907239ca9069 Mon Sep 17 00:00:00 2001 From: Ricky Wai Date: Thu, 2 Feb 2017 19:11:18 +0000 Subject: [PATCH] Fix duplicates work apps in launcher work folder after reboot Cause: When we run heuristic.processUserApps(apps), "apps" could be outdated, as it's scheduled in mBindCompleteRunnables and only runs after bind completed. The fix is get an updated app list and reschedule processUserApps(). Test: Use DMAgent to activate work proifle, it does not show duplicated work icons anymore. Bug: 32650490 Change-Id: Ia705a24c6264c077af30cc4297c8b165744c827d --- src/com/android/launcher3/LauncherModel.java | 67 +++++++++++++------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 3ac9773d97..0199d0ca78 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -115,6 +115,7 @@ public class LauncherModel extends BroadcastReceiver @Thunk LoaderTask mLoaderTask; @Thunk boolean mIsLoaderTaskRunning; @Thunk boolean mHasLoaderCompletedOnce; + @Thunk boolean mIsManagedHeuristicAppsUpdated; @Thunk static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader"); static { @@ -2726,6 +2727,47 @@ public class LauncherModel extends BroadcastReceiver runOnMainThread(r); } + private void scheduleManagedHeuristicRunnable(final ManagedProfileHeuristic heuristic, + final UserHandleCompat user, final List apps) { + if (heuristic != null) { + // Assume the app lists now is updated. + mIsManagedHeuristicAppsUpdated = false; + final Runnable managedHeuristicRunnable = new Runnable() { + @Override + public void run() { + if (mIsManagedHeuristicAppsUpdated) { + // If app list is updated, we need to reschedule it otherwise old app + // list will override everything in processUserApps(). + sWorker.post(new Runnable() { + public void run() { + final List updatedApps = + mLauncherApps.getActivityList(null, user); + scheduleManagedHeuristicRunnable(heuristic, user, + updatedApps); + } + }); + } else { + heuristic.processUserApps(apps); + } + } + }; + runOnMainThread(new Runnable() { + @Override + public void run() { + // Check isLoadingWorkspace on the UI thread, as it is updated on the UI + // thread. + if (mIsLoadingAndBindingWorkspace) { + synchronized (mBindCompleteRunnables) { + mBindCompleteRunnables.add(managedHeuristicRunnable); + } + } else { + runOnWorkerThread(managedHeuristicRunnable); + } + } + }); + } + } + private void loadAllApps() { final long loadTime = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; @@ -2761,31 +2803,9 @@ public class LauncherModel extends BroadcastReceiver // This builds the icon bitmaps. mBgAllAppsList.add(new AppInfo(mContext, app, user, mIconCache, quietMode)); } - final ManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext, user); if (heuristic != null) { - final Runnable r = new Runnable() { - - @Override - public void run() { - heuristic.processUserApps(apps); - } - }; - runOnMainThread(new Runnable() { - - @Override - public void run() { - // Check isLoadingWorkspace on the UI thread, as it is updated on - // the UI thread. - if (mIsLoadingAndBindingWorkspace) { - synchronized (mBindCompleteRunnables) { - mBindCompleteRunnables.add(r); - } - } else { - runOnWorkerThread(r); - } - } - }); + scheduleManagedHeuristicRunnable(heuristic, user, apps); } } // Huh? Shouldn't this be inside the Runnable below? @@ -3036,6 +3056,7 @@ public class LauncherModel extends BroadcastReceiver // Loader has not yet run. return; } + mIsManagedHeuristicAppsUpdated = true; final Context context = mApp.getContext(); final String[] packages = mPackages;