Merge "CTS test to verify work profile unlocks successfully"
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
index 8eb8009..2cb7b16 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
@@ -1231,7 +1231,7 @@
             return;
         }
 
-        // Freshly created profile profile has no separate challenge.
+        // Freshly created profile has no separate challenge.
         verifyUnifiedPassword(true);
 
         // Set separate challenge and verify that the API reports it correctly.
@@ -1239,6 +1239,28 @@
         verifyUnifiedPassword(false);
     }
 
+    public void testUnlockWorkProfile_deviceWidePassword() throws Exception{
+        if (!mHasFeature) {
+            return;
+        }
+        String password = "0000";
+        try {
+            // Add a device password after the work profile has been created.
+            changeUserCredential(password, /* oldCredential= */ null, mPrimaryUserId);
+            // Lock the profile with key eviction.
+            lockProfile();
+            // Turn on work profile, by unlocking the profile with the device password.
+            verifyUserCredential(password, mPrimaryUserId);
+
+            // Verify profile user is running unlocked by running a sanity test on the work profile.
+            installAppAsUser(SIMPLE_APP_APK, mProfileUserId);
+            runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".SanityTest", mProfileUserId);
+        } finally {
+            // Clean up
+            changeUserCredential(/* newCredential= */ null, password, mPrimaryUserId);
+        }
+    }
+
     public void testRebootDevice_unifiedPassword() throws Exception {
         if (!mHasFeature) {
             return;