diff options
Diffstat (limited to 'com/android/server/pm/ShortcutService.java')
-rw-r--r-- | com/android/server/pm/ShortcutService.java | 153 |
1 files changed, 42 insertions, 111 deletions
diff --git a/com/android/server/pm/ShortcutService.java b/com/android/server/pm/ShortcutService.java index 1c002aa4..27560c5f 100644 --- a/com/android/server/pm/ShortcutService.java +++ b/com/android/server/pm/ShortcutService.java @@ -553,9 +553,6 @@ public class ShortcutService extends IShortcutService.Stub { public Lifecycle(Context context) { super(context); - if (DEBUG) { - Binder.LOG_RUNTIME_EXCEPTION = true; - } mService = new ShortcutService(context); } @@ -741,10 +738,6 @@ public class ShortcutService extends IShortcutService.Stub { return parseLongAttribute(parser, attribute) == 1; } - static boolean parseBooleanAttribute(XmlPullParser parser, String attribute, boolean def) { - return parseLongAttribute(parser, attribute, (def ? 1 : 0)) == 1; - } - static int parseIntAttribute(XmlPullParser parser, String attribute) { return (int) parseLongAttribute(parser, attribute); } @@ -842,8 +835,6 @@ public class ShortcutService extends IShortcutService.Stub { static void writeAttr(XmlSerializer out, String name, boolean value) throws IOException { if (value) { writeAttr(out, name, "1"); - } else { - writeAttr(out, name, "0"); } } @@ -1698,7 +1689,7 @@ public class ShortcutService extends IShortcutService.Stub { final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId); - ps.ensureImmutableShortcutsNotIncluded(newShortcuts, /*ignoreInvisible=*/ true); + ps.ensureImmutableShortcutsNotIncluded(newShortcuts); fillInDefaultActivity(newShortcuts); @@ -1718,12 +1709,12 @@ public class ShortcutService extends IShortcutService.Stub { } // First, remove all un-pinned; dynamic shortcuts - ps.deleteAllDynamicShortcuts(/*ignoreInvisible=*/ true); + ps.deleteAllDynamicShortcuts(); // Then, add/update all. We need to make sure to take over "pinned" flag. for (int i = 0; i < size; i++) { final ShortcutInfo newShortcut = newShortcuts.get(i); - ps.addOrReplaceDynamicShortcut(newShortcut); + ps.addOrUpdateDynamicShortcut(newShortcut); } // Lastly, adjust the ranks. @@ -1749,7 +1740,7 @@ public class ShortcutService extends IShortcutService.Stub { final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId); - ps.ensureImmutableShortcutsNotIncluded(newShortcuts, /*ignoreInvisible=*/ true); + ps.ensureImmutableShortcutsNotIncluded(newShortcuts); // For update, don't fill in the default activity. Having null activity means // "don't update the activity" here. @@ -1770,9 +1761,7 @@ public class ShortcutService extends IShortcutService.Stub { fixUpIncomingShortcutInfo(source, /* forUpdate= */ true); final ShortcutInfo target = ps.findShortcutById(source.getId()); - - // Invisible shortcuts can't be updated. - if (target == null || !target.isVisibleToPublisher()) { + if (target == null) { continue; } @@ -1819,7 +1808,7 @@ public class ShortcutService extends IShortcutService.Stub { } @Override - public boolean addDynamicShortcuts(String packageName, ParceledListSlice shortcutInfoList, + public boolean addDynamicShortcuts(String packageName, ParceledListSlice shortcutInfoList, @UserIdInt int userId) { verifyCaller(packageName, userId); @@ -1831,7 +1820,7 @@ public class ShortcutService extends IShortcutService.Stub { final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId); - ps.ensureImmutableShortcutsNotIncluded(newShortcuts, /*ignoreInvisible=*/ true); + ps.ensureImmutableShortcutsNotIncluded(newShortcuts); fillInDefaultActivity(newShortcuts); @@ -1856,7 +1845,7 @@ public class ShortcutService extends IShortcutService.Stub { newShortcut.setRankChanged(); // Add it. - ps.addOrReplaceDynamicShortcut(newShortcut); + ps.addOrUpdateDynamicShortcut(newShortcut); } // Lastly, adjust the ranks. @@ -1912,22 +1901,6 @@ public class ShortcutService extends IShortcutService.Stub { Preconditions.checkState(isUidForegroundLocked(injectBinderCallingUid()), "Calling application must have a foreground activity or a foreground service"); - // If it's a pin shortcut request, and there's already a shortcut with the same ID - // that's not visible to the caller (i.e. restore-blocked; meaning it's pinned by - // someone already), then we just replace the existing one with this new one, - // and then proceed the rest of the process. - if (shortcut != null) { - final ShortcutPackage ps = getPackageShortcutsForPublisherLocked( - packageName, userId); - final String id = shortcut.getId(); - if (ps.isShortcutExistsAndInvisibleToPublisher(id)) { - - ps.updateInvisibleShortcutForPinRequestWith(shortcut); - - packageShortcutsChanged(packageName, userId); - } - } - // Send request to the launcher, if supported. ret = mShortcutRequestPinProcessor.requestPinItemLocked(shortcut, appWidget, extras, userId, resultIntent); @@ -1949,21 +1922,15 @@ public class ShortcutService extends IShortcutService.Stub { final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId); - ps.ensureImmutableShortcutsNotIncludedWithIds((List<String>) shortcutIds, - /*ignoreInvisible=*/ true); + ps.ensureImmutableShortcutsNotIncludedWithIds((List<String>) shortcutIds); final String disabledMessageString = (disabledMessage == null) ? null : disabledMessage.toString(); for (int i = shortcutIds.size() - 1; i >= 0; i--) { - final String id = Preconditions.checkStringNotEmpty((String) shortcutIds.get(i)); - if (!ps.isShortcutExistsAndVisibleToPublisher(id)) { - continue; - } - ps.disableWithId(id, + ps.disableWithId(Preconditions.checkStringNotEmpty((String) shortcutIds.get(i)), disabledMessageString, disabledMessageResId, - /* overrideImmutable=*/ false, /*ignoreInvisible=*/ true, - ShortcutInfo.DISABLED_REASON_BY_APP); + /* overrideImmutable=*/ false); } // We may have removed dynamic shortcuts which may have left a gap, so adjust the ranks. @@ -1984,15 +1951,10 @@ public class ShortcutService extends IShortcutService.Stub { final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId); - ps.ensureImmutableShortcutsNotIncludedWithIds((List<String>) shortcutIds, - /*ignoreInvisible=*/ true); + ps.ensureImmutableShortcutsNotIncludedWithIds((List<String>) shortcutIds); for (int i = shortcutIds.size() - 1; i >= 0; i--) { - final String id = Preconditions.checkStringNotEmpty((String) shortcutIds.get(i)); - if (!ps.isShortcutExistsAndVisibleToPublisher(id)) { - continue; - } - ps.enableWithId(id); + ps.enableWithId((String) shortcutIds.get(i)); } } packageShortcutsChanged(packageName, userId); @@ -2011,15 +1973,11 @@ public class ShortcutService extends IShortcutService.Stub { final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId); - ps.ensureImmutableShortcutsNotIncludedWithIds((List<String>) shortcutIds, - /*ignoreInvisible=*/ true); + ps.ensureImmutableShortcutsNotIncludedWithIds((List<String>) shortcutIds); for (int i = shortcutIds.size() - 1; i >= 0; i--) { - final String id = Preconditions.checkStringNotEmpty((String) shortcutIds.get(i)); - if (!ps.isShortcutExistsAndVisibleToPublisher(id)) { - continue; - } - ps.deleteDynamicWithId(id, /*ignoreInvisible=*/ true); + ps.deleteDynamicWithId( + Preconditions.checkStringNotEmpty((String) shortcutIds.get(i))); } // We may have removed dynamic shortcuts which may have left a gap, so adjust the ranks. @@ -2038,7 +1996,7 @@ public class ShortcutService extends IShortcutService.Stub { throwIfUserLockedL(userId); final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId); - ps.deleteAllDynamicShortcuts(/*ignoreInvisible=*/ true); + ps.deleteAllDynamicShortcuts(); } packageShortcutsChanged(packageName, userId); @@ -2055,7 +2013,7 @@ public class ShortcutService extends IShortcutService.Stub { return getShortcutsWithQueryLocked( packageName, userId, ShortcutInfo.CLONE_REMOVE_FOR_CREATOR, - ShortcutInfo::isDynamicVisible); + ShortcutInfo::isDynamic); } } @@ -2069,7 +2027,7 @@ public class ShortcutService extends IShortcutService.Stub { return getShortcutsWithQueryLocked( packageName, userId, ShortcutInfo.CLONE_REMOVE_FOR_CREATOR, - ShortcutInfo::isManifestVisible); + ShortcutInfo::isManifestShortcut); } } @@ -2083,7 +2041,7 @@ public class ShortcutService extends IShortcutService.Stub { return getShortcutsWithQueryLocked( packageName, userId, ShortcutInfo.CLONE_REMOVE_FOR_CREATOR, - ShortcutInfo::isPinnedVisible); + ShortcutInfo::isPinned); } } @@ -2232,11 +2190,7 @@ public class ShortcutService extends IShortcutService.Stub { } // We override this method in unit tests to do a simpler check. - boolean hasShortcutHostPermission(@NonNull String callingPackage, int userId, - int callingPid, int callingUid) { - if (injectCheckAccessShortcutsPermission(callingPid, callingUid)) { - return true; - } + boolean hasShortcutHostPermission(@NonNull String callingPackage, int userId) { final long start = injectElapsedRealtime(); try { return hasShortcutHostPermissionInner(callingPackage, userId); @@ -2245,14 +2199,6 @@ public class ShortcutService extends IShortcutService.Stub { } } - /** - * Returns true if the caller has the "ACCESS_SHORTCUTS" permission. - */ - boolean injectCheckAccessShortcutsPermission(int callingPid, int callingUid) { - return mContext.checkPermission(android.Manifest.permission.ACCESS_SHORTCUTS, - callingPid, callingUid) == PackageManager.PERMISSION_GRANTED; - } - // This method is extracted so we can directly call this method from unit tests, // even when hasShortcutPermission() is overridden. @VisibleForTesting @@ -2433,7 +2379,7 @@ public class ShortcutService extends IShortcutService.Stub { @NonNull String callingPackage, long changedSince, @Nullable String packageName, @Nullable List<String> shortcutIds, @Nullable ComponentName componentName, - int queryFlags, int userId, int callingPid, int callingUid) { + int queryFlags, int userId) { final ArrayList<ShortcutInfo> ret = new ArrayList<>(); final boolean cloneKeyFieldOnly = @@ -2454,15 +2400,13 @@ public class ShortcutService extends IShortcutService.Stub { if (packageName != null) { getShortcutsInnerLocked(launcherUserId, callingPackage, packageName, shortcutIds, changedSince, - componentName, queryFlags, userId, ret, cloneFlag, - callingPid, callingUid); + componentName, queryFlags, userId, ret, cloneFlag); } else { final List<String> shortcutIdsF = shortcutIds; getUserShortcutsLocked(userId).forAllPackages(p -> { getShortcutsInnerLocked(launcherUserId, callingPackage, p.getPackageName(), shortcutIdsF, changedSince, - componentName, queryFlags, userId, ret, cloneFlag, - callingPid, callingUid); + componentName, queryFlags, userId, ret, cloneFlag); }); } } @@ -2472,8 +2416,7 @@ public class ShortcutService extends IShortcutService.Stub { private void getShortcutsInnerLocked(int launcherUserId, @NonNull String callingPackage, @Nullable String packageName, @Nullable List<String> shortcutIds, long changedSince, @Nullable ComponentName componentName, int queryFlags, - int userId, ArrayList<ShortcutInfo> ret, int cloneFlag, - int callingPid, int callingUid) { + int userId, ArrayList<ShortcutInfo> ret, int cloneFlag) { final ArraySet<String> ids = shortcutIds == null ? null : new ArraySet<>(shortcutIds); @@ -2482,13 +2425,6 @@ public class ShortcutService extends IShortcutService.Stub { if (p == null) { return; // No need to instantiate ShortcutPackage. } - final boolean matchDynamic = (queryFlags & ShortcutQuery.FLAG_MATCH_DYNAMIC) != 0; - final boolean matchPinned = (queryFlags & ShortcutQuery.FLAG_MATCH_PINNED) != 0; - final boolean matchManifest = (queryFlags & ShortcutQuery.FLAG_MATCH_MANIFEST) != 0; - - final boolean getPinnedByAnyLauncher = - ((queryFlags & ShortcutQuery.FLAG_MATCH_ALL_PINNED) != 0) - && injectCheckAccessShortcutsPermission(callingPid, callingUid); p.findAll(ret, (ShortcutInfo si) -> { @@ -2504,17 +2440,20 @@ public class ShortcutService extends IShortcutService.Stub { return false; } } - if (matchDynamic && si.isDynamic()) { + if (((queryFlags & ShortcutQuery.FLAG_GET_DYNAMIC) != 0) + && si.isDynamic()) { return true; } - if ((matchPinned && si.isPinned()) || getPinnedByAnyLauncher) { + if (((queryFlags & ShortcutQuery.FLAG_GET_PINNED) != 0) + && si.isPinned()) { return true; } - if (matchManifest && si.isDeclaredInManifest()) { + if (((queryFlags & ShortcutQuery.FLAG_GET_MANIFEST) != 0) + && si.isManifestShortcut()) { return true; } return false; - }, cloneFlag, callingPackage, launcherUserId, getPinnedByAnyLauncher); + }, cloneFlag, callingPackage, launcherUserId); } @Override @@ -2531,16 +2470,14 @@ public class ShortcutService extends IShortcutService.Stub { .attemptToRestoreIfNeededAndSave(); final ShortcutInfo si = getShortcutInfoLocked( - launcherUserId, callingPackage, packageName, shortcutId, userId, - /*getPinnedByAnyLauncher=*/ false); + launcherUserId, callingPackage, packageName, shortcutId, userId); return si != null && si.isPinned(); } } private ShortcutInfo getShortcutInfoLocked( int launcherUserId, @NonNull String callingPackage, - @NonNull String packageName, @NonNull String shortcutId, int userId, - boolean getPinnedByAnyLauncher) { + @NonNull String packageName, @NonNull String shortcutId, int userId) { Preconditions.checkStringNotEmpty(packageName, "packageName"); Preconditions.checkStringNotEmpty(shortcutId, "shortcutId"); @@ -2556,7 +2493,7 @@ public class ShortcutService extends IShortcutService.Stub { final ArrayList<ShortcutInfo> list = new ArrayList<>(1); p.findAll(list, (ShortcutInfo si) -> shortcutId.equals(si.getId()), - /* clone flags=*/ 0, callingPackage, launcherUserId, getPinnedByAnyLauncher); + /* clone flags=*/ 0, callingPackage, launcherUserId); return list.size() == 0 ? null : list.get(0); } @@ -2576,7 +2513,7 @@ public class ShortcutService extends IShortcutService.Stub { getLauncherShortcutsLocked(callingPackage, userId, launcherUserId); launcher.attemptToRestoreIfNeededAndSave(); - launcher.pinShortcuts(userId, packageName, shortcutIds, /*forPinRequest=*/ false); + launcher.pinShortcuts(userId, packageName, shortcutIds); } packageShortcutsChanged(packageName, userId); @@ -2586,8 +2523,7 @@ public class ShortcutService extends IShortcutService.Stub { @Override public Intent[] createShortcutIntents(int launcherUserId, @NonNull String callingPackage, - @NonNull String packageName, @NonNull String shortcutId, int userId, - int callingPid, int callingUid) { + @NonNull String packageName, @NonNull String shortcutId, int userId) { // Calling permission must be checked by LauncherAppsImpl. Preconditions.checkStringNotEmpty(packageName, "packageName can't be empty"); Preconditions.checkStringNotEmpty(shortcutId, "shortcutId can't be empty"); @@ -2599,13 +2535,9 @@ public class ShortcutService extends IShortcutService.Stub { getLauncherShortcutsLocked(callingPackage, userId, launcherUserId) .attemptToRestoreIfNeededAndSave(); - final boolean getPinnedByAnyLauncher = - injectCheckAccessShortcutsPermission(callingPid, callingUid); - // Make sure the shortcut is actually visible to the launcher. final ShortcutInfo si = getShortcutInfoLocked( - launcherUserId, callingPackage, packageName, shortcutId, userId, - getPinnedByAnyLauncher); + launcherUserId, callingPackage, packageName, shortcutId, userId); // "si == null" should suffice here, but check the flags too just to make sure. if (si == null || !si.isEnabled() || !si.isAlive()) { Log.e(TAG, "Shortcut " + shortcutId + " does not exist or disabled"); @@ -2691,9 +2623,8 @@ public class ShortcutService extends IShortcutService.Stub { @Override public boolean hasShortcutHostPermission(int launcherUserId, - @NonNull String callingPackage, int callingPid, int callingUid) { - return ShortcutService.this.hasShortcutHostPermission(callingPackage, launcherUserId, - callingPid, callingUid); + @NonNull String callingPackage) { + return ShortcutService.this.hasShortcutHostPermission(callingPackage, launcherUserId); } @Override @@ -3412,7 +3343,7 @@ public class ShortcutService extends IShortcutService.Stub { return isApplicationFlagSet(packageName, userId, ApplicationInfo.FLAG_ALLOW_BACKUP); } - static boolean shouldBackupApp(PackageInfo pi) { + boolean shouldBackupApp(PackageInfo pi) { return (pi.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0; } @@ -3440,7 +3371,7 @@ public class ShortcutService extends IShortcutService.Stub { // Set the version code for the launchers. // We shouldn't do this for publisher packages, because we don't want to update the // version code without rescanning the manifest. - user.forAllLaunchers(launcher -> launcher.ensurePackageInfo()); + user.forAllLaunchers(launcher -> launcher.ensureVersionInfo()); // Save to the filesystem. scheduleSaveUser(userId); |