Merge "Fix "max failed login attempts" disclosure" into oc-dr1-dev
diff --git a/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java b/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java
index babf90e..8605b2e 100644
--- a/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java
+++ b/src/com/android/settings/enterprise/DevicePolicyManagerWrapper.java
@@ -45,6 +45,13 @@
     int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle);
 
     /**
+     * Calls {@code DevicePolicyManager.getDeviceOwnerComponentOnCallingUser()}.
+     *
+     * @see android.app.admin.DevicePolicyManager#getDeviceOwnerComponentOnCallingUser
+     */
+    ComponentName getDeviceOwnerComponentOnCallingUser();
+
+    /**
      * Calls {@code DevicePolicyManager.getDeviceOwnerComponentOnAnyUser()}.
      *
      * @see android.app.admin.DevicePolicyManager#getDeviceOwnerComponentOnAnyUser
diff --git a/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java b/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java
index 7906310..e11aaf6 100644
--- a/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java
+++ b/src/com/android/settings/enterprise/DevicePolicyManagerWrapperImpl.java
@@ -42,6 +42,11 @@
     }
 
     @Override
+    public ComponentName getDeviceOwnerComponentOnCallingUser() {
+        return mDpm.getDeviceOwnerComponentOnCallingUser();
+    }
+
+    @Override
     public ComponentName getDeviceOwnerComponentOnAnyUser() {
         return mDpm.getDeviceOwnerComponentOnAnyUser();
     }
diff --git a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
index 46ecb7e..a5e2f3c 100644
--- a/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
+++ b/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java
@@ -158,11 +158,14 @@
 
     @Override
     public int getMaximumFailedPasswordsBeforeWipeInCurrentUser() {
-        final ComponentName profileOwner = mDpm.getProfileOwnerAsUser(MY_USER_ID);
-        if (profileOwner == null) {
+        ComponentName owner = mDpm.getDeviceOwnerComponentOnCallingUser();
+        if (owner == null) {
+            owner = mDpm.getProfileOwnerAsUser(MY_USER_ID);
+        }
+        if (owner == null) {
             return 0;
         }
-        return mDpm.getMaximumFailedPasswordsForWipe(profileOwner, MY_USER_ID);
+        return mDpm.getMaximumFailedPasswordsForWipe(owner, MY_USER_ID);
     }
 
     @Override
diff --git a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
index d506a8e..474b278 100644
--- a/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImplTest.java
@@ -231,6 +231,7 @@
 
     @Test
     public void testGetMaximumFailedPasswordsForWipeInCurrentUser() {
+        when(mDevicePolicyManager.getDeviceOwnerComponentOnCallingUser()).thenReturn(null);
         when(mDevicePolicyManager.getProfileOwnerAsUser(MY_USER_ID)).thenReturn(null);
         when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, MY_USER_ID))
                 .thenReturn(10);
@@ -238,6 +239,10 @@
 
         when(mDevicePolicyManager.getProfileOwnerAsUser(MY_USER_ID)).thenReturn(OWNER);
         assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInCurrentUser()).isEqualTo(10);
+
+        when(mDevicePolicyManager.getDeviceOwnerComponentOnCallingUser()).thenReturn(OWNER);
+        when(mDevicePolicyManager.getProfileOwnerAsUser(MY_USER_ID)).thenReturn(null);
+        assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInCurrentUser()).isEqualTo(10);
     }
 
     @Test