From bc5da644dd9d884d7ec7b4fa20be25880e1a7e0e Mon Sep 17 00:00:00 2001 From: Rubin Xu Date: Mon, 18 Jan 2021 23:12:08 +0000 Subject: [PATCH] Add metrics for EXTRA_KEY_DEVICE_PASSWORD_REQUIREMENT_ONLY Bug: 169832516 Test: m RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.password Change-Id: I2bcd6c4f1a5f04582bb88ec9fb285621b9ec77eb --- .../settings/password/SetNewPasswordActivity.java | 9 ++++++++- .../settings/password/SetNewPasswordActivityTest.java | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/password/SetNewPasswordActivity.java b/src/com/android/settings/password/SetNewPasswordActivity.java index bd7b14d4b25..87411751bff 100644 --- a/src/com/android/settings/password/SetNewPasswordActivity.java +++ b/src/com/android/settings/password/SetNewPasswordActivity.java @@ -162,6 +162,13 @@ public class SetNewPasswordActivity extends Activity implements SetNewPasswordCo ? getIntent().getIntExtra(EXTRA_PASSWORD_COMPLEXITY, PASSWORD_COMPLEXITY_NONE) : Integer.MIN_VALUE; + final boolean extraDevicePasswordRequirementOnly = getIntent().getBooleanExtra( + EXTRA_DEVICE_PASSWORD_REQUIREMENT_ONLY, false); + + // Use 30th bit to encode extraDevicePasswordRequirementOnly, since the top bit (31th bit) + // encodes whether EXTRA_PASSWORD_COMPLEXITY has been absent. + final int logValue = extraPasswordComplexity + | (extraDevicePasswordRequirementOnly ? 1 << 30 : 0); // this activity is launched by either ACTION_SET_NEW_PASSWORD or // ACTION_SET_NEW_PARENT_PROFILE_PASSWORD final int action = ACTION_SET_NEW_PASSWORD.equals(mNewPasswordAction) @@ -175,6 +182,6 @@ public class SetNewPasswordActivity extends Activity implements SetNewPasswordCo action, SettingsEnums.SET_NEW_PASSWORD_ACTIVITY, callingAppPackageName, - extraPasswordComplexity); + logValue); } } diff --git a/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java b/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java index a5bc845375a..79d4b6b65f6 100644 --- a/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java +++ b/tests/robotests/src/com/android/settings/password/SetNewPasswordActivityTest.java @@ -315,6 +315,7 @@ public class SetNewPasswordActivityTest { @Test @Config(shadows = {ShadowPasswordUtils.class}) public void launchChooseLock_setNewParentProfilePassword_DevicePasswordRequirementExtra() { + ShadowPasswordUtils.setCallingAppPackageName(PKG_NAME); Settings.Global.putInt(RuntimeEnvironment.application.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1); @@ -328,6 +329,12 @@ public class SetNewPasswordActivityTest { assertThat(actualIntent.getBooleanExtra( EXTRA_KEY_DEVICE_PASSWORD_REQUIREMENT_ONLY, false)).isTrue(); + verify(mockMetricsProvider).action( + SettingsEnums.PAGE_UNKNOWN, + SettingsEnums.ACTION_SET_NEW_PARENT_PROFILE_PASSWORD, + SettingsEnums.SET_NEW_PASSWORD_ACTIVITY, + PKG_NAME, + Integer.MIN_VALUE | (1 << 30)); } @Test