summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehdi Alizadeh <mett@google.com>2020-04-27 18:52:52 -0700
committerMehdi Alizadeh <mett@google.com>2020-05-26 03:30:55 +0000
commita3d22cec32a0578c07fdddac0f746865fef30c1f (patch)
tree08417a0cd869458ed0d4333019a491c6c4a4be6e
parent2cdbcea8ba29bbb8d50511a9fa6e5bd2763fb153 (diff)
Adds cacheFlags parameter to cache/uncacheShortcuts() methods
Bug: 155135890 Test: atest ShortcutManagerTest1 ShortcutManagerTest11 \ ConversationInfoTest DataManagerTest \ NotificationManagerServiceTest Change-Id: Idda777ba032546bd616ee3079b9c8dc8676dc589
-rw-r--r--core/java/android/content/pm/ILauncherApps.aidl4
-rw-r--r--core/java/android/content/pm/LauncherApps.java40
-rw-r--r--core/java/android/content/pm/ShortcutInfo.java30
-rw-r--r--core/java/android/content/pm/ShortcutServiceInternal.java4
-rw-r--r--services/core/java/com/android/server/notification/ShortcutHelper.java2
-rw-r--r--services/core/java/com/android/server/pm/LauncherAppsService.java31
-rw-r--r--services/core/java/com/android/server/pm/ShortcutPackage.java48
-rw-r--r--services/core/java/com/android/server/pm/ShortcutService.java23
-rw-r--r--services/people/java/com/android/server/people/data/ConversationInfo.java11
-rw-r--r--services/people/java/com/android/server/people/data/DataManager.java12
-rw-r--r--services/tests/servicestests/src/com/android/server/people/data/ConversationInfoTest.java7
-rw-r--r--services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java32
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java41
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest11.java79
-rwxr-xr-xservices/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java4
15 files changed, 244 insertions, 124 deletions
diff --git a/core/java/android/content/pm/ILauncherApps.aidl b/core/java/android/content/pm/ILauncherApps.aidl
index aa290404c001..389458b64fc1 100644
--- a/core/java/android/content/pm/ILauncherApps.aidl
+++ b/core/java/android/content/pm/ILauncherApps.aidl
@@ -99,9 +99,9 @@ interface ILauncherApps {
in IShortcutChangeCallback callback);
void cacheShortcuts(String callingPackage, String packageName, in List<String> shortcutIds,
- in UserHandle user);
+ in UserHandle user, int cacheFlags);
void uncacheShortcuts(String callingPackage, String packageName, in List<String> shortcutIds,
- in UserHandle user);
+ in UserHandle user, int cacheFlags);
String getShortcutIconUri(String callingPackage, String packageName, String shortcutId,
int userId);
diff --git a/core/java/android/content/pm/LauncherApps.java b/core/java/android/content/pm/LauncherApps.java
index 4299e805264c..bd1ee27ece9e 100644
--- a/core/java/android/content/pm/LauncherApps.java
+++ b/core/java/android/content/pm/LauncherApps.java
@@ -155,6 +155,26 @@ public class LauncherApps {
public static final String EXTRA_PIN_ITEM_REQUEST =
"android.content.pm.extra.PIN_ITEM_REQUEST";
+ /**
+ * Cache shortcuts which are used in notifications.
+ * @hide
+ */
+ public static final int FLAG_CACHE_NOTIFICATION_SHORTCUTS = 0;
+
+ /**
+ * Cache shortcuts which are used in bubbles.
+ * @hide
+ */
+ public static final int FLAG_CACHE_BUBBLE_SHORTCUTS = 1;
+
+ /** @hide */
+ @IntDef(flag = false, prefix = { "FLAG_CACHE_" }, value = {
+ FLAG_CACHE_NOTIFICATION_SHORTCUTS,
+ FLAG_CACHE_BUBBLE_SHORTCUTS,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface ShortcutCacheFlags {}
+
private final Context mContext;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
private final ILauncherApps mService;
@@ -1109,6 +1129,11 @@ public class LauncherApps {
* @param packageName The target package name.
* @param shortcutIds The IDs of the shortcut to be cached.
* @param user The UserHandle of the profile.
+ * @param cacheFlags One of the values in:
+ * <ul>
+ * <li>{@link #FLAG_CACHE_NOTIFICATION_SHORTCUTS}
+ * <li>{@link #FLAG_CACHE_BUBBLE_SHORTCUTS}
+ * </ul>
* @throws IllegalStateException when the user is locked, or when the {@code user} user
* is locked or not running.
*
@@ -1118,10 +1143,11 @@ public class LauncherApps {
*/
@RequiresPermission(android.Manifest.permission.ACCESS_SHORTCUTS)
public void cacheShortcuts(@NonNull String packageName, @NonNull List<String> shortcutIds,
- @NonNull UserHandle user) {
+ @NonNull UserHandle user, @ShortcutCacheFlags int cacheFlags) {
logErrorForInvalidProfileAccess(user);
try {
- mService.cacheShortcuts(mContext.getPackageName(), packageName, shortcutIds, user);
+ mService.cacheShortcuts(
+ mContext.getPackageName(), packageName, shortcutIds, user, cacheFlags);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -1133,6 +1159,11 @@ public class LauncherApps {
* @param packageName The target package name.
* @param shortcutIds The IDs of the shortcut to be uncached.
* @param user The UserHandle of the profile.
+ * @param cacheFlags One of the values in:
+ * <ul>
+ * <li>{@link #FLAG_CACHE_NOTIFICATION_SHORTCUTS}
+ * <li>{@link #FLAG_CACHE_BUBBLE_SHORTCUTS}
+ * </ul>
* @throws IllegalStateException when the user is locked, or when the {@code user} user
* is locked or not running.
*
@@ -1142,10 +1173,11 @@ public class LauncherApps {
*/
@RequiresPermission(android.Manifest.permission.ACCESS_SHORTCUTS)
public void uncacheShortcuts(@NonNull String packageName, @NonNull List<String> shortcutIds,
- @NonNull UserHandle user) {
+ @NonNull UserHandle user, @ShortcutCacheFlags int cacheFlags) {
logErrorForInvalidProfileAccess(user);
try {
- mService.uncacheShortcuts(mContext.getPackageName(), packageName, shortcutIds, user);
+ mService.uncacheShortcuts(
+ mContext.getPackageName(), packageName, shortcutIds, user, cacheFlags);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/content/pm/ShortcutInfo.java b/core/java/android/content/pm/ShortcutInfo.java
index dcc6cb25c95b..1b3c46f90851 100644
--- a/core/java/android/content/pm/ShortcutInfo.java
+++ b/core/java/android/content/pm/ShortcutInfo.java
@@ -119,12 +119,27 @@ public final class ShortcutInfo implements Parcelable {
/** @hide */
public static final int FLAG_LONG_LIVED = 1 << 13;
- /** @hide */
- public static final int FLAG_CACHED = 1 << 14;
+ /**
+ * TODO(b/155135057): This is a quick and temporary fix for b/155135890. ShortcutService doesn't
+ * need to be aware of the outside world. Replace this with a more extensible solution.
+ * @hide
+ */
+ public static final int FLAG_CACHED_NOTIFICATIONS = 1 << 14;
/** @hide */
public static final int FLAG_HAS_ICON_URI = 1 << 15;
+
+ /**
+ * TODO(b/155135057): This is a quick and temporary fix for b/155135890. ShortcutService doesn't
+ * need to be aware of the outside world. Replace this with a more extensible solution.
+ * @hide
+ */
+ public static final int FLAG_CACHED_BUBBLES = 1 << 30;
+
+ /** @hide */
+ public static final int FLAG_CACHED_ALL = FLAG_CACHED_NOTIFICATIONS | FLAG_CACHED_BUBBLES;
+
/** @hide */
@IntDef(flag = true, prefix = { "FLAG_" }, value = {
FLAG_DYNAMIC,
@@ -141,8 +156,9 @@ public final class ShortcutInfo implements Parcelable {
FLAG_ICON_FILE_PENDING_SAVE,
FLAG_SHADOW,
FLAG_LONG_LIVED,
- FLAG_CACHED,
FLAG_HAS_ICON_URI,
+ FLAG_CACHED_NOTIFICATIONS,
+ FLAG_CACHED_BUBBLES,
})
@Retention(RetentionPolicy.SOURCE)
public @interface ShortcutFlags {}
@@ -1707,13 +1723,13 @@ public final class ShortcutInfo implements Parcelable {
}
/** @hide */
- public void setCached() {
- addFlags(FLAG_CACHED);
+ public void setCached(@ShortcutFlags int cacheFlag) {
+ addFlags(cacheFlag);
}
/** Return whether a shortcut is cached. */
public boolean isCached() {
- return hasFlags(FLAG_CACHED);
+ return (getFlags() & FLAG_CACHED_ALL) != 0;
}
/** Return whether a shortcut is dynamic. */
@@ -1807,7 +1823,7 @@ public final class ShortcutInfo implements Parcelable {
/** @hide */
public boolean isAlive() {
return hasFlags(FLAG_PINNED) || hasFlags(FLAG_DYNAMIC) || hasFlags(FLAG_MANIFEST)
- || hasFlags(FLAG_CACHED);
+ || isCached();
}
/** @hide */
diff --git a/core/java/android/content/pm/ShortcutServiceInternal.java b/core/java/android/content/pm/ShortcutServiceInternal.java
index eee91ce173dc..c62767ee031b 100644
--- a/core/java/android/content/pm/ShortcutServiceInternal.java
+++ b/core/java/android/content/pm/ShortcutServiceInternal.java
@@ -92,10 +92,10 @@ public abstract class ShortcutServiceInternal {
public abstract void cacheShortcuts(int launcherUserId,
@NonNull String callingPackage, @NonNull String packageName,
- @NonNull List<String> shortcutIds, int userId);
+ @NonNull List<String> shortcutIds, int userId, int cacheFlags);
public abstract void uncacheShortcuts(int launcherUserId,
@NonNull String callingPackage, @NonNull String packageName,
- @NonNull List<String> shortcutIds, int userId);
+ @NonNull List<String> shortcutIds, int userId, int cacheFlags);
/**
* Retrieves all of the direct share targets that match the given IntentFilter for the specified
diff --git a/services/core/java/com/android/server/notification/ShortcutHelper.java b/services/core/java/com/android/server/notification/ShortcutHelper.java
index e79d33fa5f7a..5bbe58274de8 100644
--- a/services/core/java/com/android/server/notification/ShortcutHelper.java
+++ b/services/core/java/com/android/server/notification/ShortcutHelper.java
@@ -198,7 +198,7 @@ public class ShortcutHelper {
if (shortcutInfo.isLongLived() && !shortcutInfo.isCached()) {
mShortcutServiceInternal.cacheShortcuts(user.getIdentifier(), "android",
shortcutInfo.getPackage(), Collections.singletonList(shortcutInfo.getId()),
- shortcutInfo.getUserId());
+ shortcutInfo.getUserId(), ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
}
}
diff --git a/services/core/java/com/android/server/pm/LauncherAppsService.java b/services/core/java/com/android/server/pm/LauncherAppsService.java
index c6d08c36631a..5bbe49088c02 100644
--- a/services/core/java/com/android/server/pm/LauncherAppsService.java
+++ b/services/core/java/com/android/server/pm/LauncherAppsService.java
@@ -18,6 +18,8 @@ package com.android.server.pm;
import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
+import static android.content.pm.LauncherApps.FLAG_CACHE_BUBBLE_SHORTCUTS;
+import static android.content.pm.LauncherApps.FLAG_CACHE_NOTIFICATION_SHORTCUTS;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -78,6 +80,7 @@ import com.android.internal.content.PackageMonitor;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.CollectionUtils;
+import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.pm.parsing.pkg.AndroidPackage;
@@ -780,26 +783,28 @@ public class LauncherAppsService extends SystemService {
@Override
public void cacheShortcuts(String callingPackage, String packageName, List<String> ids,
- UserHandle targetUser) {
+ UserHandle targetUser, int cacheFlags) {
ensureStrictAccessShortcutsPermission(callingPackage);
if (!canAccessProfile(targetUser.getIdentifier(), "Cannot cache shortcuts")) {
return;
}
- mShortcutServiceInternal.cacheShortcuts(getCallingUserId(),
- callingPackage, packageName, ids, targetUser.getIdentifier());
+ mShortcutServiceInternal.cacheShortcuts(
+ getCallingUserId(), callingPackage, packageName, ids,
+ targetUser.getIdentifier(), toShortcutsCacheFlags(cacheFlags));
}
@Override
public void uncacheShortcuts(String callingPackage, String packageName, List<String> ids,
- UserHandle targetUser) {
+ UserHandle targetUser, int cacheFlags) {
ensureStrictAccessShortcutsPermission(callingPackage);
if (!canAccessProfile(targetUser.getIdentifier(), "Cannot uncache shortcuts")) {
return;
}
- mShortcutServiceInternal.uncacheShortcuts(getCallingUserId(),
- callingPackage, packageName, ids, targetUser.getIdentifier());
+ mShortcutServiceInternal.uncacheShortcuts(
+ getCallingUserId(), callingPackage, packageName, ids,
+ targetUser.getIdentifier(), toShortcutsCacheFlags(cacheFlags));
}
@Override
@@ -1058,6 +1063,18 @@ public class LauncherAppsService extends SystemService {
user.getIdentifier(), debugMsg, false);
}
+ private int toShortcutsCacheFlags(int cacheFlags) {
+ int ret = 0;
+ if (cacheFlags == FLAG_CACHE_NOTIFICATION_SHORTCUTS) {
+ ret = ShortcutInfo.FLAG_CACHED_NOTIFICATIONS;
+ } else if (cacheFlags == FLAG_CACHE_BUBBLE_SHORTCUTS) {
+ ret = ShortcutInfo.FLAG_CACHED_BUBBLES;
+ }
+ Preconditions.checkArgumentPositive(ret, "Invalid cache owner");
+
+ return ret;
+ }
+
@VisibleForTesting
void postToPackageMonitorHandler(Runnable r) {
mCallbackHandler.post(r);
@@ -1154,7 +1171,7 @@ public class LauncherAppsService extends SystemService {
final int shortcutFlags = (matchDynamic ? ShortcutInfo.FLAG_DYNAMIC : 0)
| (matchPinned ? ShortcutInfo.FLAG_PINNED : 0)
| (matchManifest ? ShortcutInfo.FLAG_MANIFEST : 0)
- | (matchCached ? ShortcutInfo.FLAG_CACHED : 0);
+ | (matchCached ? ShortcutInfo.FLAG_CACHED_ALL : 0);
for (int i = 0; i < shortcuts.size(); i++) {
final ShortcutInfo si = shortcuts.get(i);
diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java
index 16426072ae78..9e27f65105eb 100644
--- a/services/core/java/com/android/server/pm/ShortcutPackage.java
+++ b/services/core/java/com/android/server/pm/ShortcutPackage.java
@@ -287,7 +287,7 @@ class ShortcutPackage extends ShortcutPackageItem {
if (shortcut != null) {
mShortcutUser.mService.removeIconLocked(shortcut);
shortcut.clearFlags(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_PINNED
- | ShortcutInfo.FLAG_MANIFEST | ShortcutInfo.FLAG_CACHED);
+ | ShortcutInfo.FLAG_MANIFEST | ShortcutInfo.FLAG_CACHED_ALL);
}
return shortcut;
}
@@ -323,36 +323,18 @@ class ShortcutPackage extends ShortcutPackageItem {
newShortcut.addFlags(ShortcutInfo.FLAG_DYNAMIC);
final ShortcutInfo oldShortcut = mShortcuts.get(newShortcut.getId());
-
- final boolean replaced;
-
- final boolean wasPinned;
- final boolean wasCached;
-
- if (oldShortcut == null) {
- replaced = false;
- wasPinned = false;
- wasCached = false;
- } else {
+ if (oldShortcut != null) {
// It's an update case.
// Make sure the target is updatable. (i.e. should be mutable.)
oldShortcut.ensureUpdatableWith(newShortcut, /*isUpdating=*/ false);
- replaced = true;
-
- wasPinned = oldShortcut.isPinned();
- wasCached = oldShortcut.isCached();
- }
- // If it was originally pinned, the new one should be pinned too.
- if (wasPinned) {
- newShortcut.addFlags(ShortcutInfo.FLAG_PINNED);
- }
- if (wasCached) {
- newShortcut.addFlags(ShortcutInfo.FLAG_CACHED);
+ // If it was originally pinned or cached, the new one should be pinned or cached too.
+ newShortcut.addFlags(oldShortcut.getFlags()
+ & (ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_CACHED_ALL));
}
forceReplaceShortcutInner(newShortcut);
- return replaced;
+ return oldShortcut != null;
}
/**
@@ -373,9 +355,6 @@ class ShortcutPackage extends ShortcutPackageItem {
changedShortcuts.clear();
final ShortcutInfo oldShortcut = mShortcuts.get(newShortcut.getId());
- boolean wasPinned = false;
- boolean wasCached = false;
-
boolean deleted = false;
if (oldShortcut == null) {
@@ -408,16 +387,9 @@ class ShortcutPackage extends ShortcutPackageItem {
// Make sure the target is updatable. (i.e. should be mutable.)
oldShortcut.ensureUpdatableWith(newShortcut, /*isUpdating=*/ false);
- wasPinned = oldShortcut.isPinned();
- wasCached = oldShortcut.isCached();
- }
-
- // If it was originally pinned or cached, the new one should be pinned or cached too.
- if (wasPinned) {
- newShortcut.addFlags(ShortcutInfo.FLAG_PINNED);
- }
- if (wasCached) {
- newShortcut.addFlags(ShortcutInfo.FLAG_CACHED);
+ // If it was originally pinned or cached, the new one should be pinned or cached too.
+ newShortcut.addFlags(oldShortcut.getFlags()
+ & (ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_CACHED_ALL));
}
forceReplaceShortcutInner(newShortcut);
@@ -511,7 +483,7 @@ class ShortcutPackage extends ShortcutPackageItem {
public ShortcutInfo deleteLongLivedWithId(@NonNull String shortcutId, boolean ignoreInvisible) {
final ShortcutInfo shortcut = mShortcuts.get(shortcutId);
if (shortcut != null) {
- shortcut.clearFlags(ShortcutInfo.FLAG_CACHED);
+ shortcut.clearFlags(ShortcutInfo.FLAG_CACHED_ALL);
}
return deleteOrDisableWithId(
shortcutId, /* disable =*/ false, /* overrideImmutable=*/ false, ignoreInvisible,
diff --git a/services/core/java/com/android/server/pm/ShortcutService.java b/services/core/java/com/android/server/pm/ShortcutService.java
index 3732b479c3a3..3ec139763e80 100644
--- a/services/core/java/com/android/server/pm/ShortcutService.java
+++ b/services/core/java/com/android/server/pm/ShortcutService.java
@@ -2407,7 +2407,7 @@ public class ShortcutService extends IShortcutService.Stub {
final int shortcutFlags = (matchDynamic ? ShortcutInfo.FLAG_DYNAMIC : 0)
| (matchPinned ? ShortcutInfo.FLAG_PINNED : 0)
| (matchManifest ? ShortcutInfo.FLAG_MANIFEST : 0)
- | (matchCached ? ShortcutInfo.FLAG_CACHED : 0);
+ | (matchCached ? ShortcutInfo.FLAG_CACHED_ALL : 0);
return getShortcutsWithQueryLocked(
packageName, userId, ShortcutInfo.CLONE_REMOVE_FOR_CREATOR,
@@ -3045,17 +3045,17 @@ public class ShortcutService extends IShortcutService.Stub {
@Override
public void cacheShortcuts(int launcherUserId,
@NonNull String callingPackage, @NonNull String packageName,
- @NonNull List<String> shortcutIds, int userId) {
+ @NonNull List<String> shortcutIds, int userId, int cacheFlags) {
updateCachedShortcutsInternal(launcherUserId, callingPackage, packageName, shortcutIds,
- userId, /* doCache= */ true);
+ userId, cacheFlags, /* doCache= */ true);
}
@Override
public void uncacheShortcuts(int launcherUserId,
@NonNull String callingPackage, @NonNull String packageName,
- @NonNull List<String> shortcutIds, int userId) {
+ @NonNull List<String> shortcutIds, int userId, int cacheFlags) {
updateCachedShortcutsInternal(launcherUserId, callingPackage, packageName, shortcutIds,
- userId, /* doCache= */ false);
+ userId, cacheFlags, /* doCache= */ false);
}
@Override
@@ -3079,10 +3079,12 @@ public class ShortcutService extends IShortcutService.Stub {
private void updateCachedShortcutsInternal(int launcherUserId,
@NonNull String callingPackage, @NonNull String packageName,
- @NonNull List<String> shortcutIds, int userId, boolean doCache) {
+ @NonNull List<String> shortcutIds, int userId, int cacheFlags, boolean doCache) {
// Calling permission must be checked by LauncherAppsImpl.
Preconditions.checkStringNotEmpty(packageName, "packageName");
Objects.requireNonNull(shortcutIds, "shortcutIds");
+ Preconditions.checkState(
+ (cacheFlags & ShortcutInfo.FLAG_CACHED_ALL) != 0, "invalid cacheFlags");
List<ShortcutInfo> changedShortcuts = null;
List<ShortcutInfo> removedShortcuts = null;
@@ -3101,13 +3103,13 @@ public class ShortcutService extends IShortcutService.Stub {
for (int i = 0; i < idSize; i++) {
final String id = Preconditions.checkStringNotEmpty(shortcutIds.get(i));
final ShortcutInfo si = sp.findShortcutById(id);
- if (si == null || doCache == si.isCached()) {
+ if (si == null || doCache == si.hasFlags(cacheFlags)) {
continue;
}
if (doCache) {
if (si.isLongLived()) {
- si.addFlags(ShortcutInfo.FLAG_CACHED);
+ si.addFlags(cacheFlags);
if (changedShortcuts == null) {
changedShortcuts = new ArrayList<>(1);
}
@@ -3118,9 +3120,8 @@ public class ShortcutService extends IShortcutService.Stub {
}
} else {
ShortcutInfo removed = null;
- if (si.isDynamic()) {
- si.clearFlags(ShortcutInfo.FLAG_CACHED);
- } else {
+ si.clearFlags(cacheFlags);
+ if (!si.isDynamic() && !si.isCached()) {
removed = sp.deleteLongLivedWithId(id, /*ignoreInvisible=*/ true);
}
if (removed != null) {
diff --git a/services/people/java/com/android/server/people/data/ConversationInfo.java b/services/people/java/com/android/server/people/data/ConversationInfo.java
index dc3fa2a048f6..17378285276f 100644
--- a/services/people/java/com/android/server/people/data/ConversationInfo.java
+++ b/services/people/java/com/android/server/people/data/ConversationInfo.java
@@ -142,9 +142,12 @@ public class ConversationInfo {
return hasShortcutFlags(ShortcutInfo.FLAG_LONG_LIVED);
}
- /** Whether the shortcut for this conversation is cached in Shortcut Service. */
- public boolean isShortcutCached() {
- return hasShortcutFlags(ShortcutInfo.FLAG_CACHED);
+ /**
+ * Whether the shortcut for this conversation is cached in Shortcut Service, with cache owner
+ * set as notifications.
+ */
+ public boolean isShortcutCachedForNotification() {
+ return hasShortcutFlags(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
}
/** Whether this conversation is marked as important by the user. */
@@ -223,7 +226,7 @@ public class ConversationInfo {
if (isShortcutLongLived()) {
sb.append("Liv");
}
- if (isShortcutCached()) {
+ if (isShortcutCachedForNotification()) {
sb.append("Cac");
}
sb.append("]");
diff --git a/services/people/java/com/android/server/people/data/DataManager.java b/services/people/java/com/android/server/people/data/DataManager.java
index bbb0215788fb..63b716206313 100644
--- a/services/people/java/com/android/server/people/data/DataManager.java
+++ b/services/people/java/com/android/server/people/data/DataManager.java
@@ -294,14 +294,14 @@ public class DataManager {
if (notificationListener != null) {
String packageName = packageData.getPackageName();
packageData.forAllConversations(conversationInfo -> {
- if (conversationInfo.isShortcutCached()
+ if (conversationInfo.isShortcutCachedForNotification()
&& conversationInfo.getNotificationChannelId() == null
&& !notificationListener.hasActiveNotifications(
packageName, conversationInfo.getShortcutId())) {
mShortcutServiceInternal.uncacheShortcuts(userId,
mContext.getPackageName(), packageName,
Collections.singletonList(conversationInfo.getShortcutId()),
- userId);
+ userId, ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
}
});
}
@@ -821,12 +821,12 @@ public class DataManager {
// The shortcut was cached by Notification Manager synchronously when the
// associated notification was posted. Uncache it here when all the
// associated notifications are removed.
- if (conversationInfo.isShortcutCached()
+ if (conversationInfo.isShortcutCachedForNotification()
&& conversationInfo.getNotificationChannelId() == null) {
mShortcutServiceInternal.uncacheShortcuts(mUserId,
mContext.getPackageName(), sbn.getPackageName(),
Collections.singletonList(conversationInfo.getShortcutId()),
- mUserId);
+ mUserId, ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
}
} else {
mActiveNotifCounts.put(conversationKey, count);
@@ -891,12 +891,12 @@ public class DataManager {
ConversationInfo conversationInfo =
packageData != null ? packageData.getConversationInfo(shortcutId) : null;
if (conversationInfo != null
- && conversationInfo.isShortcutCached()
+ && conversationInfo.isShortcutCachedForNotification()
&& conversationInfo.getNotificationChannelId() == null) {
mShortcutServiceInternal.uncacheShortcuts(mUserId,
mContext.getPackageName(), packageName,
Collections.singletonList(shortcutId),
- mUserId);
+ mUserId, ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
}
}
}
diff --git a/services/tests/servicestests/src/com/android/server/people/data/ConversationInfoTest.java b/services/tests/servicestests/src/com/android/server/people/data/ConversationInfoTest.java
index 70d6cf81c3b0..c5d94875b684 100644
--- a/services/tests/servicestests/src/com/android/server/people/data/ConversationInfoTest.java
+++ b/services/tests/servicestests/src/com/android/server/people/data/ConversationInfoTest.java
@@ -46,7 +46,8 @@ public final class ConversationInfoTest {
.setContactUri(CONTACT_URI)
.setContactPhoneNumber(PHONE_NUMBER)
.setNotificationChannelId(NOTIFICATION_CHANNEL_ID)
- .setShortcutFlags(ShortcutInfo.FLAG_LONG_LIVED | ShortcutInfo.FLAG_CACHED)
+ .setShortcutFlags(ShortcutInfo.FLAG_LONG_LIVED
+ | ShortcutInfo.FLAG_CACHED_NOTIFICATIONS)
.setImportant(true)
.setNotificationSilenced(true)
.setBubbled(true)
@@ -62,7 +63,7 @@ public final class ConversationInfoTest {
assertEquals(PHONE_NUMBER, conversationInfo.getContactPhoneNumber());
assertEquals(NOTIFICATION_CHANNEL_ID, conversationInfo.getNotificationChannelId());
assertTrue(conversationInfo.isShortcutLongLived());
- assertTrue(conversationInfo.isShortcutCached());
+ assertTrue(conversationInfo.isShortcutCachedForNotification());
assertTrue(conversationInfo.isImportant());
assertTrue(conversationInfo.isNotificationSilenced());
assertTrue(conversationInfo.isBubbled());
@@ -84,7 +85,7 @@ public final class ConversationInfoTest {
assertNull(conversationInfo.getContactPhoneNumber());
assertNull(conversationInfo.getNotificationChannelId());
assertFalse(conversationInfo.isShortcutLongLived());
- assertFalse(conversationInfo.isShortcutCached());
+ assertFalse(conversationInfo.isShortcutCachedForNotification());
assertFalse(conversationInfo.isImportant());
assertFalse(conversationInfo.isNotificationSilenced());
assertFalse(conversationInfo.isBubbled());
diff --git a/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java b/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java
index 1a2032ac15d0..b2f7abbf84df 100644
--- a/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java
@@ -405,7 +405,7 @@ public final class DataManagerTest {
ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID,
buildPerson());
- shortcut.setCached();
+ shortcut.setCached(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
mDataManager.addOrUpdateConversationInfo(shortcut);
NotificationListenerService listenerService =
@@ -419,7 +419,8 @@ public final class DataManagerTest {
assertEquals(1, activeNotificationOpenTimeSlots.size());
verify(mShortcutServiceInternal).uncacheShortcuts(
anyInt(), any(), eq(TEST_PKG_NAME),
- eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY));
+ eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY),
+ eq(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS));
}
@Test
@@ -434,7 +435,7 @@ public final class DataManagerTest {
mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY);
// Post one notification.
- shortcut.setCached();
+ shortcut.setCached(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
mDataManager.addOrUpdateConversationInfo(shortcut);
listenerService.onNotificationPosted(mStatusBarNotification);
@@ -445,14 +446,15 @@ public final class DataManagerTest {
listenerService.onNotificationRemoved(mStatusBarNotification, null,
NotificationListenerService.REASON_CANCEL);
verify(mShortcutServiceInternal, never()).uncacheShortcuts(
- anyInt(), any(), anyString(), any(), anyInt());
+ anyInt(), any(), anyString(), any(), anyInt(), anyInt());
// Removing the second notification un-caches the shortcut.
listenerService.onNotificationRemoved(mStatusBarNotification, null,
NotificationListenerService.REASON_CANCEL_ALL);
verify(mShortcutServiceInternal).uncacheShortcuts(
anyInt(), any(), eq(TEST_PKG_NAME),
- eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY));
+ eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY),
+ eq(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS));
}
@Test
@@ -467,7 +469,7 @@ public final class DataManagerTest {
mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY);
listenerService.onNotificationPosted(mStatusBarNotification);
- shortcut.setCached();
+ shortcut.setCached(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
mDataManager.addOrUpdateConversationInfo(shortcut);
listenerService.onNotificationChannelModified(TEST_PKG_NAME, UserHandle.of(USER_ID_PRIMARY),
@@ -477,7 +479,8 @@ public final class DataManagerTest {
NotificationListenerService.REASON_CANCEL_ALL);
verify(mShortcutServiceInternal, never()).uncacheShortcuts(
anyInt(), any(), eq(TEST_PKG_NAME),
- eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY));
+ eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY),
+ eq(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS));
}
@Test
@@ -569,13 +572,14 @@ public final class DataManagerTest {
mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY);
listenerService.onNotificationPosted(mStatusBarNotification);
- shortcut.setCached();
+ shortcut.setCached(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
mDataManager.addOrUpdateConversationInfo(shortcut);
mShutdownBroadcastReceiver.onReceive(mContext, new Intent());
verify(mShortcutServiceInternal).uncacheShortcuts(
anyInt(), any(), eq(TEST_PKG_NAME),
- eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY));
+ eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY),
+ eq(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS));
}
@Test
@@ -590,7 +594,7 @@ public final class DataManagerTest {
mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY);
listenerService.onNotificationPosted(mStatusBarNotification);
- shortcut.setCached();
+ shortcut.setCached(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
mDataManager.addOrUpdateConversationInfo(shortcut);
listenerService.onNotificationChannelModified(TEST_PKG_NAME, UserHandle.of(USER_ID_PRIMARY),
@@ -599,7 +603,8 @@ public final class DataManagerTest {
mShutdownBroadcastReceiver.onReceive(mContext, new Intent());
verify(mShortcutServiceInternal, never()).uncacheShortcuts(
anyInt(), any(), eq(TEST_PKG_NAME),
- eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY));
+ eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY),
+ eq(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS));
}
@Test
@@ -767,14 +772,15 @@ public final class DataManagerTest {
ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID,
buildPerson());
- shortcut.setCached();
+ shortcut.setCached(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS);
mDataManager.addOrUpdateConversationInfo(shortcut);
mDataManager.pruneDataForUser(USER_ID_PRIMARY, mCancellationSignal);
verify(mShortcutServiceInternal).uncacheShortcuts(
anyInt(), any(), eq(TEST_PKG_NAME),
- eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY));
+ eq(Collections.singletonList(TEST_SHORTCUT_ID)), eq(USER_ID_PRIMARY),
+ eq(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS));
}
@Test
diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
index db02524e6fab..90989b9eda84 100644
--- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
+++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
@@ -137,6 +137,9 @@ import java.util.function.BiConsumer;
@SmallTest
public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
+ private static final int CACHE_OWNER_0 = LauncherApps.FLAG_CACHE_NOTIFICATION_SHORTCUTS;
+ private static final int CACHE_OWNER_1 = LauncherApps.FLAG_CACHE_BUBBLE_SHORTCUTS;
+
@Override
protected void tearDown() throws Exception {
deleteUriFile("file32x32.jpg");
@@ -487,7 +490,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
mManager.pushDynamicShortcut(s8);
assertEquals(4, getCallerShortcut("s8").getRank());
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s8"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s8"), HANDLE_USER_0,
+ CACHE_OWNER_0);
});
mManager.pushDynamicShortcut(s9);
@@ -1452,8 +1456,10 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
// Cache 1 and 2
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2"),
- HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1"),
+ HANDLE_USER_0, CACHE_OWNER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"),
+ HANDLE_USER_0, CACHE_OWNER_1);
});
setCaller(CALLING_PACKAGE_1);
@@ -1532,8 +1538,10 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
// Cache some, but non long lived shortcuts will be ignored.
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2", "s4"),
- HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2"),
+ HANDLE_USER_0, CACHE_OWNER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2", "s4"),
+ HANDLE_USER_0, CACHE_OWNER_1);
});
setCaller(CALLING_PACKAGE_1);
@@ -1555,10 +1563,18 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
"s2", "s4");
+ runWithCaller(LAUNCHER_1, USER_0, () -> {
+ mLauncherApps.uncacheShortcuts(CALLING_PACKAGE_1, list("s2", "s4"),
+ HANDLE_USER_0, CACHE_OWNER_0);
+ });
+ // s2 still cached by owner1. s4 wasn't cached by owner0 so didn't get removed.
+ assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
+ "s2", "s4");
+
// uncache a non-dynamic shortcut. Should be removed.
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.uncacheShortcuts(CALLING_PACKAGE_1, list("s4"),
- HANDLE_USER_0);
+ HANDLE_USER_0, CACHE_OWNER_1);
});
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
"s2");
@@ -1566,7 +1582,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
// Cache another shortcut
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s3"),
- HANDLE_USER_0);
+ HANDLE_USER_0, CACHE_OWNER_0);
});
assertShortcutIds(mManager.getShortcuts(ShortcutManager.FLAG_MATCH_CACHED),
"s2", "s3");
@@ -1594,7 +1610,7 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
// Cache All
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2", "s3", "s4"),
- HANDLE_USER_0);
+ HANDLE_USER_0, CACHE_OWNER_0);
});
setCaller(CALLING_PACKAGE_1);
@@ -1792,8 +1808,10 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
setCaller(LAUNCHER_1);
// Cache some shortcuts. Only long lived shortcuts can get cached.
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1"), getCallingUser());
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_3, list("s3"), getCallingUser());
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1"), getCallingUser(),
+ CACHE_OWNER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_3, list("s3"), getCallingUser(),
+ CACHE_OWNER_0);
// Cached ones only
assertShortcutIds(assertAllNotKeyFieldsOnly(
@@ -8732,7 +8750,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s3", USER_0,
filter_any));
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2"), HANDLE_USER_0,
+ CACHE_OWNER_0);
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0);
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest11.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest11.java
index 621966535306..6a2b8e0da2d2 100644
--- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest11.java
+++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest11.java
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.content.ComponentName;
+import android.content.pm.LauncherApps;
import android.content.pm.LauncherApps.ShortcutChangeCallback;
import android.content.pm.LauncherApps.ShortcutQuery;
import android.content.pm.ShortcutInfo;
@@ -46,6 +47,9 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
private static final ShortcutQuery QUERY_MATCH_ALL = createShortcutQuery(
ShortcutQuery.FLAG_MATCH_ALL_KINDS_WITH_ALL_PINNED);
+ private static final int CACHE_OWNER_0 = LauncherApps.FLAG_CACHE_NOTIFICATION_SHORTCUTS;
+ private static final int CACHE_OWNER_1 = LauncherApps.FLAG_CACHE_BUBBLE_SHORTCUTS;
+
private final TestLooper mTestLooper = new TestLooper();
public void testShortcutChangeCallback_setDynamicShortcuts() {
@@ -113,7 +117,8 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s1"), HANDLE_USER_0);
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0,
+ CACHE_OWNER_0);
});
ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
@@ -211,7 +216,42 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
mTestLooper.getNewExecutor());
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s3"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s3"), HANDLE_USER_0,
+ CACHE_OWNER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s3"), HANDLE_USER_0,
+ CACHE_OWNER_1);
+ });
+
+ mTestLooper.dispatchAll();
+
+ ArgumentCaptor<List> shortcuts = ArgumentCaptor.forClass(List.class);
+ verify(callback, times(2)).onShortcutsAddedOrUpdated(
+ eq(CALLING_PACKAGE_1), shortcuts.capture(), eq(HANDLE_USER_0));
+ verify(callback, times(0)).onShortcutsRemoved(any(), any(), any());
+
+ assertWith(shortcuts.getValue())
+ .areAllWithKeyFieldsOnly()
+ .haveIds("s1", "s3");
+ }
+
+ public void testShortcutChangeCallback_cacheShortcuts_alreadyCached() {
+ runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
+ assertTrue(mManager.setDynamicShortcuts(list(makeLongLivedShortcut("s1"),
+ makeLongLivedShortcut("s2"), makeLongLivedShortcut("s3"))));
+ });
+
+ ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
+ runWithCaller(LAUNCHER_1, USER_0, () -> {
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s3"), HANDLE_USER_0,
+ CACHE_OWNER_0);
+ mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
+ mTestLooper.getNewExecutor());
+ // Should not cause any callback events
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s3"), HANDLE_USER_0,
+ CACHE_OWNER_0);
+ // Should cause a change event
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s3"), HANDLE_USER_0,
+ CACHE_OWNER_1);
});
mTestLooper.dispatchAll();
@@ -234,10 +274,12 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2"), HANDLE_USER_0,
+ CACHE_OWNER_0);
mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
mTestLooper.getNewExecutor());
- mLauncherApps.uncacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0);
+ mLauncherApps.uncacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0,
+ CACHE_OWNER_0);
});
mTestLooper.dispatchAll();
@@ -259,8 +301,11 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
});
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2", "s3"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2", "s3"), HANDLE_USER_0,
+ CACHE_OWNER_0);
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1"), HANDLE_USER_0,
+ CACHE_OWNER_1);
});
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
@@ -271,7 +316,8 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
mTestLooper.getNewExecutor());
- mLauncherApps.uncacheShortcuts(CALLING_PACKAGE_1, list("s2", "s3"), HANDLE_USER_0);
+ mLauncherApps.uncacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2", "s3"), HANDLE_USER_0,
+ CACHE_OWNER_0);
});
mTestLooper.dispatchAll();
@@ -284,9 +330,10 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
verify(callback, times(1)).onShortcutsRemoved(
eq(CALLING_PACKAGE_1), removedShortcuts.capture(), eq(HANDLE_USER_0));
+ // s1 is still cached for owner1, s2 is pinned.
assertWith(changedShortcuts.getValue())
.areAllWithKeyFieldsOnly()
- .haveIds("s2");
+ .haveIds("s1", "s2");
assertWith(removedShortcuts.getValue())
.areAllWithKeyFieldsOnly()
@@ -453,7 +500,8 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0,
+ CACHE_OWNER_0);
mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
mTestLooper.getNewExecutor());
});
@@ -511,7 +559,8 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0,
+ CACHE_OWNER_0);
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0);
mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
mTestLooper.getNewExecutor());
@@ -547,7 +596,8 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
});
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0,
+ CACHE_OWNER_0);
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0);
});
@@ -614,7 +664,8 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0,
+ CACHE_OWNER_0);
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0);
mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
mTestLooper.getNewExecutor());
@@ -680,7 +731,8 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0,
+ CACHE_OWNER_0);
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0);
mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
mTestLooper.getNewExecutor());
@@ -747,7 +799,8 @@ public class ShortcutManagerTest11 extends BaseShortcutManagerTest {
ShortcutChangeCallback callback = mock(ShortcutChangeCallback.class);
runWithCaller(LAUNCHER_1, USER_0, () -> {
- mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0);
+ mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s2"), HANDLE_USER_0,
+ CACHE_OWNER_0);
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0);
mLauncherApps.registerShortcutChangeCallback(callback, QUERY_MATCH_ALL,
mTestLooper.getNewExecutor());
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index ced780475fb7..c43eae75edf7 100755
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -6154,7 +6154,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
// Make sure the shortcut is cached.
verify(mShortcutServiceInternal).cacheShortcuts(
anyInt(), any(), eq(PKG), eq(Collections.singletonList(VALID_CONVO_SHORTCUT_ID)),
- eq(USER_SYSTEM));
+ eq(USER_SYSTEM), eq(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS));
// Test: Remove the shortcut
when(mLauncherApps.getShortcuts(any(), any())).thenReturn(null);
@@ -6227,7 +6227,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
// Make sure the shortcut is cached.
verify(mShortcutServiceInternal).cacheShortcuts(
anyInt(), any(), eq(PKG), eq(Collections.singletonList(shortcutId)),
- eq(USER_SYSTEM));
+ eq(USER_SYSTEM), eq(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS));
// Test: Remove the notification
mBinderService.cancelNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),