From cd5bb5beb722419a63aa8ae92b6662ca96be011e Mon Sep 17 00:00:00 2001 From: Alex Johnston Date: Thu, 19 Mar 2020 18:50:19 +0000 Subject: [PATCH] Clean up logs in DevicePolicyManagerTest * Added a test method to get the device owner in DevicePolicyManagerTest (which does not hold the DPMS lock). dpms.getDeviceOwnerAdminLocked() is no longer called from the test. Bug: 149456557 Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest Change-Id: I890e560b60c1d12674d2aec364660eacb5ca8762 --- .../devicepolicy/DevicePolicyManagerTest.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java index d038d6c1ca7ff..94ac36af73051 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java @@ -1405,8 +1405,8 @@ public class DevicePolicyManagerTest extends DpmTestBase { assertEquals(admin2, dpms.getDeviceOwnerComponent(/* callingUserOnly =*/ false)); // Then check getDeviceOwnerAdminLocked(). - assertEquals(admin2, dpms.getDeviceOwnerAdminLocked().info.getComponent()); - assertEquals(DpmMockContext.CALLER_UID, dpms.getDeviceOwnerAdminLocked().getUid()); + assertEquals(admin2, getDeviceOwner().info.getComponent()); + assertEquals(DpmMockContext.CALLER_UID, getDeviceOwner().getUid()); } /** @@ -1759,7 +1759,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { DpmTestUtils.assertRestrictions( DpmTestUtils.newRestrictions( UserManager.DISALLOW_ADD_USER, UserManager.DISALLOW_OUTGOING_CALLS), - dpms.getDeviceOwnerAdminLocked().ensureUserRestrictions() + getDeviceOwner().ensureUserRestrictions() ); DpmTestUtils.assertRestrictions( DpmTestUtils.newRestrictions( @@ -1776,7 +1776,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { DpmTestUtils.assertRestrictions( DpmTestUtils.newRestrictions(UserManager.DISALLOW_OUTGOING_CALLS), - dpms.getDeviceOwnerAdminLocked().ensureUserRestrictions() + getDeviceOwner().ensureUserRestrictions() ); DpmTestUtils.assertRestrictions( DpmTestUtils.newRestrictions(UserManager.DISALLOW_OUTGOING_CALLS), @@ -1834,6 +1834,18 @@ public class DevicePolicyManagerTest extends DpmTestBase { reset(getServices().userManagerInternal); } + private DevicePolicyManagerService.ActiveAdmin getDeviceOwner() { + ComponentName component = dpms.mOwners.getDeviceOwnerComponent(); + DevicePolicyManagerService.DevicePolicyData policy = + dpms.getUserData(dpms.mOwners.getDeviceOwnerUserId()); + for (DevicePolicyManagerService.ActiveAdmin admin : policy.mAdminList) { + if (component.equals(admin.info.getComponent())) { + return admin; + } + } + return null; + } + public void testDaDisallowedPolicies_SecurityException() throws Exception { mContext.callerPermissions.add(permission.MANAGE_DEVICE_ADMINS); mContext.callerPermissions.add(permission.INTERACT_ACROSS_USERS_FULL); @@ -2067,7 +2079,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { private void assertNoDeviceOwnerRestrictions() { DpmTestUtils.assertRestrictions( DpmTestUtils.newRestrictions(), - dpms.getDeviceOwnerAdminLocked().ensureUserRestrictions() + getDeviceOwner().ensureUserRestrictions() ); DpmTestUtils.assertRestrictions( DpmTestUtils.newRestrictions(),