Distinguish multiple PendingIntents via requestCode

Settings uses a system of intent extras to open subsettings pages. When
PendingIntents are created from these Intents, the system does not think
they are unique as extras are not included in this equality check. So
only one of them is likely to work.

A unique request code can be used to distinguish between them.

Bug: 238605613
Test: atest LockScreenSafetySourceTest
Change-Id: Ia59197eeb86e988d9ffbb86caff4bbda7b30f059
This commit is contained in:
Simon Wingrove
2022-07-12 06:42:15 +00:00
parent 92f0c3d84d
commit f2b0cedcd0
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 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() {
}
@@ -62,9 +65,11 @@ public final class BiometricsSafetySource {
setBiometricSafetySourceData(context,
context.getString(R.string.security_settings_biometric_preference_title),
combinedBiometricStatusUtils.getSummary(),
biometricNavigationUtils.getBiometricSettingsIntent(context,
combinedBiometricStatusUtils.getSettingsClassName(), disablingAdmin,
Bundle.EMPTY),
createPendingIntent(context,
biometricNavigationUtils.getBiometricSettingsIntent(context,
combinedBiometricStatusUtils.getSettingsClassName(),
disablingAdmin, Bundle.EMPTY),
REQUEST_CODE_COMBINED_BIOMETRIC_SETTING),
disablingAdmin == null /* enabled */,
combinedBiometricStatusUtils.hasEnrolled(),
safetyEvent);
@@ -80,9 +85,11 @@ public final class BiometricsSafetySource {
setBiometricSafetySourceData(context,
context.getString(R.string.security_settings_face_preference_title),
faceStatusUtils.getSummary(),
biometricNavigationUtils.getBiometricSettingsIntent(context,
faceStatusUtils.getSettingsClassName(), disablingAdmin,
Bundle.EMPTY),
createPendingIntent(context,
biometricNavigationUtils.getBiometricSettingsIntent(context,
faceStatusUtils.getSettingsClassName(), disablingAdmin,
Bundle.EMPTY),
REQUEST_CODE_FACE_SETTING),
disablingAdmin == null /* enabled */,
faceStatusUtils.hasEnrolled(),
safetyEvent);
@@ -100,9 +107,11 @@ public final class BiometricsSafetySource {
setBiometricSafetySourceData(context,
context.getString(R.string.security_settings_fingerprint_preference_title),
fingerprintStatusUtils.getSummary(),
biometricNavigationUtils.getBiometricSettingsIntent(context,
fingerprintStatusUtils.getSettingsClassName(), disablingAdmin,
Bundle.EMPTY),
createPendingIntent(context,
biometricNavigationUtils.getBiometricSettingsIntent(context,
fingerprintStatusUtils.getSettingsClassName(), disablingAdmin,
Bundle.EMPTY),
REQUEST_CODE_FINGERPRINT_SETTING),
disablingAdmin == null /* enabled */,
fingerprintStatusUtils.hasEnrolled(),
safetyEvent);
@@ -118,8 +127,8 @@ public final class BiometricsSafetySource {
}
private static void setBiometricSafetySourceData(Context context, String title, String summary,
Intent clickIntent, boolean enabled, boolean hasEnrolled, SafetyEvent safetyEvent) {
final PendingIntent pendingIntent = createPendingIntent(context, clickIntent);
PendingIntent pendingIntent, boolean enabled, boolean hasEnrolled,
SafetyEvent safetyEvent) {
final int severityLevel =
enabled && hasEnrolled ? SafetySourceData.SEVERITY_LEVEL_INFORMATION
: SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
@@ -133,11 +142,12 @@ public final class BiometricsSafetySource {
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
.getActivity(
context,
0 /* requestCode */,
requestCode,
intent,
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 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() {
}
@@ -62,7 +65,7 @@ public final class LockScreenSafetySource {
.checkIfPasswordQualityIsSet(context, userId);
final PendingIntent pendingIntent = createPendingIntent(context,
screenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent(
SettingsEnums.SAFETY_CENTER));
SettingsEnums.SAFETY_CENTER), REQUEST_CODE_SCREEN_LOCK);
final IconAction gearMenuIconAction = createGearMenuIconAction(context,
screenLockPreferenceDetailsUtils);
final boolean enabled =
@@ -114,15 +117,17 @@ public final class LockScreenSafetySource {
IconAction.ICON_TYPE_GEAR,
createPendingIntent(context,
screenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent(
SettingsEnums.SAFETY_CENTER)))
SettingsEnums.SAFETY_CENTER),
REQUEST_CODE_SCREEN_LOCK_SETTINGS))
: null;
}
private static PendingIntent createPendingIntent(Context context, Intent intent) {
private static PendingIntent createPendingIntent(Context context, Intent intent,
int requestCode) {
return PendingIntent
.getActivity(
context,
0 /* requestCode */,
requestCode,
intent,
PendingIntent.FLAG_IMMUTABLE);
}

View File

@@ -55,8 +55,10 @@ import org.mockito.MockitoAnnotations;
public class LockScreenSafetySourceTest {
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_SCREEN_LOCK_SETTINGS = "screen_lock_settings";
private static final String FAKE_ACTION_OPEN_SUB_SETTING = "open_sub_setting";
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 =
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build();
@@ -157,7 +159,10 @@ public class LockScreenSafetySourceTest {
.isEqualTo(SUMMARY);
assertThat(safetySourceStatus.getPendingIntent().getIntent()).isNotNull();
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
@@ -300,7 +305,9 @@ public class LockScreenSafetySourceTest {
ResourcesUtils.getResourcesString(mApplicationContext,
"no_screen_lock_issue_action_label"));
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
@@ -383,9 +390,6 @@ public class LockScreenSafetySourceTest {
public void setSafetySourceData_whenShouldShowGearMenu_setGearMenuActionIcon() {
whenScreenLockIsEnabled();
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);
LockScreenSafetySource.setSafetySourceData(mApplicationContext,
@@ -399,7 +403,10 @@ public class LockScreenSafetySourceTest {
assertThat(iconAction.getIconType()).isEqualTo(IconAction.ICON_TYPE_GEAR);
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
@@ -448,9 +455,15 @@ public class LockScreenSafetySourceTest {
when(mScreenLockPreferenceDetailsUtils.isAvailable()).thenReturn(true);
when(mScreenLockPreferenceDetailsUtils.getSummary(anyInt())).thenReturn(SUMMARY);
Intent launchChooseLockGenericFragment = new Intent(
FAKE_ACTION_CHOOSE_LOCK_GENERIC_FRAGMENT);
Intent launchChooseLockGenericFragment = new Intent(FAKE_ACTION_OPEN_SUB_SETTING);
launchChooseLockGenericFragment.putExtra(EXTRA_DESTINATION,
FAKE_CHOOSE_LOCK_GENERIC_FRAGMENT);
when(mScreenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent(anyInt()))
.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);
}
}