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

Commit 583c6458 authored by Himanshu Gupta's avatar Himanshu Gupta
Browse files

Adding API for retrieving the list of pre-installed system packages.

Launcher apps can use this API to identify system installed apps for
a given profile type.

The API is only accessible to system launcher ATM as it
can enlist activities in private space.
At a later point (b/303803157) this would be fine tuned.

Bug: 308054233
Test: atest LauncherAppsTest
Change-Id: Ifeb19580f13ced5e514244974d022749ed90031d
parent 7d00847a
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
@@ -1570,6 +1570,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,