Merge "Handle null safety source id list in broadcast receiver."

This commit is contained in:
Marie Matheson
2022-02-15 13:30:04 +00:00
committed by Android (Google) Code Review
2 changed files with 19 additions and 7 deletions

View File

@@ -33,8 +33,9 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
return;
}
ImmutableList<String> sourceIds =
ImmutableList.copyOf(intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS));
String[] sourceIdsExtra = 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)) {
LockScreenSafetySource.sendSafetyData(context);
@@ -44,4 +45,5 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
BiometricsSafetySource.sendSafetyData(context);
}
}
}
}

View File

@@ -79,6 +79,16 @@ public class SafetySourceBroadcastReceiverTest {
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
public void sendSafetyData_whenSafetyCenterIsEnabled_withNoSourceIds_sendsNoData() {
when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true);