Screen lock type metrics are not reported if user goes back

bug: 63116381
Test: Manually tested and verified that metrics are passed back to
setupwizard. Also added robolectric tests
Change-Id: I9d095754addc34121a2a0a12b3e5d1479ff15a78
This commit is contained in:
Ajay Nadathur
2017-07-05 13:17:30 -07:00
parent 24ba2fbdb9
commit 3d9fffed16
3 changed files with 156 additions and 11 deletions

View File

@@ -29,6 +29,7 @@ import android.widget.Button;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.password.SetupChooseLockGeneric.SetupChooseLockGenericFragment;
import com.android.settings.password.SetupSkipDialog;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
@@ -105,6 +106,89 @@ public class SetupFingerprintEnrollIntroductionTest {
.isEqualTo(FingerprintEnrollBase.RESULT_SKIP);
}
@Test
public void testBackKeyPress_shouldSetIntentDataIfLockScreenAdded() {
getShadowKeyguardManager().setIsKeyguardSecure(false);
mController.create().resume();
getShadowKeyguardManager().setIsKeyguardSecure(true);
SetupFingerprintEnrollIntroduction activity = mController.get();
activity.onBackPressed();
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
assertThat(shadowActivity.getResultIntent()).isNotNull();
assertThat(shadowActivity.getResultIntent().hasExtra(
SetupChooseLockGenericFragment.EXTRA_PASSWORD_QUALITY)).isTrue();
}
@Test
public void testBackKeyPress_shouldNotSetIntentDataIfLockScreenPresentBeforeLaunch() {
getShadowKeyguardManager().setIsKeyguardSecure(true);
mController.create().resume();
SetupFingerprintEnrollIntroduction activity = mController.get();
activity.onBackPressed();
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
assertThat(shadowActivity.getResultIntent()).isNull();
}
@Test
public void testCancelClicked_shouldSetIntentDataIfLockScreenAdded() {
getShadowKeyguardManager().setIsKeyguardSecure(false);
SetupFingerprintEnrollIntroduction activity = mController.create().resume().get();
final Button skipButton = activity.findViewById(R.id.fingerprint_cancel_button);
getShadowKeyguardManager().setIsKeyguardSecure(true);
skipButton.performClick();
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
assertThat(shadowActivity.getResultIntent()).isNotNull();
assertThat(shadowActivity.getResultIntent().hasExtra(
SetupChooseLockGenericFragment.EXTRA_PASSWORD_QUALITY)).isTrue();
}
@Test
public void testCancelClicked_shouldNotSetIntentDataIfLockScreenPresentBeforeLaunch() {
getShadowKeyguardManager().setIsKeyguardSecure(true);
SetupFingerprintEnrollIntroduction activity = mController.create().resume().get();
final Button skipButton = activity.findViewById(R.id.fingerprint_cancel_button);
skipButton.performClick();
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
assertThat(shadowActivity.getResultIntent()).isNull();
}
@Test
public void testOnResultFromFindSensor_shouldNotSetIntentDataIfLockScreenPresentBeforeLaunch() {
getShadowKeyguardManager().setIsKeyguardSecure(true);
SetupFingerprintEnrollIntroduction activity = mController.create().resume().get();
activity.onActivityResult(FingerprintEnrollIntroduction.FINGERPRINT_FIND_SENSOR_REQUEST,
FingerprintEnrollBase.RESULT_FINISHED, null);
assertThat(Shadows.shadowOf(activity).getResultIntent()).isNull();
}
@Test
public void testOnResultFromFindSensor_shouldSetIntentDataIfLockScreenAdded() {
getShadowKeyguardManager().setIsKeyguardSecure(false);
SetupFingerprintEnrollIntroduction activity = mController.create().resume().get();
getShadowKeyguardManager().setIsKeyguardSecure(true);
activity.onActivityResult(FingerprintEnrollIntroduction.FINGERPRINT_FIND_SENSOR_REQUEST,
FingerprintEnrollBase.RESULT_FINISHED, null);
assertThat(Shadows.shadowOf(activity).getResultIntent()).isNotNull();
}
@Test
public void testOnResultFromFindSensor_shouldNotSetIntentDataIfLockScreenNotAdded() {
getShadowKeyguardManager().setIsKeyguardSecure(false);
SetupFingerprintEnrollIntroduction activity = mController.create().resume().get();
activity.onActivityResult(FingerprintEnrollIntroduction.FINGERPRINT_FIND_SENSOR_REQUEST,
FingerprintEnrollBase.RESULT_FINISHED, null);
assertThat(Shadows.shadowOf(activity).getResultIntent()).isNull();
}
private ShadowKeyguardManager getShadowKeyguardManager() {
return Shadows.shadowOf(application.getSystemService(KeyguardManager.class));
}

View File

@@ -19,12 +19,14 @@ package com.android.settings.testutils.shadow;
import android.app.admin.DevicePolicyManager;
import com.android.internal.widget.LockPatternUtils;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(LockPatternUtils.class)
public class ShadowLockPatternUtils {
private int mPasswordQuality = 1;
@Implementation
public boolean isSecure(int id) {
return true;
@@ -34,4 +36,19 @@ public class ShadowLockPatternUtils {
public int getActivePasswordQuality(int userId) {
return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
}
@Implementation
public int getKeyguardStoredPasswordQuality(int userHandle) {
return mPasswordQuality;
}
// Non-Android accessor.
public int getPasswordQuality() {
return mPasswordQuality;
}
// Non-Android accessor.
public void setPasswordQuality(int passwordQuality) {
mPasswordQuality = passwordQuality;
}
}