Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf6a2c81 authored by Marie Matheson's avatar Marie Matheson
Browse files

Handle null safety source id list in broadcast receiver.

Bug: 215515448
Test: atest SettingsUnitTests
Change-Id: I5c8b24533c4ce39ff28f533fbfc7e386639f4983
parent 9377681a
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -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);
@@ -45,3 +46,4 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
            }
        }
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -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);