summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherModel.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-08-10 16:09:29 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-08-10 17:00:15 -0700
commit95f3d6ba2ca02a9841487777cfff43fb9df65ec7 (patch)
tree520e94b5d4720cdfe16552a0e1c9baaf9f2f8ca6 /src/com/android/launcher3/LauncherModel.java
parentea5bcba847a5740b29485ea40d2419841c8cd62c (diff)
downloadandroid_packages_apps_Trebuchet-95f3d6ba2ca02a9841487777cfff43fb9df65ec7.tar.gz
android_packages_apps_Trebuchet-95f3d6ba2ca02a9841487777cfff43fb9df65ec7.tar.bz2
android_packages_apps_Trebuchet-95f3d6ba2ca02a9841487777cfff43fb9df65ec7.zip
Reloading workspace when the shortcuts permission changes
> Check for permission on every onResume > If the permission is different than last known permission, reload and rebind workspace. Bug: 30789422 Change-Id: Idfa445815e29e2336505779545507d106b33a253
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r--src/com/android/launcher3/LauncherModel.java41
1 files changed, 36 insertions, 5 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 34660ac15..6a63110b1 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -146,6 +146,20 @@ public class LauncherModel extends BroadcastReceiver
// Maps all launcher activities to the id's of their shortcuts (if they have any).
private final MultiHashMap<ComponentKey, String> mBgDeepShortcutMap = new MultiHashMap<>();
+ private boolean mHasShortcutHostPermission;
+ // Runnable to check if the shortcuts permission has changed.
+ private final Runnable mShortcutPermissionCheckRunnable = new Runnable() {
+ @Override
+ public void run() {
+ if (mDeepShortcutsLoaded) {
+ boolean hasShortcutHostPermission = mDeepShortcutManager.hasHostPermission();
+ if (hasShortcutHostPermission != mHasShortcutHostPermission) {
+ mApp.reloadWorkspace();
+ }
+ }
+ }
+ };
+
// The lock that must be acquired before referencing any static bg data structures. Unlike
// other locks, this one can generally be held long-term because we never expect any of these
// static data structures to be referenced outside of the worker thread except on the first
@@ -1244,6 +1258,7 @@ public class LauncherModel extends BroadcastReceiver
if (resetAllAppsLoaded) mAllAppsLoaded = false;
if (resetWorkspaceLoaded) mWorkspaceLoaded = false;
// Always reset deep shortcuts loaded.
+ // TODO: why?
mDeepShortcutsLoaded = false;
}
}
@@ -1299,6 +1314,7 @@ public class LauncherModel extends BroadcastReceiver
// If there is already one running, tell it to stop.
stopLoaderLocked();
mLoaderTask = new LoaderTask(mApp.getContext(), synchronousBindPage);
+ // TODO: mDeepShortcutsLoaded does not need to be true for synchronous bind.
if (synchronousBindPage != PagedView.INVALID_RESTORE_PAGE && mAllAppsLoaded
&& mWorkspaceLoaded && mDeepShortcutsLoaded && !mIsLoaderTaskRunning) {
mLoaderTask.runBindSynchronousPage(synchronousBindPage);
@@ -2793,11 +2809,14 @@ public class LauncherModel extends BroadcastReceiver
}
if (!mDeepShortcutsLoaded) {
mBgDeepShortcutMap.clear();
- for (UserHandleCompat user : mUserManager.getUserProfiles()) {
- if (mUserManager.isUserUnlocked(user)) {
- List<ShortcutInfoCompat> shortcuts = mDeepShortcutManager
- .queryForAllShortcuts(user);
- updateDeepShortcutMap(null, user, shortcuts);
+ mHasShortcutHostPermission = mDeepShortcutManager.hasHostPermission();
+ if (mHasShortcutHostPermission) {
+ for (UserHandleCompat user : mUserManager.getUserProfiles()) {
+ if (mUserManager.isUserUnlocked(user)) {
+ List<ShortcutInfoCompat> shortcuts = mDeepShortcutManager
+ .queryForAllShortcuts(user);
+ updateDeepShortcutMap(null, user, shortcuts);
+ }
}
}
synchronized (LoaderTask.this) {
@@ -2863,6 +2882,18 @@ public class LauncherModel extends BroadcastReceiver
}
/**
+ * Refreshes the cached shortcuts if the shortcut permission has changed.
+ * Current implementation simply reloads the workspace, but it can be optimized to
+ * use partial updates similar to {@link UserManagerCompat}
+ */
+ public void refreshShortcutsIfRequired() {
+ if (Utilities.isNycMR1OrAbove()) {
+ sWorker.removeCallbacks(mShortcutPermissionCheckRunnable);
+ sWorker.post(mShortcutPermissionCheckRunnable);
+ }
+ }
+
+ /**
* Called when the icons for packages have been updated in the icon cache.
*/
public void onPackageIconsUpdated(HashSet<String> updatedPackages, UserHandleCompat user) {