Loading core/java/android/content/pm/ShortcutServiceInternal.java +16 −7 Original line number Diff line number Diff line Loading @@ -40,28 +40,37 @@ public abstract class ShortcutServiceInternal { } public abstract List<ShortcutInfo> getShortcuts(@NonNull String callingPackage, long changedSince, getShortcuts(int launcherUserId, @NonNull String callingPackage, long changedSince, @Nullable String packageName, @Nullable ComponentName componentName, @ShortcutQuery.QueryFlags int flags, int userId); public abstract List<ShortcutInfo> getShortcutInfo(@NonNull String callingPackage, getShortcutInfo(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @Nullable List<String> ids, int userId); public abstract void pinShortcuts(@NonNull String callingPackage, @NonNull String packageName, public abstract boolean isPinnedByCaller(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String id, int userId); public abstract void pinShortcuts(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull List<String> shortcutIds, int userId); public abstract Intent createShortcutIntent(@NonNull String callingPackage, public abstract Intent createShortcutIntent(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId, int userId); public abstract void addListener(@NonNull ShortcutChangeListener listener); public abstract int getShortcutIconResId(@NonNull String callingPackage, public abstract int getShortcutIconResId(int launcherUserId, @NonNull String callingPackage, @NonNull ShortcutInfo shortcut, int userId); public abstract ParcelFileDescriptor getShortcutIconFd(@NonNull String callingPackage, public abstract ParcelFileDescriptor getShortcutIconFd(int launcherUserId, @NonNull String callingPackage, @NonNull ShortcutInfo shortcut, int userId); public abstract boolean hasShortcutHostPermission(@NonNull String callingPackage, int userId); public abstract boolean hasShortcutHostPermission(int launcherUserId, @NonNull String callingPackage); } services/core/java/com/android/server/pm/LauncherAppsService.java +37 −28 Original line number Diff line number Diff line Loading @@ -335,40 +335,40 @@ public class LauncherAppsService extends SystemService { verifyCallingPackage(callingPackage); ensureInUserProfiles(user, "Cannot start activity for unrelated profile " + user); if (!mShortcutServiceInternal.hasShortcutHostPermission(callingPackage, user.getIdentifier())) { if (!mShortcutServiceInternal.hasShortcutHostPermission(getCallingUserId(), callingPackage)) { throw new SecurityException("Caller can't access shortcut information"); } } @Override public ParceledListSlice getShortcuts(String callingPackage, long changedSince, String packageName, ComponentName componentName, int flags, UserHandle user) throws RemoteException { String packageName, ComponentName componentName, int flags, UserHandle user) { ensureShortcutPermission(callingPackage, user); return new ParceledListSlice<>( mShortcutServiceInternal.getShortcuts(callingPackage, changedSince, packageName, mShortcutServiceInternal.getShortcuts(getCallingUserId(), callingPackage, changedSince, packageName, componentName, flags, user.getIdentifier())); } @Override public ParceledListSlice getShortcutInfo(String callingPackage, String packageName, List<String> ids, UserHandle user) throws RemoteException { List<String> ids, UserHandle user) { ensureShortcutPermission(callingPackage, user); return new ParceledListSlice<>( mShortcutServiceInternal.getShortcutInfo(callingPackage, packageName, ids, user.getIdentifier())); mShortcutServiceInternal.getShortcutInfo(getCallingUserId(), callingPackage, packageName, ids, user.getIdentifier())); } @Override public void pinShortcuts(String callingPackage, String packageName, List<String> ids, UserHandle user) throws RemoteException { UserHandle user) { ensureShortcutPermission(callingPackage, user); mShortcutServiceInternal.pinShortcuts(callingPackage, packageName, ids, user.getIdentifier()); mShortcutServiceInternal.pinShortcuts(getCallingUserId(), callingPackage, packageName, ids, user.getIdentifier()); } @Override Loading @@ -376,8 +376,8 @@ public class LauncherAppsService extends SystemService { UserHandle user) { ensureShortcutPermission(callingPackage, user); return mShortcutServiceInternal.getShortcutIconResId(callingPackage, shortcut, user.getIdentifier()); return mShortcutServiceInternal.getShortcutIconResId(getCallingUserId(), callingPackage, shortcut, user.getIdentifier()); } @Override Loading @@ -385,25 +385,31 @@ public class LauncherAppsService extends SystemService { UserHandle user) { ensureShortcutPermission(callingPackage, user); return mShortcutServiceInternal.getShortcutIconFd(callingPackage, shortcut, user.getIdentifier()); return mShortcutServiceInternal.getShortcutIconFd(getCallingUserId(), callingPackage, shortcut, user.getIdentifier()); } @Override public boolean hasShortcutHostPermission(String callingPackage) throws RemoteException { public boolean hasShortcutHostPermission(String callingPackage) { verifyCallingPackage(callingPackage); return mShortcutServiceInternal.hasShortcutHostPermission(callingPackage, getCallingUserId()); return mShortcutServiceInternal.hasShortcutHostPermission(getCallingUserId(), callingPackage); } @Override public boolean startShortcut(String callingPackage, String packageName, String shortcutId, Rect sourceBounds, Bundle startActivityOptions, UserHandle user) throws RemoteException { Rect sourceBounds, Bundle startActivityOptions, UserHandle user) { verifyCallingPackage(callingPackage); ensureInUserProfiles(user, "Cannot start activity for unrelated profile " + user); // Even without the permission, pinned shortcuts are always launchable. if (!mShortcutServiceInternal.isPinnedByCaller(getCallingUserId(), callingPackage, packageName, shortcutId, user.getIdentifier())) { ensureShortcutPermission(callingPackage, user); } final Intent intent = mShortcutServiceInternal.createShortcutIntent(callingPackage, packageName, shortcutId, user.getIdentifier()); final Intent intent = mShortcutServiceInternal.createShortcutIntent(getCallingUserId(), callingPackage, packageName, shortcutId, user.getIdentifier()); if (intent == null) { return false; } Loading Loading @@ -713,9 +719,11 @@ public class LauncherAppsService extends SystemService { BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); if (!isEnabledProfileOf(user, cookie.user, "onShortcutChanged")) continue; final int launcherUserId = cookie.user.getIdentifier(); // Make sure the caller has the permission. if (!mShortcutServiceInternal.hasShortcutHostPermission(cookie.packageName, cookie.user.getIdentifier())) { if (!mShortcutServiceInternal.hasShortcutHostPermission( launcherUserId, cookie.packageName)) { continue; } // Each launcher has a different set of pinned shortcuts, so we need to do a Loading @@ -723,7 +731,8 @@ public class LauncherAppsService extends SystemService { // (As of now, only one launcher has the permission at a time, so it's bit // moot, but we may change the permission model eventually.) final List<ShortcutInfo> list = mShortcutServiceInternal.getShortcuts(cookie.packageName, mShortcutServiceInternal.getShortcuts(launcherUserId, cookie.packageName, /* changedSince= */ 0, packageName, /* component= */ null, ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY | ShortcutQuery.FLAG_GET_PINNED Loading services/core/java/com/android/server/pm/ShortcutLauncher.java +21 −5 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ class ShortcutLauncher implements ShortcutPackageItem { private static final String TAG_PACKAGE = "package"; private static final String TAG_PIN = "pin"; private static final String ATTR_LAUNCHER_USER_ID = "launcher-user"; private static final String ATTR_VALUE = "value"; private static final String ATTR_PACKAGE_NAME = "package-name"; Loading @@ -49,14 +50,19 @@ class ShortcutLauncher implements ShortcutPackageItem { @NonNull private final String mPackageName; @UserIdInt private final int mLauncherUserId; /** * Package name -> IDs. */ final private ArrayMap<String, ArraySet<String>> mPinnedShortcuts = new ArrayMap<>(); ShortcutLauncher(@UserIdInt int userId, @NonNull String packageName) { ShortcutLauncher(@UserIdInt int userId, @NonNull String packageName, @UserIdInt int launcherUserId) { mUserId = userId; mPackageName = packageName; mLauncherUserId = launcherUserId; } @UserIdInt Loading @@ -64,6 +70,11 @@ class ShortcutLauncher implements ShortcutPackageItem { return mUserId; } @UserIdInt public int getLauncherUserId() { return mLauncherUserId; } @NonNull public String getPackageName() { return mPackageName; Loading Loading @@ -120,8 +131,8 @@ class ShortcutLauncher implements ShortcutPackageItem { } out.startTag(null, TAG_ROOT); ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, mPackageName); ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, mPackageName); ShortcutService.writeAttr(out, ATTR_LAUNCHER_USER_ID, mLauncherUserId); for (int i = 0; i < size; i++) { out.startTag(null, TAG_PACKAGE); Loading @@ -142,12 +153,15 @@ class ShortcutLauncher implements ShortcutPackageItem { /** * Load. */ public static ShortcutLauncher loadFromXml(XmlPullParser parser, int userId) public static ShortcutLauncher loadFromXml(XmlPullParser parser, int ownerUserId) throws IOException, XmlPullParserException { final String launcherPackageName = ShortcutService.parseStringAttribute(parser, ATTR_PACKAGE_NAME); final int launcherUserId = ShortcutService.parseIntAttribute(parser, ATTR_LAUNCHER_USER_ID, ownerUserId); final ShortcutLauncher ret = new ShortcutLauncher(userId, launcherPackageName); final ShortcutLauncher ret = new ShortcutLauncher(launcherUserId, launcherPackageName, launcherUserId); ArraySet<String> ids = null; final int outerDepth = parser.getDepth(); Loading Loading @@ -184,6 +198,8 @@ class ShortcutLauncher implements ShortcutPackageItem { pw.print(prefix); pw.print("Launcher: "); pw.print(mPackageName); pw.print(" UserId: "); pw.print(mLauncherUserId); pw.println(); final int size = mPinnedShortcuts.size(); Loading services/core/java/com/android/server/pm/ShortcutPackage.java +19 −4 Original line number Diff line number Diff line Loading @@ -104,6 +104,9 @@ class ShortcutPackage implements ShortcutPackageItem { return mPackageName; } /** * Note this does *not* provide a correct view to the calling launcher. */ @Nullable public ShortcutInfo findShortcutById(String id) { return mShortcuts.get(id); Loading Loading @@ -229,8 +232,8 @@ class ShortcutPackage implements ShortcutPackageItem { } // Then, for the pinned set for each launcher, set the pin flag one by one. final ArrayMap<String, ShortcutLauncher> launchers = s.getUserShortcutsLocked(mUserId).getLaunchers(); final ArrayMap<ShortcutUser.PackageWithUser, ShortcutLauncher> launchers = s.getUserShortcutsLocked(mUserId).getAllLaunchers(); for (int l = launchers.size() - 1; l >= 0; l--) { final ShortcutLauncher launcherShortcuts = launchers.valueAt(l); Loading Loading @@ -300,13 +303,25 @@ class ShortcutPackage implements ShortcutPackageItem { /** * Find all shortcuts that match {@code query}. */ public void findAll(@NonNull ShortcutService s, @NonNull List<ShortcutInfo> result, @Nullable Predicate<ShortcutInfo> query, int cloneFlag) { findAll(s, result, query, cloneFlag, null, 0); } /** * Find all shortcuts that match {@code query}. * * This will also provide a "view" for each launcher -- a non-dynamic shortcut that's not pinned * by the calling launcher will not be included in the result, and also "isPinned" will be * adjusted for the caller too. */ public void findAll(@NonNull ShortcutService s, @NonNull List<ShortcutInfo> result, @Nullable Predicate<ShortcutInfo> query, int cloneFlag, @Nullable String callingLauncher) { @Nullable String callingLauncher, int launcherUserId) { // Set of pinned shortcuts by the calling launcher. final ArraySet<String> pinnedByCallerSet = (callingLauncher == null) ? null : s.getLauncherShortcuts(callingLauncher, mUserId) : s.getLauncherShortcuts(callingLauncher, mUserId, launcherUserId) .getPinnedShortcutIds(mPackageName); for (int i = 0; i < mShortcuts.size(); i++) { Loading services/core/java/com/android/server/pm/ShortcutPackageInfo.java +20 −10 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ class ShortcutPackageInfo implements ShortcutPackageItem { private static final String TAG = ShortcutService.TAG; static final String TAG_ROOT = "package-info"; private static final String ATTR_USER_ID = "user"; private static final String ATTR_NAME = "name"; private static final String ATTR_VERSION = "version"; private static final String ATTR_SHADOW = "shadow"; Loading @@ -55,11 +56,8 @@ class ShortcutPackageInfo implements ShortcutPackageItem { private static final String TAG_SIGNATURE = "signature"; private static final String ATTR_SIGNATURE_HASH = "hash"; public interface ShortcutPackageInfoHolder { ShortcutPackageInfo getShortcutPackageInfo(); } private final String mPackageName; private final int mUserId; /** * When true, this package information was restored from the previous device, and the app hasn't Loading @@ -69,12 +67,13 @@ class ShortcutPackageInfo implements ShortcutPackageItem { private int mVersionCode; private ArrayList<byte[]> mSigHashes; private ShortcutPackageInfo(String packageName, int versionCode, ArrayList<byte[]> sigHashes, boolean isShadow) { private ShortcutPackageInfo(String packageName, int userId, int versionCode, ArrayList<byte[]> sigHashes, boolean isShadow) { mPackageName = Preconditions.checkNotNull(packageName); mUserId = userId; mVersionCode = versionCode; mIsShadow = isShadow; mSigHashes = sigHashes; mPackageName = Preconditions.checkNotNull(packageName); } @NonNull Loading @@ -82,6 +81,10 @@ class ShortcutPackageInfo implements ShortcutPackageItem { return mPackageName; } public int getUserId() { return mUserId; } public boolean isShadow() { return mIsShadow; } Loading Loading @@ -197,7 +200,7 @@ class ShortcutPackageInfo implements ShortcutPackageItem { Slog.e(TAG, "Can't get signatures: package=" + packageName); return null; } final ShortcutPackageInfo ret = new ShortcutPackageInfo(packageName, pi.versionCode, final ShortcutPackageInfo ret = new ShortcutPackageInfo(packageName, userId, pi.versionCode, hashSignatureArray(pi.signatures), /* shadow=*/ false); return ret; Loading @@ -221,6 +224,7 @@ class ShortcutPackageInfo implements ShortcutPackageItem { out.startTag(null, TAG_ROOT); ShortcutService.writeAttr(out, ATTR_NAME, mPackageName); ShortcutService.writeAttr(out, ATTR_USER_ID, mUserId); ShortcutService.writeAttr(out, ATTR_VERSION, mVersionCode); ShortcutService.writeAttr(out, ATTR_SHADOW, mIsShadow); Loading @@ -232,10 +236,11 @@ class ShortcutPackageInfo implements ShortcutPackageItem { out.endTag(null, TAG_ROOT); } public static ShortcutPackageInfo loadFromXml(XmlPullParser parser) public static ShortcutPackageInfo loadFromXml(XmlPullParser parser, int ownerUserId) throws IOException, XmlPullParserException { final String packageName = ShortcutService.parseStringAttribute(parser, ATTR_NAME); final int userId = ShortcutService.parseIntAttribute(parser, ATTR_USER_ID, ownerUserId); final int versionCode = ShortcutService.parseIntAttribute(parser, ATTR_VERSION); final boolean shadow = ShortcutService.parseBooleanAttribute(parser, ATTR_SHADOW); Loading @@ -261,7 +266,7 @@ class ShortcutPackageInfo implements ShortcutPackageItem { } throw ShortcutService.throwForInvalidTag(depth, tag); } return new ShortcutPackageInfo(packageName, versionCode, hashes, shadow); return new ShortcutPackageInfo(packageName, userId, versionCode, hashes, shadow); } public void dump(ShortcutService s, PrintWriter pw, String prefix) { Loading @@ -272,6 +277,11 @@ class ShortcutPackageInfo implements ShortcutPackageItem { pw.print(mPackageName); pw.println(); pw.print(prefix); pw.print(" User: "); pw.print(mUserId); pw.println(); pw.print(prefix); pw.print(" IsShadow: "); pw.print(mIsShadow); Loading Loading
core/java/android/content/pm/ShortcutServiceInternal.java +16 −7 Original line number Diff line number Diff line Loading @@ -40,28 +40,37 @@ public abstract class ShortcutServiceInternal { } public abstract List<ShortcutInfo> getShortcuts(@NonNull String callingPackage, long changedSince, getShortcuts(int launcherUserId, @NonNull String callingPackage, long changedSince, @Nullable String packageName, @Nullable ComponentName componentName, @ShortcutQuery.QueryFlags int flags, int userId); public abstract List<ShortcutInfo> getShortcutInfo(@NonNull String callingPackage, getShortcutInfo(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @Nullable List<String> ids, int userId); public abstract void pinShortcuts(@NonNull String callingPackage, @NonNull String packageName, public abstract boolean isPinnedByCaller(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String id, int userId); public abstract void pinShortcuts(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull List<String> shortcutIds, int userId); public abstract Intent createShortcutIntent(@NonNull String callingPackage, public abstract Intent createShortcutIntent(int launcherUserId, @NonNull String callingPackage, @NonNull String packageName, @NonNull String shortcutId, int userId); public abstract void addListener(@NonNull ShortcutChangeListener listener); public abstract int getShortcutIconResId(@NonNull String callingPackage, public abstract int getShortcutIconResId(int launcherUserId, @NonNull String callingPackage, @NonNull ShortcutInfo shortcut, int userId); public abstract ParcelFileDescriptor getShortcutIconFd(@NonNull String callingPackage, public abstract ParcelFileDescriptor getShortcutIconFd(int launcherUserId, @NonNull String callingPackage, @NonNull ShortcutInfo shortcut, int userId); public abstract boolean hasShortcutHostPermission(@NonNull String callingPackage, int userId); public abstract boolean hasShortcutHostPermission(int launcherUserId, @NonNull String callingPackage); }
services/core/java/com/android/server/pm/LauncherAppsService.java +37 −28 Original line number Diff line number Diff line Loading @@ -335,40 +335,40 @@ public class LauncherAppsService extends SystemService { verifyCallingPackage(callingPackage); ensureInUserProfiles(user, "Cannot start activity for unrelated profile " + user); if (!mShortcutServiceInternal.hasShortcutHostPermission(callingPackage, user.getIdentifier())) { if (!mShortcutServiceInternal.hasShortcutHostPermission(getCallingUserId(), callingPackage)) { throw new SecurityException("Caller can't access shortcut information"); } } @Override public ParceledListSlice getShortcuts(String callingPackage, long changedSince, String packageName, ComponentName componentName, int flags, UserHandle user) throws RemoteException { String packageName, ComponentName componentName, int flags, UserHandle user) { ensureShortcutPermission(callingPackage, user); return new ParceledListSlice<>( mShortcutServiceInternal.getShortcuts(callingPackage, changedSince, packageName, mShortcutServiceInternal.getShortcuts(getCallingUserId(), callingPackage, changedSince, packageName, componentName, flags, user.getIdentifier())); } @Override public ParceledListSlice getShortcutInfo(String callingPackage, String packageName, List<String> ids, UserHandle user) throws RemoteException { List<String> ids, UserHandle user) { ensureShortcutPermission(callingPackage, user); return new ParceledListSlice<>( mShortcutServiceInternal.getShortcutInfo(callingPackage, packageName, ids, user.getIdentifier())); mShortcutServiceInternal.getShortcutInfo(getCallingUserId(), callingPackage, packageName, ids, user.getIdentifier())); } @Override public void pinShortcuts(String callingPackage, String packageName, List<String> ids, UserHandle user) throws RemoteException { UserHandle user) { ensureShortcutPermission(callingPackage, user); mShortcutServiceInternal.pinShortcuts(callingPackage, packageName, ids, user.getIdentifier()); mShortcutServiceInternal.pinShortcuts(getCallingUserId(), callingPackage, packageName, ids, user.getIdentifier()); } @Override Loading @@ -376,8 +376,8 @@ public class LauncherAppsService extends SystemService { UserHandle user) { ensureShortcutPermission(callingPackage, user); return mShortcutServiceInternal.getShortcutIconResId(callingPackage, shortcut, user.getIdentifier()); return mShortcutServiceInternal.getShortcutIconResId(getCallingUserId(), callingPackage, shortcut, user.getIdentifier()); } @Override Loading @@ -385,25 +385,31 @@ public class LauncherAppsService extends SystemService { UserHandle user) { ensureShortcutPermission(callingPackage, user); return mShortcutServiceInternal.getShortcutIconFd(callingPackage, shortcut, user.getIdentifier()); return mShortcutServiceInternal.getShortcutIconFd(getCallingUserId(), callingPackage, shortcut, user.getIdentifier()); } @Override public boolean hasShortcutHostPermission(String callingPackage) throws RemoteException { public boolean hasShortcutHostPermission(String callingPackage) { verifyCallingPackage(callingPackage); return mShortcutServiceInternal.hasShortcutHostPermission(callingPackage, getCallingUserId()); return mShortcutServiceInternal.hasShortcutHostPermission(getCallingUserId(), callingPackage); } @Override public boolean startShortcut(String callingPackage, String packageName, String shortcutId, Rect sourceBounds, Bundle startActivityOptions, UserHandle user) throws RemoteException { Rect sourceBounds, Bundle startActivityOptions, UserHandle user) { verifyCallingPackage(callingPackage); ensureInUserProfiles(user, "Cannot start activity for unrelated profile " + user); // Even without the permission, pinned shortcuts are always launchable. if (!mShortcutServiceInternal.isPinnedByCaller(getCallingUserId(), callingPackage, packageName, shortcutId, user.getIdentifier())) { ensureShortcutPermission(callingPackage, user); } final Intent intent = mShortcutServiceInternal.createShortcutIntent(callingPackage, packageName, shortcutId, user.getIdentifier()); final Intent intent = mShortcutServiceInternal.createShortcutIntent(getCallingUserId(), callingPackage, packageName, shortcutId, user.getIdentifier()); if (intent == null) { return false; } Loading Loading @@ -713,9 +719,11 @@ public class LauncherAppsService extends SystemService { BroadcastCookie cookie = (BroadcastCookie) mListeners.getBroadcastCookie(i); if (!isEnabledProfileOf(user, cookie.user, "onShortcutChanged")) continue; final int launcherUserId = cookie.user.getIdentifier(); // Make sure the caller has the permission. if (!mShortcutServiceInternal.hasShortcutHostPermission(cookie.packageName, cookie.user.getIdentifier())) { if (!mShortcutServiceInternal.hasShortcutHostPermission( launcherUserId, cookie.packageName)) { continue; } // Each launcher has a different set of pinned shortcuts, so we need to do a Loading @@ -723,7 +731,8 @@ public class LauncherAppsService extends SystemService { // (As of now, only one launcher has the permission at a time, so it's bit // moot, but we may change the permission model eventually.) final List<ShortcutInfo> list = mShortcutServiceInternal.getShortcuts(cookie.packageName, mShortcutServiceInternal.getShortcuts(launcherUserId, cookie.packageName, /* changedSince= */ 0, packageName, /* component= */ null, ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY | ShortcutQuery.FLAG_GET_PINNED Loading
services/core/java/com/android/server/pm/ShortcutLauncher.java +21 −5 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ class ShortcutLauncher implements ShortcutPackageItem { private static final String TAG_PACKAGE = "package"; private static final String TAG_PIN = "pin"; private static final String ATTR_LAUNCHER_USER_ID = "launcher-user"; private static final String ATTR_VALUE = "value"; private static final String ATTR_PACKAGE_NAME = "package-name"; Loading @@ -49,14 +50,19 @@ class ShortcutLauncher implements ShortcutPackageItem { @NonNull private final String mPackageName; @UserIdInt private final int mLauncherUserId; /** * Package name -> IDs. */ final private ArrayMap<String, ArraySet<String>> mPinnedShortcuts = new ArrayMap<>(); ShortcutLauncher(@UserIdInt int userId, @NonNull String packageName) { ShortcutLauncher(@UserIdInt int userId, @NonNull String packageName, @UserIdInt int launcherUserId) { mUserId = userId; mPackageName = packageName; mLauncherUserId = launcherUserId; } @UserIdInt Loading @@ -64,6 +70,11 @@ class ShortcutLauncher implements ShortcutPackageItem { return mUserId; } @UserIdInt public int getLauncherUserId() { return mLauncherUserId; } @NonNull public String getPackageName() { return mPackageName; Loading Loading @@ -120,8 +131,8 @@ class ShortcutLauncher implements ShortcutPackageItem { } out.startTag(null, TAG_ROOT); ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, mPackageName); ShortcutService.writeAttr(out, ATTR_PACKAGE_NAME, mPackageName); ShortcutService.writeAttr(out, ATTR_LAUNCHER_USER_ID, mLauncherUserId); for (int i = 0; i < size; i++) { out.startTag(null, TAG_PACKAGE); Loading @@ -142,12 +153,15 @@ class ShortcutLauncher implements ShortcutPackageItem { /** * Load. */ public static ShortcutLauncher loadFromXml(XmlPullParser parser, int userId) public static ShortcutLauncher loadFromXml(XmlPullParser parser, int ownerUserId) throws IOException, XmlPullParserException { final String launcherPackageName = ShortcutService.parseStringAttribute(parser, ATTR_PACKAGE_NAME); final int launcherUserId = ShortcutService.parseIntAttribute(parser, ATTR_LAUNCHER_USER_ID, ownerUserId); final ShortcutLauncher ret = new ShortcutLauncher(userId, launcherPackageName); final ShortcutLauncher ret = new ShortcutLauncher(launcherUserId, launcherPackageName, launcherUserId); ArraySet<String> ids = null; final int outerDepth = parser.getDepth(); Loading Loading @@ -184,6 +198,8 @@ class ShortcutLauncher implements ShortcutPackageItem { pw.print(prefix); pw.print("Launcher: "); pw.print(mPackageName); pw.print(" UserId: "); pw.print(mLauncherUserId); pw.println(); final int size = mPinnedShortcuts.size(); Loading
services/core/java/com/android/server/pm/ShortcutPackage.java +19 −4 Original line number Diff line number Diff line Loading @@ -104,6 +104,9 @@ class ShortcutPackage implements ShortcutPackageItem { return mPackageName; } /** * Note this does *not* provide a correct view to the calling launcher. */ @Nullable public ShortcutInfo findShortcutById(String id) { return mShortcuts.get(id); Loading Loading @@ -229,8 +232,8 @@ class ShortcutPackage implements ShortcutPackageItem { } // Then, for the pinned set for each launcher, set the pin flag one by one. final ArrayMap<String, ShortcutLauncher> launchers = s.getUserShortcutsLocked(mUserId).getLaunchers(); final ArrayMap<ShortcutUser.PackageWithUser, ShortcutLauncher> launchers = s.getUserShortcutsLocked(mUserId).getAllLaunchers(); for (int l = launchers.size() - 1; l >= 0; l--) { final ShortcutLauncher launcherShortcuts = launchers.valueAt(l); Loading Loading @@ -300,13 +303,25 @@ class ShortcutPackage implements ShortcutPackageItem { /** * Find all shortcuts that match {@code query}. */ public void findAll(@NonNull ShortcutService s, @NonNull List<ShortcutInfo> result, @Nullable Predicate<ShortcutInfo> query, int cloneFlag) { findAll(s, result, query, cloneFlag, null, 0); } /** * Find all shortcuts that match {@code query}. * * This will also provide a "view" for each launcher -- a non-dynamic shortcut that's not pinned * by the calling launcher will not be included in the result, and also "isPinned" will be * adjusted for the caller too. */ public void findAll(@NonNull ShortcutService s, @NonNull List<ShortcutInfo> result, @Nullable Predicate<ShortcutInfo> query, int cloneFlag, @Nullable String callingLauncher) { @Nullable String callingLauncher, int launcherUserId) { // Set of pinned shortcuts by the calling launcher. final ArraySet<String> pinnedByCallerSet = (callingLauncher == null) ? null : s.getLauncherShortcuts(callingLauncher, mUserId) : s.getLauncherShortcuts(callingLauncher, mUserId, launcherUserId) .getPinnedShortcutIds(mPackageName); for (int i = 0; i < mShortcuts.size(); i++) { Loading
services/core/java/com/android/server/pm/ShortcutPackageInfo.java +20 −10 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ class ShortcutPackageInfo implements ShortcutPackageItem { private static final String TAG = ShortcutService.TAG; static final String TAG_ROOT = "package-info"; private static final String ATTR_USER_ID = "user"; private static final String ATTR_NAME = "name"; private static final String ATTR_VERSION = "version"; private static final String ATTR_SHADOW = "shadow"; Loading @@ -55,11 +56,8 @@ class ShortcutPackageInfo implements ShortcutPackageItem { private static final String TAG_SIGNATURE = "signature"; private static final String ATTR_SIGNATURE_HASH = "hash"; public interface ShortcutPackageInfoHolder { ShortcutPackageInfo getShortcutPackageInfo(); } private final String mPackageName; private final int mUserId; /** * When true, this package information was restored from the previous device, and the app hasn't Loading @@ -69,12 +67,13 @@ class ShortcutPackageInfo implements ShortcutPackageItem { private int mVersionCode; private ArrayList<byte[]> mSigHashes; private ShortcutPackageInfo(String packageName, int versionCode, ArrayList<byte[]> sigHashes, boolean isShadow) { private ShortcutPackageInfo(String packageName, int userId, int versionCode, ArrayList<byte[]> sigHashes, boolean isShadow) { mPackageName = Preconditions.checkNotNull(packageName); mUserId = userId; mVersionCode = versionCode; mIsShadow = isShadow; mSigHashes = sigHashes; mPackageName = Preconditions.checkNotNull(packageName); } @NonNull Loading @@ -82,6 +81,10 @@ class ShortcutPackageInfo implements ShortcutPackageItem { return mPackageName; } public int getUserId() { return mUserId; } public boolean isShadow() { return mIsShadow; } Loading Loading @@ -197,7 +200,7 @@ class ShortcutPackageInfo implements ShortcutPackageItem { Slog.e(TAG, "Can't get signatures: package=" + packageName); return null; } final ShortcutPackageInfo ret = new ShortcutPackageInfo(packageName, pi.versionCode, final ShortcutPackageInfo ret = new ShortcutPackageInfo(packageName, userId, pi.versionCode, hashSignatureArray(pi.signatures), /* shadow=*/ false); return ret; Loading @@ -221,6 +224,7 @@ class ShortcutPackageInfo implements ShortcutPackageItem { out.startTag(null, TAG_ROOT); ShortcutService.writeAttr(out, ATTR_NAME, mPackageName); ShortcutService.writeAttr(out, ATTR_USER_ID, mUserId); ShortcutService.writeAttr(out, ATTR_VERSION, mVersionCode); ShortcutService.writeAttr(out, ATTR_SHADOW, mIsShadow); Loading @@ -232,10 +236,11 @@ class ShortcutPackageInfo implements ShortcutPackageItem { out.endTag(null, TAG_ROOT); } public static ShortcutPackageInfo loadFromXml(XmlPullParser parser) public static ShortcutPackageInfo loadFromXml(XmlPullParser parser, int ownerUserId) throws IOException, XmlPullParserException { final String packageName = ShortcutService.parseStringAttribute(parser, ATTR_NAME); final int userId = ShortcutService.parseIntAttribute(parser, ATTR_USER_ID, ownerUserId); final int versionCode = ShortcutService.parseIntAttribute(parser, ATTR_VERSION); final boolean shadow = ShortcutService.parseBooleanAttribute(parser, ATTR_SHADOW); Loading @@ -261,7 +266,7 @@ class ShortcutPackageInfo implements ShortcutPackageItem { } throw ShortcutService.throwForInvalidTag(depth, tag); } return new ShortcutPackageInfo(packageName, versionCode, hashes, shadow); return new ShortcutPackageInfo(packageName, userId, versionCode, hashes, shadow); } public void dump(ShortcutService s, PrintWriter pw, String prefix) { Loading @@ -272,6 +277,11 @@ class ShortcutPackageInfo implements ShortcutPackageItem { pw.print(mPackageName); pw.println(); pw.print(prefix); pw.print(" User: "); pw.print(mUserId); pw.println(); pw.print(prefix); pw.print(" IsShadow: "); pw.print(mIsShadow); Loading