Merge "Set the Refresh Broadcast ID for Safety Event if available" into tm-dev am: 829ee90dd3
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/17197110 Change-Id: If6a2bbb6a6dcf5d51c81a3dc341ad69234b3c46b
This commit is contained in:
@@ -26,6 +26,7 @@ import android.app.settings.SettingsEnums;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.safetycenter.SafetyCenterManager;
|
||||||
import android.safetycenter.SafetyEvent;
|
import android.safetycenter.SafetyEvent;
|
||||||
|
|
||||||
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
|
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
|
||||||
@@ -37,8 +38,6 @@ import java.util.List;
|
|||||||
/** Broadcast receiver for handling requests from Safety Center for fresh data. */
|
/** Broadcast receiver for handling requests from Safety Center for fresh data. */
|
||||||
public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
|
public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
private static final SafetyEvent EVENT_REFRESH_REQUESTED =
|
|
||||||
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_REFRESH_REQUESTED).build();
|
|
||||||
private static final SafetyEvent EVENT_DEVICE_REBOOTED =
|
private static final SafetyEvent EVENT_DEVICE_REBOOTED =
|
||||||
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_DEVICE_REBOOTED).build();
|
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_DEVICE_REBOOTED).build();
|
||||||
|
|
||||||
@@ -52,10 +51,15 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
String[] sourceIdsExtra =
|
String[] sourceIdsExtra =
|
||||||
intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS);
|
intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS);
|
||||||
if (sourceIdsExtra != null && sourceIdsExtra.length > 0) {
|
if (sourceIdsExtra != null && sourceIdsExtra.length > 0) {
|
||||||
|
final String refreshBroadcastId = intent.getStringExtra(
|
||||||
|
SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID);
|
||||||
|
final SafetyEvent safetyEvent = new SafetyEvent.Builder(
|
||||||
|
SAFETY_EVENT_TYPE_REFRESH_REQUESTED)
|
||||||
|
.setRefreshBroadcastId(refreshBroadcastId).build();
|
||||||
refreshSafetySources(
|
refreshSafetySources(
|
||||||
context,
|
context,
|
||||||
ImmutableList.copyOf(sourceIdsExtra),
|
ImmutableList.copyOf(sourceIdsExtra),
|
||||||
EVENT_REFRESH_REQUESTED);
|
safetyEvent);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.safetycenter;
|
package com.android.settings.safetycenter;
|
||||||
|
|
||||||
import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES;
|
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.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS;
|
||||||
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_DEVICE_REBOOTED;
|
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_DEVICE_REBOOTED;
|
||||||
import static android.safetycenter.SafetyEvent.SAFETY_EVENT_TYPE_REFRESH_REQUESTED;
|
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());
|
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
|
@Test
|
||||||
public void onReceive_onRefresh_withLockscreenSourceId_setsLockscreenData() {
|
public void onReceive_onRefresh_withLockscreenSourceId_setsLockscreenData() {
|
||||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||||
|
Reference in New Issue
Block a user