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

Commit 8b0ad261 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Integrated policy-exempt-apps into setApplicationHidden()." into sc-dev am: 53a24c73

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13998093

Change-Id: Ia9b740eb6e748191b60afb9ba6f973ea3766a488
parents 385d3899 53a24c73
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -10692,10 +10692,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    private String[] populateNonExemptAndExemptFromPolicyApps(String[] packageNames,
            Set<String> outputExemptApps) {
        Preconditions.checkArgument(outputExemptApps.isEmpty(), "outputExemptApps is not empty");
        List<String> exemptApps = listPolicyExemptAppsUnchecked();
        if (exemptApps.isEmpty()) {
        List<String> exemptAppsList = listPolicyExemptAppsUnchecked();
        if (exemptAppsList.isEmpty()) {
            return packageNames;
        }
        // Using a set so contains() is O(1)
        Set<String> exemptApps = new HashSet<>(exemptAppsList);
        List<String> nonExemptApps = new ArrayList<>(packageNames.length);
        for (int i = 0; i < packageNames.length; i++) {
            String app = packageNames[i];
@@ -10974,6 +10976,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                && (isProfileOwner(caller) || isDeviceOwner(caller)))
                || (caller.hasPackage() && isCallerDelegate(caller, DELEGATION_PACKAGE_ACCESS)));
        List<String> exemptApps = listPolicyExemptAppsUnchecked();
        if (exemptApps.contains(packageName)) {
            Slog.d(LOG_TAG, "setApplicationHidden(): ignoring %s as it's on policy-exempt list",
                    packageName);
            return false;
        }
        final int userId = parent ? getProfileParentId(caller.getUserId()) : caller.getUserId();
        boolean result;
        synchronized (getLockObject()) {
@@ -10988,6 +10997,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            }
            checkCanExecuteOrThrowUnsafe(DevicePolicyManager.OPERATION_SET_APPLICATION_HIDDEN);
            if (VERBOSE_LOG) {
                Slog.v(LOG_TAG, "calling pm.setApplicationHiddenSettingAsUser(%s, %b, %d)",
                        packageName, hidden, userId);
            }
            result = mInjector.binderWithCleanCallingIdentity(() -> mIPackageManager
                    .setApplicationHiddenSettingAsUser(packageName, hidden, userId));
        }
+9 −0
Original line number Diff line number Diff line
@@ -2569,6 +2569,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        setupDeviceOwner();
        mContext.packageName = admin1.getPackageName();
        setUpPackageManagerForAdmin(admin1, mContext.binder.callingUid);
        mockEmptyPolicyExemptApps();

        String packageName = "com.google.android.test";

@@ -2598,6 +2599,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE);
        mContext.packageName = admin1.getPackageName();
        setUpPackageManagerForAdmin(admin1, mContext.binder.callingUid);
        mockEmptyPolicyExemptApps();

        String packageName = "com.google.android.test";

@@ -7489,4 +7491,11 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        Log.d(TAG, "Mocking R.array.vendor_policy_exempt_apps to return " + Arrays.toString(apps));
        when(mContext.resources.getStringArray(R.array.vendor_policy_exempt_apps)).thenReturn(apps);
    }

    private void mockEmptyPolicyExemptApps() {
        when(mContext.getResources().getStringArray(R.array.policy_exempt_apps))
                .thenReturn(new String[0]);
        when(mContext.getResources().getStringArray(R.array.vendor_policy_exempt_apps))
                .thenReturn(new String[0]);
    }
}