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

Commit 6a4fc06f authored by Jakob Schneider's avatar Jakob Schneider
Browse files

Fix a crash in the LauncherApps Api for the work profile.

Launchers can currently not fetch archived apps from other profiles (it
crashes in fact). The new approach is consistent with how we handle
other activities http://shortn/_m6ScWfSfA7. 1) check canAccessProfile(),
2) Execute userId checkss without relying on the binderUid.

Test: LauncherAppsTest
Bug: 314947627
Change-Id: Iffd62827bb6538591518337942f6806d963fa11f
parent b813ecf9
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -222,6 +222,14 @@ public abstract class PackageManagerInternal {
            @PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId,
            int callingUid);

    /**
     * Like {@link #getInstalledApplications}, but allows the fetching of apps
     * cross user.
     */
    public abstract List<ApplicationInfo> getInstalledApplicationsCrossUser(
            @PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId,
            int callingUid);

    /**
     * Retrieve launcher extras for a suspended package provided to the system in
     * {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
+1 −1
Original line number Diff line number Diff line
@@ -467,7 +467,7 @@ public interface Computer extends PackageDataSnapshot {
    @NonNull
    List<ApplicationInfo> getInstalledApplications(
            @PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId,
            int callingUid);
            int callingUid, boolean forceAllowCrossUser);

    @Nullable
    ProviderInfo resolveContentProvider(@NonNull String name,
+9 −7
Original line number Diff line number Diff line
@@ -4623,7 +4623,7 @@ public class ComputerEngine implements Computer {
    @Override
    public List<ApplicationInfo> getInstalledApplications(
            @PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId,
            int callingUid) {
            int callingUid, boolean forceAllowCrossUser) {
        if (getInstantAppPackageName(callingUid) != null) {
            return Collections.emptyList();
        }
@@ -4633,12 +4633,14 @@ public class ComputerEngine implements Computer {
        final boolean listApex = (flags & MATCH_APEX) != 0;
        final boolean listArchivedOnly = !listUninstalled && (flags & MATCH_ARCHIVED_PACKAGES) != 0;

        if (!forceAllowCrossUser) {
            enforceCrossUserPermission(
                    callingUid,
                    userId,
                    false /* requireFullPermission */,
                    false /* checkShell */,
                    "get installed application info");
        }

        ArrayList<ApplicationInfo> list;
        final ArrayMap<String, ? extends PackageStateInternal> packageStates =
+2 −1
Original line number Diff line number Diff line
@@ -476,7 +476,8 @@ public abstract class IPackageManagerBase extends IPackageManager.Stub {
            @PackageManager.ApplicationInfoFlagsBits long flags, int userId) {
        final int callingUid = Binder.getCallingUid();
        return new ParceledListSlice<>(
                snapshot().getInstalledApplications(flags, userId, callingUid));
                snapshot().getInstalledApplications(flags, userId, callingUid,
                        /* forceAllowCrossUser= */ false));
    }

    @Override
+10 −6
Original line number Diff line number Diff line
@@ -769,6 +769,9 @@ public class LauncherAppsService extends SystemService {
        @NonNull
        private List<LauncherActivityInfoInternal> generateLauncherActivitiesForArchivedApp(
                @Nullable String packageName, UserHandle user) {
            if (!canAccessProfile(user.getIdentifier(), "Cannot retrieve activities")) {
                return List.of();
            }
            List<ApplicationInfo> applicationInfoList =
                    (packageName == null)
                            ? getApplicationInfoListForAllArchivedApps(user)
@@ -827,7 +830,7 @@ public class LauncherAppsService extends SystemService {
        private List<ApplicationInfo> getApplicationInfoListForAllArchivedApps(UserHandle user) {
            final int callingUid = injectBinderCallingUid();
            List<ApplicationInfo> installedApplicationInfoList =
                    mPackageManagerInternal.getInstalledApplications(
                    mPackageManagerInternal.getInstalledApplicationsCrossUser(
                            PackageManager.MATCH_ARCHIVED_PACKAGES,
                            user.getIdentifier(),
                            callingUid);
@@ -845,11 +848,12 @@ public class LauncherAppsService extends SystemService {
        private List<ApplicationInfo> getApplicationInfoForArchivedApp(
                @NonNull String packageName, UserHandle user) {
            final int callingUid = injectBinderCallingUid();
            ApplicationInfo applicationInfo = mPackageManagerInternal.getApplicationInfo(
            ApplicationInfo applicationInfo = Binder.withCleanCallingIdentity(() ->
                    mPackageManagerInternal.getApplicationInfo(
                            packageName,
                            PackageManager.MATCH_ARCHIVED_PACKAGES,
                            callingUid,
                    user.getIdentifier());
                            user.getIdentifier()));
            if (applicationInfo == null || !applicationInfo.isArchived) {
                return Collections.EMPTY_LIST;
            }
Loading