Distinguish multiple PendingIntents via requestCode am: 25686219d3

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/19289844

Change-Id: Id8509feac060578cf8d7ffb4d7a7b9def221f029
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Simon Wingrove
2022-07-18 19:19:15 +00:00
committed by Automerger Merge Worker
3 changed files with 55 additions and 27 deletions

View File

@@ -39,6 +39,9 @@ import com.android.settingslib.RestrictedLockUtils;
public final class BiometricsSafetySource { public final class BiometricsSafetySource {
public static final String SAFETY_SOURCE_ID = "AndroidBiometrics"; public static final String SAFETY_SOURCE_ID = "AndroidBiometrics";
private static final int REQUEST_CODE_COMBINED_BIOMETRIC_SETTING = 10;
private static final int REQUEST_CODE_FACE_SETTING = 20;
private static final int REQUEST_CODE_FINGERPRINT_SETTING = 30;
private BiometricsSafetySource() { private BiometricsSafetySource() {
} }
@@ -62,9 +65,11 @@ public final class BiometricsSafetySource {
setBiometricSafetySourceData(context, setBiometricSafetySourceData(context,
context.getString(R.string.security_settings_biometric_preference_title), context.getString(R.string.security_settings_biometric_preference_title),
combinedBiometricStatusUtils.getSummary(), combinedBiometricStatusUtils.getSummary(),
createPendingIntent(context,
biometricNavigationUtils.getBiometricSettingsIntent(context, biometricNavigationUtils.getBiometricSettingsIntent(context,
combinedBiometricStatusUtils.getSettingsClassName(), disablingAdmin, combinedBiometricStatusUtils.getSettingsClassName(),
Bundle.EMPTY), disablingAdmin, Bundle.EMPTY),
REQUEST_CODE_COMBINED_BIOMETRIC_SETTING),
disablingAdmin == null /* enabled */, disablingAdmin == null /* enabled */,
combinedBiometricStatusUtils.hasEnrolled(), combinedBiometricStatusUtils.hasEnrolled(),
safetyEvent); safetyEvent);
@@ -80,9 +85,11 @@ public final class BiometricsSafetySource {
setBiometricSafetySourceData(context, setBiometricSafetySourceData(context,
context.getString(R.string.security_settings_face_preference_title), context.getString(R.string.security_settings_face_preference_title),
faceStatusUtils.getSummary(), faceStatusUtils.getSummary(),
createPendingIntent(context,
biometricNavigationUtils.getBiometricSettingsIntent(context, biometricNavigationUtils.getBiometricSettingsIntent(context,
faceStatusUtils.getSettingsClassName(), disablingAdmin, faceStatusUtils.getSettingsClassName(), disablingAdmin,
Bundle.EMPTY), Bundle.EMPTY),
REQUEST_CODE_FACE_SETTING),
disablingAdmin == null /* enabled */, disablingAdmin == null /* enabled */,
faceStatusUtils.hasEnrolled(), faceStatusUtils.hasEnrolled(),
safetyEvent); safetyEvent);
@@ -100,9 +107,11 @@ public final class BiometricsSafetySource {
setBiometricSafetySourceData(context, setBiometricSafetySourceData(context,
context.getString(R.string.security_settings_fingerprint_preference_title), context.getString(R.string.security_settings_fingerprint_preference_title),
fingerprintStatusUtils.getSummary(), fingerprintStatusUtils.getSummary(),
createPendingIntent(context,
biometricNavigationUtils.getBiometricSettingsIntent(context, biometricNavigationUtils.getBiometricSettingsIntent(context,
fingerprintStatusUtils.getSettingsClassName(), disablingAdmin, fingerprintStatusUtils.getSettingsClassName(), disablingAdmin,
Bundle.EMPTY), Bundle.EMPTY),
REQUEST_CODE_FINGERPRINT_SETTING),
disablingAdmin == null /* enabled */, disablingAdmin == null /* enabled */,
fingerprintStatusUtils.hasEnrolled(), fingerprintStatusUtils.hasEnrolled(),
safetyEvent); safetyEvent);
@@ -118,8 +127,8 @@ public final class BiometricsSafetySource {
} }
private static void setBiometricSafetySourceData(Context context, String title, String summary, private static void setBiometricSafetySourceData(Context context, String title, String summary,
Intent clickIntent, boolean enabled, boolean hasEnrolled, SafetyEvent safetyEvent) { PendingIntent pendingIntent, boolean enabled, boolean hasEnrolled,
final PendingIntent pendingIntent = createPendingIntent(context, clickIntent); SafetyEvent safetyEvent) {
final int severityLevel = final int severityLevel =
enabled && hasEnrolled ? SafetySourceData.SEVERITY_LEVEL_INFORMATION enabled && hasEnrolled ? SafetySourceData.SEVERITY_LEVEL_INFORMATION
: SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED; : SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
@@ -133,11 +142,12 @@ public final class BiometricsSafetySource {
context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent); context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent);
} }
private static PendingIntent createPendingIntent(Context context, Intent intent) { private static PendingIntent createPendingIntent(Context context, Intent intent,
int requestCode) {
return PendingIntent return PendingIntent
.getActivity( .getActivity(
context, context,
0 /* requestCode */, requestCode,
intent, intent,
PendingIntent.FLAG_IMMUTABLE); PendingIntent.FLAG_IMMUTABLE);
} }

View File

@@ -42,6 +42,9 @@ public final class LockScreenSafetySource {
public static final String NO_SCREEN_LOCK_ISSUE_TYPE_ID = "NoScreenLockIssueType"; public static final String NO_SCREEN_LOCK_ISSUE_TYPE_ID = "NoScreenLockIssueType";
public static final String SET_SCREEN_LOCK_ACTION_ID = "SetScreenLockAction"; public static final String SET_SCREEN_LOCK_ACTION_ID = "SetScreenLockAction";
private static final int REQUEST_CODE_SCREEN_LOCK = 1;
private static final int REQUEST_CODE_SCREEN_LOCK_SETTINGS = 2;
private LockScreenSafetySource() { private LockScreenSafetySource() {
} }
@@ -62,7 +65,7 @@ public final class LockScreenSafetySource {
.checkIfPasswordQualityIsSet(context, userId); .checkIfPasswordQualityIsSet(context, userId);
final PendingIntent pendingIntent = createPendingIntent(context, final PendingIntent pendingIntent = createPendingIntent(context,
screenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent( screenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent(
SettingsEnums.SAFETY_CENTER)); SettingsEnums.SAFETY_CENTER), REQUEST_CODE_SCREEN_LOCK);
final IconAction gearMenuIconAction = createGearMenuIconAction(context, final IconAction gearMenuIconAction = createGearMenuIconAction(context,
screenLockPreferenceDetailsUtils); screenLockPreferenceDetailsUtils);
final boolean enabled = final boolean enabled =
@@ -114,15 +117,17 @@ public final class LockScreenSafetySource {
IconAction.ICON_TYPE_GEAR, IconAction.ICON_TYPE_GEAR,
createPendingIntent(context, createPendingIntent(context,
screenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent( screenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent(
SettingsEnums.SAFETY_CENTER))) SettingsEnums.SAFETY_CENTER),
REQUEST_CODE_SCREEN_LOCK_SETTINGS))
: null; : null;
} }
private static PendingIntent createPendingIntent(Context context, Intent intent) { private static PendingIntent createPendingIntent(Context context, Intent intent,
int requestCode) {
return PendingIntent return PendingIntent
.getActivity( .getActivity(
context, context,
0 /* requestCode */, requestCode,
intent, intent,
PendingIntent.FLAG_IMMUTABLE); PendingIntent.FLAG_IMMUTABLE);
} }

View File

@@ -55,8 +55,10 @@ import org.mockito.MockitoAnnotations;
public class LockScreenSafetySourceTest { public class LockScreenSafetySourceTest {
private static final String SUMMARY = "summary"; private static final String SUMMARY = "summary";
private static final String FAKE_ACTION_CHOOSE_LOCK_GENERIC_FRAGMENT = "choose_lock_generic"; private static final String FAKE_ACTION_OPEN_SUB_SETTING = "open_sub_setting";
private static final String FAKE_ACTION_SCREEN_LOCK_SETTINGS = "screen_lock_settings"; private static final String EXTRA_DESTINATION = "destination";
private static final String FAKE_CHOOSE_LOCK_GENERIC_FRAGMENT = "choose_lock_generic";
private static final String FAKE_SCREEN_LOCK_SETTINGS = "screen_lock_settings";
private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED = private static final SafetyEvent EVENT_SOURCE_STATE_CHANGED =
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build(); new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
@@ -157,7 +159,10 @@ public class LockScreenSafetySourceTest {
.isEqualTo(SUMMARY); .isEqualTo(SUMMARY);
assertThat(safetySourceStatus.getPendingIntent().getIntent()).isNotNull(); assertThat(safetySourceStatus.getPendingIntent().getIntent()).isNotNull();
assertThat(safetySourceStatus.getPendingIntent().getIntent().getAction()) assertThat(safetySourceStatus.getPendingIntent().getIntent().getAction())
.isEqualTo(FAKE_ACTION_CHOOSE_LOCK_GENERIC_FRAGMENT); .isEqualTo(FAKE_ACTION_OPEN_SUB_SETTING);
assertThat(
safetySourceStatus.getPendingIntent().getIntent().getStringExtra(EXTRA_DESTINATION))
.isEqualTo(FAKE_CHOOSE_LOCK_GENERIC_FRAGMENT);
} }
@Test @Test
@@ -300,7 +305,9 @@ public class LockScreenSafetySourceTest {
ResourcesUtils.getResourcesString(mApplicationContext, ResourcesUtils.getResourcesString(mApplicationContext,
"no_screen_lock_issue_action_label")); "no_screen_lock_issue_action_label"));
assertThat(action.getPendingIntent().getIntent().getAction()) assertThat(action.getPendingIntent().getIntent().getAction())
.isEqualTo(FAKE_ACTION_CHOOSE_LOCK_GENERIC_FRAGMENT); .isEqualTo(FAKE_ACTION_OPEN_SUB_SETTING);
assertThat(action.getPendingIntent().getIntent().getStringExtra(EXTRA_DESTINATION))
.isEqualTo(FAKE_CHOOSE_LOCK_GENERIC_FRAGMENT);
} }
@Test @Test
@@ -383,9 +390,6 @@ public class LockScreenSafetySourceTest {
public void setSafetySourceData_whenShouldShowGearMenu_setGearMenuActionIcon() { public void setSafetySourceData_whenShouldShowGearMenu_setGearMenuActionIcon() {
whenScreenLockIsEnabled(); whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
final Intent launchScreenLockSettings = new Intent(FAKE_ACTION_SCREEN_LOCK_SETTINGS);
when(mScreenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent(anyInt()))
.thenReturn(launchScreenLockSettings);
when(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).thenReturn(true); when(mScreenLockPreferenceDetailsUtils.shouldShowGearMenu()).thenReturn(true);
LockScreenSafetySource.setSafetySourceData(mApplicationContext, LockScreenSafetySource.setSafetySourceData(mApplicationContext,
@@ -399,7 +403,10 @@ public class LockScreenSafetySourceTest {
assertThat(iconAction.getIconType()).isEqualTo(IconAction.ICON_TYPE_GEAR); assertThat(iconAction.getIconType()).isEqualTo(IconAction.ICON_TYPE_GEAR);
assertThat(iconAction.getPendingIntent().getIntent().getAction()) assertThat(iconAction.getPendingIntent().getIntent().getAction())
.isEqualTo(FAKE_ACTION_SCREEN_LOCK_SETTINGS); .isEqualTo(FAKE_ACTION_OPEN_SUB_SETTING);
assertThat(
iconAction.getPendingIntent().getIntent().getStringExtra(EXTRA_DESTINATION))
.isEqualTo(FAKE_SCREEN_LOCK_SETTINGS);
} }
@Test @Test
@@ -448,9 +455,15 @@ public class LockScreenSafetySourceTest {
when(mScreenLockPreferenceDetailsUtils.isAvailable()).thenReturn(true); when(mScreenLockPreferenceDetailsUtils.isAvailable()).thenReturn(true);
when(mScreenLockPreferenceDetailsUtils.getSummary(anyInt())).thenReturn(SUMMARY); when(mScreenLockPreferenceDetailsUtils.getSummary(anyInt())).thenReturn(SUMMARY);
Intent launchChooseLockGenericFragment = new Intent( Intent launchChooseLockGenericFragment = new Intent(FAKE_ACTION_OPEN_SUB_SETTING);
FAKE_ACTION_CHOOSE_LOCK_GENERIC_FRAGMENT); launchChooseLockGenericFragment.putExtra(EXTRA_DESTINATION,
FAKE_CHOOSE_LOCK_GENERIC_FRAGMENT);
when(mScreenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent(anyInt())) when(mScreenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent(anyInt()))
.thenReturn(launchChooseLockGenericFragment); .thenReturn(launchChooseLockGenericFragment);
Intent launchScreenLockSettings = new Intent(FAKE_ACTION_OPEN_SUB_SETTING);
launchScreenLockSettings.putExtra(EXTRA_DESTINATION, FAKE_SCREEN_LOCK_SETTINGS);
when(mScreenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent(anyInt()))
.thenReturn(launchScreenLockSettings);
} }
} }