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; 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);
@@ -45,3 +46,4 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
} }
} }
} }
}

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);