Ask profile password before unifying to prevent untrusted reset

Test: make -j RunSettingsRoboTests
Test: manual, unify when profile lock is compliant
Test: manual, unify when profile lock is not compliant
Test: manual, unify when profile lock is empty
Fixes: 110262879

Change-Id: I0dfa885f2a0e44e09c217b3e7766b367f1340c9e
This commit is contained in:
Pavel Grafov
2018-06-20 17:20:05 +01:00
parent 8700777839
commit 80d9020cc2
4 changed files with 82 additions and 59 deletions

View File

@@ -17,11 +17,11 @@
package com.android.settings.security;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.UserHandle;
import android.os.UserManager;
import com.android.internal.widget.LockPatternUtils;
@@ -35,7 +35,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -54,7 +53,6 @@ public class LockUnificationPreferenceControllerTest {
@Mock
private SecuritySettings mHost;
private FakeFeatureFactory mFeatureFactory;
private Context mContext;
private LockUnificationPreferenceController mController;
private Preference mPreference;
@@ -66,10 +64,12 @@ public class LockUnificationPreferenceControllerTest {
ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {FAKE_PROFILE_USER_ID});
mFeatureFactory = FakeFeatureFactory.setupForTest();
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
when(featureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
.thenReturn(mLockPatternUtils);
}
private void init() {
mController = new LockUnificationPreferenceController(mContext, mHost);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mPreference = new Preference(mContext);
@@ -77,7 +77,8 @@ public class LockUnificationPreferenceControllerTest {
@Test
public void isAvailable_noProfile_false() {
ReflectionHelpers.setField(mController, "mProfileChallengeUserId", UserHandle.USER_NULL);
when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[0]);
init();
assertThat(mController.isAvailable()).isFalse();
}
@@ -85,6 +86,7 @@ public class LockUnificationPreferenceControllerTest {
@Test
public void isAvailable_separateChallengeNotAllowed_false() {
when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(false);
init();
assertThat(mController.isAvailable()).isFalse();
}
@@ -92,6 +94,7 @@ public class LockUnificationPreferenceControllerTest {
@Test
public void isAvailable_separateChallengeAllowed_true() {
when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(true);
init();
assertThat(mController.isAvailable()).isTrue();
}