Set the Refresh Broadcast ID for Safety Event if available

Test: atest SettingsUnitTests

Bug: 222679576
Change-Id: I52ba3aff3045a8211fc936240f1310da6fad9fb0
This commit is contained in:
Yuri Ufimtsev
2022-03-15 15:23:07 +00:00
parent db201b0d03
commit 4e255cb407
2 changed files with 31 additions and 3 deletions

View File

@@ -17,6 +17,7 @@
package com.android.settings.safetycenter;
import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES;
import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID;
import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS;
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_DEVICE_REBOOTED;
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_REFRESH_REQUESTED;
@@ -147,6 +148,29 @@ public class SafetySourceBroadcastReceiverTest {
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_REFRESH_REQUESTED).build());
}
@Test
public void onReceive_onRefreshWithBroadcastId_setsRefreshEventWithBroadcastId() {
final String refreshBroadcastId = "REFRESH_BROADCAST_ID";
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
Intent intent =
new Intent()
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
.putExtra(
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
new String[]{ LockScreenSafetySource.SAFETY_SOURCE_ID })
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, refreshBroadcastId);
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
ArgumentCaptor<SafetyEvent> captor = ArgumentCaptor.forClass(SafetyEvent.class);
verify(mSafetyCenterManagerWrapper, times(1))
.setSafetySourceData(any(), any(), any(), captor.capture());
assertThat(captor.getValue().getRefreshBroadcastId()).isEqualTo(refreshBroadcastId);
assertThat(captor.getValue()).isEqualTo(
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_REFRESH_REQUESTED)
.setRefreshBroadcastId(refreshBroadcastId).build());
}
@Test
public void onReceive_onRefresh_withLockscreenSourceId_setsLockscreenData() {
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);