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

Commit 30554003 authored by Jackal Guo's avatar Jackal Guo
Browse files

Fix cross user app visibility gap for setApplicationHidden

Since DO/POs are privileged components, the implementation in DPM
would invoke PM#setApplicationHidden with #clearCallingIdentity.
However, the check in #getPackageStateForInstalledAndFiltered by-
passes system, shell, and root UID. This makes the check invalid,
and results in cross user app visibility gap. Apply the install
state check manually to mitigate this. Besides, this CL makes the
return early if the hidden state is unchanged.

Bug: 229684723
Bug: 239945013
Test: CtsDevicePolicyManagerTestCases:ManagedProfileCrossProfileTest
Test: FrameworksServicesTests:DevicePolicyManagerTest#
        testSetApplicationHiddenWithDO
        testSetApplicationHiddenWithPOOfOrganizationOwnedDevice
        testSetApplicationHidden_failIfNotDeviceOrProfileOwner
Test: SettingsLibTests:
        AppRestrictionsHelperTest#testApplyUserAppsStates
        AppCopyingHelperTest#testInstallSelectedApps
Test: manually using the PoC in the buganizer to ensure the symptom
      no longer exists.

Change-Id: I5f6040e622f6dfc6c10a6bdfb7d37e30fdf3c3f1
parent 9bfd66eb
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -5434,13 +5434,19 @@ public class PackageManagerService implements PackageSender, TestUtilityService

            final long callingId = Binder.clearCallingIdentity();
            try {
                final PackageStateInternal packageState =
                        snapshot.getPackageStateForInstalledAndFiltered(
                                packageName, callingUid, userId);
                final PackageStateInternal packageState = snapshot.getPackageStateInternal(
                        packageName);
                if (packageState == null) {
                    return false;
                }

                final PackageUserStateInternal userState = packageState.getUserStateOrDefault(
                        userId);
                if (userState.isHidden() == hidden || !userState.isInstalled()
                        || snapshot.shouldFilterApplication(packageState, callingUid, userId)) {
                    return false;
                }

                // Cannot hide static shared libs as they are considered
                // a part of the using app (emulating static linking). Also
                // static libs are installed always on internal storage.
@@ -5470,10 +5476,6 @@ public class PackageManagerService implements PackageSender, TestUtilityService
                    return false;
                }

                if (packageState.getUserStateOrDefault(userId).isHidden() == hidden) {
                    return false;
                }

                commitPackageStateMutation(null, packageName, packageState1 ->
                        packageState1.userState(userId).setHidden(hidden));