summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherModel.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-05-06 16:48:46 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-05-06 16:48:47 +0000
commitdeb189fd105a5367d965538fd2ebc4a132346ee4 (patch)
treea12e2e8da6222de12e9ac5ca95a58b0b3fe1d191 /src/com/android/launcher3/LauncherModel.java
parente8db3f023d29e1b44399205feb79c3ea421580bd (diff)
parent756a28aeece3b00f40415f1fccae6f7d57104bfb (diff)
downloadandroid_packages_apps_Trebuchet-deb189fd105a5367d965538fd2ebc4a132346ee4.tar.gz
android_packages_apps_Trebuchet-deb189fd105a5367d965538fd2ebc4a132346ee4.tar.bz2
android_packages_apps_Trebuchet-deb189fd105a5367d965538fd2ebc4a132346ee4.zip
Merge "Adding workprofile shortcuts after the loader has completed" into ub-launcher3-burnaby
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r--src/com/android/launcher3/LauncherModel.java61
1 files changed, 51 insertions, 10 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 95ff6a49b..0138a913a 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -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";
@@ -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 >
@@ -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() ;
}
@@ -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,
@@ -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) {
@@ -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) {
@@ -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() {
@@ -1615,6 +1651,7 @@ public class LauncherModel extends BroadcastReceiver
mLoaderTask = null;
}
mIsLoaderTaskRunning = false;
+ mHasLoaderCompletedOnce = true;
}
}
@@ -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);
@@ -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);
- if (heuristic != null) {
- heuristic.processUserApps(apps);
- }
+ 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?