Loading services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +9 −1 Original line number Diff line number Diff line Loading @@ -96,6 +96,7 @@ import static android.app.admin.DevicePolicyManager.PROVISIONING_RESULT_REMOVE_N import static android.app.admin.DevicePolicyManager.PROVISIONING_RESULT_SETTING_PROFILE_OWNER_FAILED; import static android.app.admin.DevicePolicyManager.PROVISIONING_RESULT_SET_DEVICE_OWNER_FAILED; import static android.app.admin.DevicePolicyManager.PROVISIONING_RESULT_STARTING_PROFILE_FAILED; import static android.app.admin.DevicePolicyManager.STATE_USER_UNMANAGED; import static android.app.admin.DevicePolicyManager.WIPE_EUICC; import static android.app.admin.DevicePolicyManager.WIPE_EXTERNAL_STORAGE; import static android.app.admin.DevicePolicyManager.WIPE_RESET_PROTECTION_DATA; Loading Loading @@ -8735,7 +8736,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { final CallerIdentity caller = getCallerIdentity(); if (userHandle != mOwners.getDeviceOwnerUserId() && !mOwners.hasProfileOwner(userHandle) && getManagedUserId(userHandle) == -1) { && getManagedUserId(userHandle) == -1 && newState != STATE_USER_UNMANAGED) { // No managed device, user or profile, so setting provisioning state makes no sense. throw new IllegalStateException("Not allowed to change provisioning state unless a " + "device or profile owner is set."); Loading Loading @@ -8798,6 +8800,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { case DevicePolicyManager.STATE_USER_SETUP_FINALIZED: // Cannot transition out of finalized. break; case DevicePolicyManager.STATE_USER_PROFILE_FINALIZED: // Should only move to an unmanaged state after removing the work profile. if (newState == DevicePolicyManager.STATE_USER_UNMANAGED) { return; } break; } // Didn't meet any of the accepted state transition checks above, throw appropriate error. Loading services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -3178,6 +3178,16 @@ public class DevicePolicyManagerTest extends DpmTestBase { DevicePolicyManager.STATE_USER_UNMANAGED)); } @Test public void testSetUserProvisioningState_profileFinalized_canTransitionToUserUnmanaged() throws Exception { setupProfileOwner(); exerciseUserProvisioningTransitions(CALLER_USER_HANDLE, DevicePolicyManager.STATE_USER_PROFILE_FINALIZED, DevicePolicyManager.STATE_USER_UNMANAGED); } @Test public void testSetUserProvisioningState_illegalTransitionToAnotherInProgressState() throws Exception { Loading Loading
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +9 −1 Original line number Diff line number Diff line Loading @@ -96,6 +96,7 @@ import static android.app.admin.DevicePolicyManager.PROVISIONING_RESULT_REMOVE_N import static android.app.admin.DevicePolicyManager.PROVISIONING_RESULT_SETTING_PROFILE_OWNER_FAILED; import static android.app.admin.DevicePolicyManager.PROVISIONING_RESULT_SET_DEVICE_OWNER_FAILED; import static android.app.admin.DevicePolicyManager.PROVISIONING_RESULT_STARTING_PROFILE_FAILED; import static android.app.admin.DevicePolicyManager.STATE_USER_UNMANAGED; import static android.app.admin.DevicePolicyManager.WIPE_EUICC; import static android.app.admin.DevicePolicyManager.WIPE_EXTERNAL_STORAGE; import static android.app.admin.DevicePolicyManager.WIPE_RESET_PROTECTION_DATA; Loading Loading @@ -8735,7 +8736,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { final CallerIdentity caller = getCallerIdentity(); if (userHandle != mOwners.getDeviceOwnerUserId() && !mOwners.hasProfileOwner(userHandle) && getManagedUserId(userHandle) == -1) { && getManagedUserId(userHandle) == -1 && newState != STATE_USER_UNMANAGED) { // No managed device, user or profile, so setting provisioning state makes no sense. throw new IllegalStateException("Not allowed to change provisioning state unless a " + "device or profile owner is set."); Loading Loading @@ -8798,6 +8800,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { case DevicePolicyManager.STATE_USER_SETUP_FINALIZED: // Cannot transition out of finalized. break; case DevicePolicyManager.STATE_USER_PROFILE_FINALIZED: // Should only move to an unmanaged state after removing the work profile. if (newState == DevicePolicyManager.STATE_USER_UNMANAGED) { return; } break; } // Didn't meet any of the accepted state transition checks above, throw appropriate error. Loading
services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -3178,6 +3178,16 @@ public class DevicePolicyManagerTest extends DpmTestBase { DevicePolicyManager.STATE_USER_UNMANAGED)); } @Test public void testSetUserProvisioningState_profileFinalized_canTransitionToUserUnmanaged() throws Exception { setupProfileOwner(); exerciseUserProvisioningTransitions(CALLER_USER_HANDLE, DevicePolicyManager.STATE_USER_PROFILE_FINALIZED, DevicePolicyManager.STATE_USER_UNMANAGED); } @Test public void testSetUserProvisioningState_illegalTransitionToAnotherInProgressState() throws Exception { Loading