Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7e389908 authored by Himanshu Gupta's avatar Himanshu Gupta Committed by Android (Google) Code Review
Browse files

Merge "Adding API for retrieving the list of pre-installed system packages." into main

parents dc21a79c 583c6458
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+23 −0
Original line number Diff line number Diff line
@@ -799,6 +799,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.
+24 −0
Original line number Diff line number Diff line
@@ -1574,6 +1574,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,