diff options
| -rw-r--r-- | core/java/android/content/pm/ILauncherApps.aidl | 1 | ||||
| -rw-r--r-- | core/java/android/content/pm/LauncherApps.java | 23 | ||||
| -rw-r--r-- | services/core/java/com/android/server/pm/LauncherAppsService.java | 24 |
3 files changed, 48 insertions, 0 deletions
diff --git a/core/java/android/content/pm/ILauncherApps.aidl b/core/java/android/content/pm/ILauncherApps.aidl index e9f419e9a8ce..6f7299aa8e31 100644 --- a/core/java/android/content/pm/ILauncherApps.aidl +++ b/core/java/android/content/pm/ILauncherApps.aidl @@ -64,6 +64,7 @@ interface ILauncherApps { PendingIntent getActivityLaunchIntent(String callingPackage, in ComponentName component, in UserHandle user); LauncherUserInfo getLauncherUserInfo(in UserHandle user); + List<String> getPreInstalledSystemPackages(in UserHandle user); void showAppDetailsAsUser(in IApplicationThread caller, String callingPackage, String callingFeatureId, in ComponentName component, in Rect sourceBounds, in Bundle opts, in UserHandle user); diff --git a/core/java/android/content/pm/LauncherApps.java b/core/java/android/content/pm/LauncherApps.java index 0cd4358b2c91..ccc8f0956865 100644 --- a/core/java/android/content/pm/LauncherApps.java +++ b/core/java/android/content/pm/LauncherApps.java @@ -800,6 +800,29 @@ public class LauncherApps { } /** + * Returns the list of the system packages that are installed at user creation. + * + * <p>An empty list denotes that all system packages are installed for that user at creation. + * This behaviour is inherited from the underlining UserManager API. + * + * @param userHandle the user for which installed system packages are required. + * @return {@link List} of {@link String}, representing the package name of the installed + * package. Can be empty but not null. + * @hide + */ + @FlaggedApi(Flags.FLAG_ALLOW_PRIVATE_PROFILE) + public List<String> getPreInstalledSystemPackages(@NonNull UserHandle userHandle) { + if (DEBUG) { + Log.i(TAG, "getPreInstalledSystemPackages for user: " + userHandle); + } + try { + return mService.getPreInstalledSystemPackages(userHandle); + } catch (RemoteException re) { + throw re.rethrowFromSystemServer(); + } + } + + /** * Returns the activity info for a given intent and user handle, if it resolves. Otherwise it * returns null. * diff --git a/services/core/java/com/android/server/pm/LauncherAppsService.java b/services/core/java/com/android/server/pm/LauncherAppsService.java index b80c0094ffb9..ecbee3934c8a 100644 --- a/services/core/java/com/android/server/pm/LauncherAppsService.java +++ b/services/core/java/com/android/server/pm/LauncherAppsService.java @@ -1571,6 +1571,30 @@ public class LauncherAppsService extends SystemService { } @Override + public List<String> getPreInstalledSystemPackages(UserHandle user) { + // Only system launchers, which have access to recents should have access to this API. + // TODO(b/303803157): Update access control for this API to default Launcher app. + if (!mActivityTaskManagerInternal.isCallerRecents(Binder.getCallingUid())) { + throw new SecurityException("Caller is not the recents app"); + } + if (!canAccessProfile(user.getIdentifier(), + "Can't access preinstalled packages for another user")) { + return null; + } + final long identity = Binder.clearCallingIdentity(); + try { + String userType = mUm.getUserInfo(user.getIdentifier()).userType; + Set<String> preInstalledPackages = mUm.getPreInstallableSystemPackages(userType); + if (preInstalledPackages == null) { + return new ArrayList<>(); + } + return List.copyOf(preInstalledPackages); + } finally { + Binder.restoreCallingIdentity(identity); + } + } + + @Override public void startActivityAsUser(IApplicationThread caller, String callingPackage, String callingFeatureId, ComponentName component, Rect sourceBounds, Bundle opts, UserHandle user) throws RemoteException { |