From 3c4b81418972f7c8e2d61e83eeeaec61ea29fc0b Mon Sep 17 00:00:00 2001 From: kholoud mohamed Date: Wed, 10 Mar 2021 13:57:16 +0000 Subject: Allow forceUpdateUserSetupComplete on user builds This fixes some failing cts tests running on user builds. Test: atest android.devicepolicy.cts.DevicePolicyManagerTest Fixes: 181567444 Change-Id: I07c3a98fcbe79d41fb224967569b877eefbc593c --- .../android/app/admin/DevicePolicyManager.java | 2 +- .../devicepolicy/DevicePolicyManagerService.java | 4 --- .../devicepolicy/DevicePolicyManagerTest.java | 30 +--------------------- 3 files changed, 2 insertions(+), 34 deletions(-) diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index b919bfc92e79..75fda47f4081 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -11769,7 +11769,7 @@ public class DevicePolicyManager { /** * @hide - * Force update user setup completed status. This API has no effect on user build. + * Force update user setup completed status. * @throws {@link SecurityException} if the caller has no * {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is * not {@link UserHandle#SYSTEM_USER} diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 28e9acf8d883..fbb8988de2b8 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -14101,10 +14101,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { hasCallingOrSelfPermission(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)); enforceCallerSystemUserHandle(); - // no effect if it's called from user build - if (!mInjector.isBuildDebuggable()) { - return; - } final int userId = UserHandle.USER_SYSTEM; boolean isUserCompleted = mInjector.settingsSecureGetIntForUser( Settings.Secure.USER_SETUP_COMPLETE, 0, userId) != 0; 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 87100a63e35e..89435e9a8862 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java @@ -3875,7 +3875,7 @@ public class DevicePolicyManagerTest extends DpmTestBase { } @Test - public void testForceUpdateUserSetupComplete_userbuild() { + public void testForceUpdateUserSetupComplete_forcesUpdate() { mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID; @@ -3888,34 +3888,6 @@ public class DevicePolicyManagerTest extends DpmTestBase { userData.mUserSetupComplete = true; dpms.mUserData.put(UserHandle.USER_SYSTEM, userData); - // GIVEN it's user build - getServices().buildMock.isDebuggable = false; - - assertThat(dpms.hasUserSetupCompleted()).isTrue(); - - dpm.forceUpdateUserSetupComplete(); - - // THEN the state in dpms is not changed - assertThat(dpms.hasUserSetupCompleted()).isTrue(); - } - - @Test - public void testForceUpdateUserSetupComplete_userDebugbuild() { - mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS); - mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID; - - final int userId = UserHandle.USER_SYSTEM; - // GIVEN userComplete is false in SettingsProvider - setUserSetupCompleteForUser(false, userId); - - // GIVEN userComplete is true in DPM - DevicePolicyData userData = new DevicePolicyData(userId); - userData.mUserSetupComplete = true; - dpms.mUserData.put(UserHandle.USER_SYSTEM, userData); - - // GIVEN it's userdebug build - getServices().buildMock.isDebuggable = true; - assertThat(dpms.hasUserSetupCompleted()).isTrue(); dpm.forceUpdateUserSetupComplete(); -- cgit v1.2.3-59-g8ed1b