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

Commit d9283a79 authored by Alex Johnston's avatar Alex Johnston
Browse files

Update COPE metrics

* Add the parent flag to the existing metrics for:
	- setUserRestriction
	- getPasswordComplexity
	- wipeData
	- setCameraDisabled

Bug: 148841428
Test: atest com.android.cts.devicepolicy.DeviceOwnerPlusProfileOwnerTest#testWipeData_secondaryUserLogged
      atest com.android.cts.devicepolicy.ManagedProfileWipeTest#testWipeDataLogged
      atest com.android.cts.devicepolicy.PasswordComplexityTest#testGetPasswordComplexity
      atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testSetCameraDisabledLogged
      atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testSetKeyguardDisabledFeaturesLogged
      atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testApplicationHidden
      atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testPasswordMethodsLogged
      atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testSetUserRestrictionLogged
      atest com.android.cts.devicepolicy.OrgOwnedProfileOwnerTest#testCameraDisabledOnParentLogged
      atest com.android.cts.devicepolicy.OrgOwnedProfileOwnerTest#testUserRestrictionSetOnParentLogged

Change-Id: Ia3bf5aa1149aded6d2effab938881669b2e23c45
parent 688689eb
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -408,6 +408,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    private static final String ATTR_APPLICATION_RESTRICTIONS_MANAGER
            = "application-restrictions-manager";
    private static final String CALLED_FROM_PARENT = "calledFromParent";
    private static final String NOT_CALLED_FROM_PARENT = "notCalledFromParent";
    // Comprehensive list of delegations.
    private static final String DELEGATIONS[] = {
        DELEGATION_CERT_INSTALL,
@@ -4467,7 +4470,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                .createEvent(DevicePolicyEnums.SET_PASSWORD_QUALITY)
                .setAdmin(who)
                .setInt(quality)
                .setBoolean(parent)
                .setStrings(parent ? CALLED_FROM_PARENT : NOT_CALLED_FROM_PARENT)
                .write();
    }
@@ -5255,8 +5258,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    public int getPasswordComplexity(boolean parent) {
        DevicePolicyEventLogger
                .createEvent(DevicePolicyEnums.GET_USER_PASSWORD_COMPLEXITY_LEVEL)
                .setStrings(mInjector.getPackageManager()
                        .getPackagesForUid(mInjector.binderGetCallingUid()))
                .setStrings(parent ? CALLED_FROM_PARENT : NOT_CALLED_FROM_PARENT,
                        mInjector.getPackageManager().getPackagesForUid(
                                mInjector.binderGetCallingUid()))
                .write();
        final int callingUserId = mInjector.userHandleGetCallingUserId();
@@ -6930,6 +6934,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                .createEvent(DevicePolicyEnums.WIPE_DATA_WITH_REASON)
                .setAdmin(admin.info.getComponent())
                .setInt(flags)
                .setStrings(calledOnParentInstance ? CALLED_FROM_PARENT : NOT_CALLED_FROM_PARENT)
                .write();
        String internalReason = String.format(
                "DevicePolicyManager.wipeDataWithReason() from %s, organization-owned? %s",
@@ -8089,6 +8094,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                .createEvent(DevicePolicyEnums.SET_CAMERA_DISABLED)
                .setAdmin(who)
                .setBoolean(disabled)
                .setStrings(parent ? CALLED_FROM_PARENT : NOT_CALLED_FROM_PARENT)
                .write();
    }
@@ -8166,7 +8172,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                .createEvent(DevicePolicyEnums.SET_KEYGUARD_DISABLED_FEATURES)
                .setAdmin(who)
                .setInt(which)
                .setBoolean(parent)
                .setStrings(parent ? CALLED_FROM_PARENT : NOT_CALLED_FROM_PARENT)
                .write();
    }
@@ -10670,7 +10676,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        DevicePolicyEventLogger
                .createEvent(eventId)
                .setAdmin(who)
                .setStrings(key)
                .setStrings(key, parent ? CALLED_FROM_PARENT : NOT_CALLED_FROM_PARENT)
                .write();
        if (SecurityLog.isLoggingEnabled()) {
            final int eventTag = enabledFromThisOwner
@@ -10814,8 +10820,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                .createEvent(DevicePolicyEnums.SET_APPLICATION_HIDDEN)
                .setAdmin(callerPackage)
                .setBoolean(isDelegate)
                .setBoolean(parent)
                .setStrings(packageName, hidden ? "hidden" : "not_hidden")
                .setStrings(packageName, hidden ? "hidden" : "not_hidden",
                        parent ? CALLED_FROM_PARENT : NOT_CALLED_FROM_PARENT)
                .write();
        return result;
    }
+18 −0
Original line number Diff line number Diff line
@@ -5689,6 +5689,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    }

    public void testGetPasswordComplexity_securityExceptionNotThrownForParentInstance() {
        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        when(getServices().packageManager.getPackagesForUid(DpmMockContext.CALLER_UID)).thenReturn(
                new String[0]);
        mServiceContext.permissions.add(permission.REQUEST_PASSWORD_COMPLEXITY);
        setAsProfileOwner(admin1);

@@ -5698,12 +5701,18 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    }

    public void testGetPasswordComplexity_illegalStateExceptionIfLocked() {
        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        when(getServices().packageManager.getPackagesForUid(DpmMockContext.CALLER_UID)).thenReturn(
                new String[0]);
        when(getServices().userManager.isUserUnlocked(DpmMockContext.CALLER_USER_HANDLE))
                .thenReturn(false);
        assertThrows(IllegalStateException.class, () -> dpm.getPasswordComplexity());
    }

    public void testGetPasswordComplexity_securityExceptionWithoutPermissions() {
        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        when(getServices().packageManager.getPackagesForUid(DpmMockContext.CALLER_UID)).thenReturn(
                new String[0]);
        when(getServices().userManager.isUserUnlocked(DpmMockContext.CALLER_USER_HANDLE))
                .thenReturn(true);
        assertThrows(SecurityException.class, () -> dpm.getPasswordComplexity());
@@ -5711,6 +5720,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {


    public void testGetPasswordComplexity_currentUserNoPassword() {
        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        when(getServices().packageManager.getPackagesForUid(DpmMockContext.CALLER_UID)).thenReturn(
                new String[0]);
        when(getServices().userManager.isUserUnlocked(DpmMockContext.CALLER_USER_HANDLE))
                .thenReturn(true);
        mServiceContext.permissions.add(permission.REQUEST_PASSWORD_COMPLEXITY);
@@ -5721,6 +5733,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    }

    public void testGetPasswordComplexity_currentUserHasPassword() {
        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        when(getServices().packageManager.getPackagesForUid(DpmMockContext.CALLER_UID)).thenReturn(
                new String[0]);
        when(getServices().userManager.isUserUnlocked(DpmMockContext.CALLER_USER_HANDLE))
                .thenReturn(true);
        mServiceContext.permissions.add(permission.REQUEST_PASSWORD_COMPLEXITY);
@@ -5734,6 +5749,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    }

    public void testGetPasswordComplexity_unifiedChallengeReturnsParentUserPassword() {
        mContext.binder.callingUid = DpmMockContext.CALLER_UID;
        when(getServices().packageManager.getPackagesForUid(DpmMockContext.CALLER_UID)).thenReturn(
                new String[0]);
        when(getServices().userManager.isUserUnlocked(DpmMockContext.CALLER_USER_HANDLE))
                .thenReturn(true);
        mServiceContext.permissions.add(permission.REQUEST_PASSWORD_COMPLEXITY);