Merge "Add refresh broadcast id checks" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
cd2d6f3e25
@@ -49,9 +49,9 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
|
|||||||
if (ACTION_REFRESH_SAFETY_SOURCES.equals(intent.getAction())) {
|
if (ACTION_REFRESH_SAFETY_SOURCES.equals(intent.getAction())) {
|
||||||
String[] sourceIdsExtra =
|
String[] sourceIdsExtra =
|
||||||
intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS);
|
intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS);
|
||||||
if (sourceIdsExtra != null && sourceIdsExtra.length > 0) {
|
|
||||||
final String refreshBroadcastId = intent.getStringExtra(
|
final String refreshBroadcastId = intent.getStringExtra(
|
||||||
SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID);
|
SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID);
|
||||||
|
if (sourceIdsExtra != null && sourceIdsExtra.length > 0 && refreshBroadcastId != null) {
|
||||||
final SafetyEvent safetyEvent = new SafetyEvent.Builder(
|
final SafetyEvent safetyEvent = new SafetyEvent.Builder(
|
||||||
SAFETY_EVENT_TYPE_REFRESH_REQUESTED)
|
SAFETY_EVENT_TYPE_REFRESH_REQUESTED)
|
||||||
.setRefreshBroadcastId(refreshBroadcastId).build();
|
.setRefreshBroadcastId(refreshBroadcastId).build();
|
||||||
|
@@ -54,13 +54,13 @@ import java.util.List;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class SafetySourceBroadcastReceiverTest {
|
public class SafetySourceBroadcastReceiverTest {
|
||||||
|
|
||||||
|
private static final String REFRESH_BROADCAST_ID = "REFRESH_BROADCAST_ID";
|
||||||
|
|
||||||
private Context mApplicationContext;
|
private Context mApplicationContext;
|
||||||
|
|
||||||
@Mock
|
@Mock private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
|
||||||
private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper;
|
|
||||||
|
|
||||||
@Mock
|
@Mock private LockPatternUtils mLockPatternUtils;
|
||||||
private LockPatternUtils mLockPatternUtils;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -77,17 +77,6 @@ public class SafetySourceBroadcastReceiverTest {
|
|||||||
SafetyCenterManagerWrapper.sInstance = null;
|
SafetyCenterManagerWrapper.sInstance = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onReceive_onRefresh_whenSafetyCenterIsEnabled_withNoIntentAction_doesNotSetData() {
|
|
||||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
|
||||||
Intent intent = new Intent().putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{});
|
|
||||||
|
|
||||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
|
||||||
|
|
||||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
|
||||||
any(), any(), any(), any());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onReceive_onRefresh_whenSafetyCenterIsDisabled_doesNotSetData() {
|
public void onReceive_onRefresh_whenSafetyCenterIsDisabled_doesNotSetData() {
|
||||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
|
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(false);
|
||||||
@@ -96,23 +85,43 @@ public class SafetySourceBroadcastReceiverTest {
|
|||||||
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
||||||
.putExtra(
|
.putExtra(
|
||||||
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
||||||
new String[]{ LockScreenSafetySource.SAFETY_SOURCE_ID });
|
new String[] {LockScreenSafetySource.SAFETY_SOURCE_ID})
|
||||||
|
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
|
||||||
|
|
||||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||||
|
|
||||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
verify(mSafetyCenterManagerWrapper, never())
|
||||||
any(), any(), any(), any());
|
.setSafetySourceData(any(), any(), any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onReceive_onRefresh_whenSafetyCenterIsEnabled_withNoIntentAction_doesNotSetData() {
|
||||||
|
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||||
|
Intent intent =
|
||||||
|
new Intent()
|
||||||
|
.putExtra(
|
||||||
|
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
||||||
|
new String[] {LockScreenSafetySource.SAFETY_SOURCE_ID})
|
||||||
|
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
|
||||||
|
|
||||||
|
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||||
|
|
||||||
|
verify(mSafetyCenterManagerWrapper, never())
|
||||||
|
.setSafetySourceData(any(), any(), any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onReceive_onRefresh_whenSafetyCenterIsEnabled_withNullSourceIds_doesNotSetData() {
|
public void onReceive_onRefresh_whenSafetyCenterIsEnabled_withNullSourceIds_doesNotSetData() {
|
||||||
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
|
||||||
Intent intent = new Intent().setAction(ACTION_REFRESH_SAFETY_SOURCES);
|
Intent intent =
|
||||||
|
new Intent()
|
||||||
|
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
||||||
|
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
|
||||||
|
|
||||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||||
|
|
||||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
verify(mSafetyCenterManagerWrapper, never())
|
||||||
any(), any(), any(), any());
|
.setSafetySourceData(any(), any(), any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -121,12 +130,29 @@ public class SafetySourceBroadcastReceiverTest {
|
|||||||
Intent intent =
|
Intent intent =
|
||||||
new Intent()
|
new Intent()
|
||||||
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
||||||
.putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{});
|
.putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[] {})
|
||||||
|
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
|
||||||
|
|
||||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||||
|
|
||||||
verify(mSafetyCenterManagerWrapper, never()).setSafetySourceData(
|
verify(mSafetyCenterManagerWrapper, never())
|
||||||
any(), any(), any(), any());
|
.setSafetySourceData(any(), any(), any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onReceive_onRefresh_whenSafetyCenterIsEnabled_withNoBroadcastId_doesNotSetData() {
|
||||||
|
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});
|
||||||
|
|
||||||
|
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||||
|
|
||||||
|
verify(mSafetyCenterManagerWrapper, never())
|
||||||
|
.setSafetySourceData(any(), any(), any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -137,38 +163,19 @@ public class SafetySourceBroadcastReceiverTest {
|
|||||||
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
||||||
.putExtra(
|
.putExtra(
|
||||||
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
||||||
new String[]{ LockScreenSafetySource.SAFETY_SOURCE_ID });
|
new String[] {LockScreenSafetySource.SAFETY_SOURCE_ID})
|
||||||
|
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
|
||||||
|
|
||||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||||
ArgumentCaptor<SafetyEvent> captor = ArgumentCaptor.forClass(SafetyEvent.class);
|
ArgumentCaptor<SafetyEvent> captor = ArgumentCaptor.forClass(SafetyEvent.class);
|
||||||
verify(mSafetyCenterManagerWrapper, times(1))
|
verify(mSafetyCenterManagerWrapper, times(1))
|
||||||
.setSafetySourceData(any(), any(), any(), captor.capture());
|
.setSafetySourceData(any(), any(), any(), captor.capture());
|
||||||
|
|
||||||
assertThat(captor.getValue()).isEqualTo(
|
assertThat(captor.getValue())
|
||||||
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_REFRESH_REQUESTED).build());
|
.isEqualTo(
|
||||||
}
|
|
||||||
|
|
||||||
@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)
|
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_REFRESH_REQUESTED)
|
||||||
.setRefreshBroadcastId(refreshBroadcastId).build());
|
.setRefreshBroadcastId(REFRESH_BROADCAST_ID)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -179,7 +186,8 @@ public class SafetySourceBroadcastReceiverTest {
|
|||||||
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
||||||
.putExtra(
|
.putExtra(
|
||||||
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
||||||
new String[]{ LockScreenSafetySource.SAFETY_SOURCE_ID });
|
new String[] {LockScreenSafetySource.SAFETY_SOURCE_ID})
|
||||||
|
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
|
||||||
|
|
||||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
@@ -197,7 +205,8 @@ public class SafetySourceBroadcastReceiverTest {
|
|||||||
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
.setAction(ACTION_REFRESH_SAFETY_SOURCES)
|
||||||
.putExtra(
|
.putExtra(
|
||||||
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
EXTRA_REFRESH_SAFETY_SOURCE_IDS,
|
||||||
new String[]{ BiometricsSafetySource.SAFETY_SOURCE_ID });
|
new String[] {BiometricsSafetySource.SAFETY_SOURCE_ID})
|
||||||
|
.putExtra(EXTRA_REFRESH_SAFETY_SOURCES_BROADCAST_ID, REFRESH_BROADCAST_ID);
|
||||||
|
|
||||||
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent);
|
||||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||||
|
Reference in New Issue
Block a user