diff options
Diffstat (limited to 'com/android/server/pm/ShortcutLauncher.java')
-rw-r--r-- | com/android/server/pm/ShortcutLauncher.java | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/com/android/server/pm/ShortcutLauncher.java b/com/android/server/pm/ShortcutLauncher.java index f922ad19..cedf4763 100644 --- a/com/android/server/pm/ShortcutLauncher.java +++ b/com/android/server/pm/ShortcutLauncher.java @@ -83,11 +83,16 @@ class ShortcutLauncher extends ShortcutPackageItem { return mOwnerUserId; } + @Override + protected boolean canRestoreAnyVersion() { + // Launcher's pinned shortcuts can be restored to an older version. + return true; + } + /** * Called when the new package can't receive the backup, due to signature or version mismatch. */ - @Override - protected void onRestoreBlocked() { + private void onRestoreBlocked() { final ArrayList<PackageWithUser> pinnedPackages = new ArrayList<>(mPinnedShortcuts.keySet()); mPinnedShortcuts.clear(); @@ -101,15 +106,21 @@ class ShortcutLauncher extends ShortcutPackageItem { } @Override - protected void onRestored() { - // Nothing to do. + protected void onRestored(int restoreBlockReason) { + // For launcher, possible reasons here are DISABLED_REASON_SIGNATURE_MISMATCH or + // DISABLED_REASON_BACKUP_NOT_SUPPORTED. + // DISABLED_REASON_VERSION_LOWER will NOT happen because we don't check version + // code for launchers. + if (restoreBlockReason != ShortcutInfo.DISABLED_REASON_NOT_DISABLED) { + onRestoreBlocked(); + } } /** * Pin the given shortcuts, replacing the current pinned ones. */ public void pinShortcuts(@UserIdInt int packageUserId, - @NonNull String packageName, @NonNull List<String> ids) { + @NonNull String packageName, @NonNull List<String> ids, boolean forPinRequest) { final ShortcutPackage packageShortcuts = mShortcutUser.getPackageShortcutsIfExists(packageName); if (packageShortcuts == null) { @@ -124,8 +135,12 @@ class ShortcutLauncher extends ShortcutPackageItem { } else { final ArraySet<String> prevSet = mPinnedShortcuts.get(pu); - // Pin shortcuts. Make sure only pin the ones that were visible to the caller. - // i.e. a non-dynamic, pinned shortcut by *other launchers* shouldn't be pinned here. + // Actually pin shortcuts. + // This logic here is to make sure a launcher cannot pin a shortcut that is floating + // (i.e. not dynamic nor manifest but is pinned) and pinned by another launcher. + // In this case, technically the shortcut doesn't exist to this launcher, so it can't + // pin it. + // (Maybe unnecessarily strict...) final ArraySet<String> newSet = new ArraySet<>(); @@ -135,8 +150,10 @@ class ShortcutLauncher extends ShortcutPackageItem { if (si == null) { continue; } - if (si.isDynamic() || si.isManifestShortcut() - || (prevSet != null && prevSet.contains(id))) { + if (si.isDynamic() + || si.isManifestShortcut() + || (prevSet != null && prevSet.contains(id)) + || forPinRequest) { newSet.add(id); } } @@ -155,7 +172,7 @@ class ShortcutLauncher extends ShortcutPackageItem { } /** - * Return true if the given shortcut is pinned by this launcher. + * Return true if the given shortcut is pinned by this launcher.<code></code> */ public boolean hasPinned(ShortcutInfo shortcut) { final ArraySet<String> pinned = @@ -164,10 +181,10 @@ class ShortcutLauncher extends ShortcutPackageItem { } /** - * Additionally pin a shortcut. c.f. {@link #pinShortcuts(int, String, List)} + * Additionally pin a shortcut. c.f. {@link #pinShortcuts(int, String, List, boolean)} */ public void addPinnedShortcut(@NonNull String packageName, @UserIdInt int packageUserId, - String id) { + String id, boolean forPinRequest) { final ArraySet<String> pinnedSet = getPinnedShortcutIds(packageName, packageUserId); final ArrayList<String> pinnedList; if (pinnedSet != null) { @@ -178,21 +195,21 @@ class ShortcutLauncher extends ShortcutPackageItem { } pinnedList.add(id); - pinShortcuts(packageUserId, packageName, pinnedList); + pinShortcuts(packageUserId, packageName, pinnedList, forPinRequest); } boolean cleanUpPackage(String packageName, @UserIdInt int packageUserId) { return mPinnedShortcuts.remove(PackageWithUser.of(packageUserId, packageName)) != null; } - public void ensureVersionInfo() { + public void ensurePackageInfo() { final PackageInfo pi = mShortcutUser.mService.getPackageInfoWithSignatures( getPackageName(), getPackageUserId()); if (pi == null) { Slog.w(TAG, "Package not found: " + getPackageName()); return; } - getPackageInfo().updateVersionInfo(pi); + getPackageInfo().updateFromPackageInfo(pi); } /** @@ -201,6 +218,10 @@ class ShortcutLauncher extends ShortcutPackageItem { @Override public void saveToXml(XmlSerializer out, boolean forBackup) throws IOException { + if (forBackup && !getPackageInfo().isBackupAllowed()) { + // If an launcher app doesn't support backup&restore, then nothing to do. + return; + } final int size = mPinnedShortcuts.size(); if (size == 0) { return; // Nothing to write. @@ -209,7 +230,7 @@ class ShortcutLauncher extends ShortcutPackageItem { out.startTag(null, TAG_ROOT); ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, getPackageName()); ShortcutService.writeAttr(out, ATTR_LAUNCHER_USER_ID, getPackageUserId()); - getPackageInfo().saveToXml(out); + getPackageInfo().saveToXml(out, forBackup); for (int i = 0; i < size; i++) { final PackageWithUser pu = mPinnedShortcuts.keyAt(i); |