Handle null safety source id list in broadcast receiver.

Bug: 215515448
Test: atest SettingsUnitTests
Change-Id: I5c8b24533c4ce39ff28f533fbfc7e386639f4983
This commit is contained in:
Marie Matheson
2022-02-11 19:04:19 +00:00
parent 9377681a5f
commit bf6a2c8136
2 changed files with 19 additions and 7 deletions

View File

@@ -33,15 +33,17 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
return; return;
} }
ImmutableList<String> sourceIds = String[] sourceIdsExtra = intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS);
ImmutableList.copyOf(intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS)); if (sourceIdsExtra != null && sourceIdsExtra.length > 0) {
ImmutableList<String> sourceIds = ImmutableList.copyOf(sourceIdsExtra);
if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) { if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) {
LockScreenSafetySource.sendSafetyData(context); LockScreenSafetySource.sendSafetyData(context);
} }
if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)) { if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)) {
BiometricsSafetySource.sendSafetyData(context); BiometricsSafetySource.sendSafetyData(context);
}
} }
} }
} }

View File

@@ -79,6 +79,16 @@ public class SafetySourceBroadcastReceiverTest {
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any()); verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
} }
@Test
public void sendSafetyData_whenSafetyCenterIsEnabled_withNullSourceIds_sendsNoData() {
when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true);
Intent intent = new Intent();
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any());
}
@Test @Test
public void sendSafetyData_whenSafetyCenterIsEnabled_withNoSourceIds_sendsNoData() { public void sendSafetyData_whenSafetyCenterIsEnabled_withNoSourceIds_sendsNoData() {
when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true);