Improve work profile unification flow

When unifying work profile challenge, keep the device lock
as long as it will still meet password requirement after unification.
If not, prompt the user to set a new device lock and only unify
work challenge after a compliant device lock is set.

Bug: 148630506
Fix: 149682344
Test: make RunSettingsRoboTests
ROBOTEST_FILTER='ChooseLockGenericTest|ChooseLockPasswordTest|ChooseLockPatternTest|LockUnificationPreferenceControllerTest'

Change-Id: I99cde2650902927f6a4cc7c0cc7c6016e0dc283f
This commit is contained in:
Rubin Xu
2020-04-02 16:29:36 +01:00
parent e1839d2955
commit f535e87e51
10 changed files with 279 additions and 93 deletions

View File

@@ -35,12 +35,14 @@ import static org.robolectric.Shadows.shadowOf;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings.Global;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import com.android.internal.widget.LockPatternUtils;
import com.android.internal.widget.LockscreenCredential;
import com.android.settings.R;
import com.android.settings.biometrics.BiometricEnrollBase;
import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
@@ -312,6 +314,56 @@ public class ChooseLockGenericTest {
.isEqualTo("app name");
}
@Test
public void testUnifyProfile_IntentPassedToChooseLockPassword() {
final Bundle arguments = new Bundle();
arguments.putInt(ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_ID, 11);
arguments.putParcelable(ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_CREDENTIAL,
LockscreenCredential.createNone());
mFragment.setArguments(arguments);
Intent intent = new Intent().putExtra(
LockPatternUtils.PASSWORD_TYPE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_NUMERIC);
initActivity(intent);
mFragment.updatePreferencesOrFinish(false /* isRecreatingActivity */);
Intent nextIntent = shadowOf(mActivity).getNextStartedActivity();
assertThat(nextIntent).isNotNull();
assertThat(nextIntent.getComponent().getClassName()).isEqualTo(
ChooseLockPassword.class.getName());
assertThat(nextIntent.getIntExtra(
ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_ID, 0)).isEqualTo(11);
assertThat((LockscreenCredential) nextIntent.getParcelableExtra(
ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_CREDENTIAL)).isNotNull();
}
@Test
public void testUnifyProfile_IntentPassedToChooseLockPattern() {
final Bundle arguments = new Bundle();
arguments.putInt(ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_ID, 13);
arguments.putParcelable(ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_CREDENTIAL,
LockscreenCredential.createNone());
mFragment.setArguments(arguments);
Intent intent = new Intent().putExtra(
LockPatternUtils.PASSWORD_TYPE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
initActivity(intent);
mFragment.updatePreferencesOrFinish(false /* isRecreatingActivity */);
Intent nextIntent = shadowOf(mActivity).getNextStartedActivity();
assertThat(nextIntent).isNotNull();
assertThat(nextIntent.getComponent().getClassName()).isEqualTo(
ChooseLockPattern.class.getName());
assertThat(nextIntent.getIntExtra(
ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_ID, 0)).isEqualTo(13);
assertThat((LockscreenCredential) nextIntent.getParcelableExtra(
ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_CREDENTIAL)).isNotNull();
}
private void initActivity(@Nullable Intent intent) {
if (intent == null) {
intent = new Intent();

View File

@@ -147,6 +147,21 @@ public class ChooseLockPasswordTest {
assertThat(intent.hasExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY)).isFalse();
}
@Test
public void intentBuilder_setProfileToUnify_shouldAddExtras() {
Intent intent = new IntentBuilder(application)
.setProfileToUnify(23, LockscreenCredential.createNone())
.build();
assertThat(intent.getIntExtra(ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_ID, 0))
.named("EXTRA_KEY_UNIFICATION_PROFILE_ID")
.isEqualTo(23);
assertThat((LockscreenCredential) intent.getParcelableExtra(
ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_CREDENTIAL))
.named("EXTRA_KEY_UNIFICATION_PROFILE_CREDENTIAL")
.isNotNull();
}
@Test
public void processAndValidatePasswordRequirements_noMinPasswordComplexity() {
mShadowDpm.setPasswordQuality(PASSWORD_QUALITY_ALPHABETIC);

View File

@@ -92,6 +92,21 @@ public class ChooseLockPatternTest {
.isEqualTo(123);
}
@Test
public void intentBuilder_setProfileToUnify_shouldAddExtras() {
Intent intent = new IntentBuilder(application)
.setProfileToUnify(23, LockscreenCredential.createNone())
.build();
assertThat(intent.getIntExtra(ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_ID, 0))
.named("EXTRA_KEY_UNIFICATION_PROFILE_ID")
.isEqualTo(23);
assertThat((LockscreenCredential) intent.getParcelableExtra(
ChooseLockSettingsHelper.EXTRA_KEY_UNIFICATION_PROFILE_CREDENTIAL))
.named("EXTRA_KEY_UNIFICATION_PROFILE_CREDENTIAL")
.isNotNull();
}
@Config(qualifiers = "sw400dp")
@Test
public void fingerprintExtraSet_shouldDisplayFingerprintIcon() {