Loading AndroidManifest.xml +1 −0 Original line number Diff line number Diff line Loading @@ -4349,6 +4349,7 @@ android:exported="true"> <intent-filter> <action android:name="android.safetycenter.action.REFRESH_SAFETY_SOURCES"/> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver> Loading src/com/android/settings/safetycenter/SafetySourceBroadcastReceiver.java +29 −9 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.safetycenter; import static android.content.Intent.ACTION_BOOT_COMPLETED; import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES; import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS; import android.content.BroadcastReceiver; Loading @@ -24,6 +26,8 @@ import android.content.Intent; import com.google.common.collect.ImmutableList; import java.util.List; /** Broadcast receiver for handling requests from Safety Center for fresh data. */ public class SafetySourceBroadcastReceiver extends BroadcastReceiver { Loading @@ -33,10 +37,22 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver { return; } String[] sourceIdsExtra = intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS); if (ACTION_REFRESH_SAFETY_SOURCES.equals(intent.getAction())) { String[] sourceIdsExtra = intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS); if (sourceIdsExtra != null && sourceIdsExtra.length > 0) { ImmutableList<String> sourceIds = ImmutableList.copyOf(sourceIdsExtra); refreshSafetySources(context, ImmutableList.copyOf(sourceIdsExtra)); } return; } if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) { refreshAllSafetySources(context); } } private static void refreshSafetySources(Context context, List<String> sourceIds) { if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) { LockScreenSafetySource.sendSafetyData(context); } Loading @@ -45,5 +61,9 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver { BiometricsSafetySource.sendSafetyData(context); } } private static void refreshAllSafetySources(Context context) { LockScreenSafetySource.sendSafetyData(context); BiometricsSafetySource.sendSafetyData(context); } } tests/unit/src/com/android/settings/safetycenter/SafetySourceBroadcastReceiverTest.java +47 −11 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settings.safetycenter; import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES; import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -66,11 +67,23 @@ public class SafetySourceBroadcastReceiverTest { SafetyCenterStatusHolder.sInstance = null; } @Test public void sendSafetyData_whenSafetyCenterIsEnabled_withNoIntentAction_sendsNoData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent().putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{}); new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent); verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any()); } @Test public void sendSafetyData_whenSafetyCenterIsDisabled_sendsNoData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(false); Intent intent = new Intent().putExtra( new Intent() .setAction(ACTION_REFRESH_SAFETY_SOURCES) .putExtra( EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{ LockScreenSafetySource.SAFETY_SOURCE_ID }); Loading @@ -82,7 +95,7 @@ public class SafetySourceBroadcastReceiverTest { @Test public void sendSafetyData_whenSafetyCenterIsEnabled_withNullSourceIds_sendsNoData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent(); Intent intent = new Intent().setAction(ACTION_REFRESH_SAFETY_SOURCES); new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent); Loading @@ -92,7 +105,10 @@ public class SafetySourceBroadcastReceiverTest { @Test public void sendSafetyData_whenSafetyCenterIsEnabled_withNoSourceIds_sendsNoData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent().putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{}); Intent intent = new Intent() .setAction(ACTION_REFRESH_SAFETY_SOURCES) .putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{}); new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent); Loading @@ -103,7 +119,9 @@ public class SafetySourceBroadcastReceiverTest { public void sendSafetyData_withLockscreenSourceId_sendsLockscreenData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent().putExtra( new Intent() .setAction(ACTION_REFRESH_SAFETY_SOURCES) .putExtra( EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{ LockScreenSafetySource.SAFETY_SOURCE_ID }); Loading @@ -120,7 +138,9 @@ public class SafetySourceBroadcastReceiverTest { public void sendSafetyData_withBiometricsSourceId_sendsBiometricData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent().putExtra( new Intent() .setAction(ACTION_REFRESH_SAFETY_SOURCES) .putExtra( EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{ BiometricsSafetySource.SAFETY_SOURCE_ID }); Loading @@ -129,4 +149,20 @@ public class SafetySourceBroadcastReceiverTest { // TODO(b/215517420): Update this test when BiometricSafetySource is implemented. verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any()); } @Test public void sendSafetyData_onBootCompleted_sendsBiometricAndLockscreenData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent().setAction(Intent.ACTION_BOOT_COMPLETED); // TODO(b/215517420): Update this test when BiometricSafetySource is implemented to test // that biometrics data is also sent. new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent); ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class); verify(mSafetyCenterManagerWrapper, times(1)) .sendSafetyCenterUpdate(any(), captor.capture()); SafetySourceData safetySourceData = captor.getValue(); assertThat(safetySourceData.getId()).isEqualTo(LockScreenSafetySource.SAFETY_SOURCE_ID); } } Loading
AndroidManifest.xml +1 −0 Original line number Diff line number Diff line Loading @@ -4349,6 +4349,7 @@ android:exported="true"> <intent-filter> <action android:name="android.safetycenter.action.REFRESH_SAFETY_SOURCES"/> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver> Loading
src/com/android/settings/safetycenter/SafetySourceBroadcastReceiver.java +29 −9 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.safetycenter; import static android.content.Intent.ACTION_BOOT_COMPLETED; import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES; import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS; import android.content.BroadcastReceiver; Loading @@ -24,6 +26,8 @@ import android.content.Intent; import com.google.common.collect.ImmutableList; import java.util.List; /** Broadcast receiver for handling requests from Safety Center for fresh data. */ public class SafetySourceBroadcastReceiver extends BroadcastReceiver { Loading @@ -33,10 +37,22 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver { return; } String[] sourceIdsExtra = intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS); if (ACTION_REFRESH_SAFETY_SOURCES.equals(intent.getAction())) { String[] sourceIdsExtra = intent.getStringArrayExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS); if (sourceIdsExtra != null && sourceIdsExtra.length > 0) { ImmutableList<String> sourceIds = ImmutableList.copyOf(sourceIdsExtra); refreshSafetySources(context, ImmutableList.copyOf(sourceIdsExtra)); } return; } if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) { refreshAllSafetySources(context); } } private static void refreshSafetySources(Context context, List<String> sourceIds) { if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) { LockScreenSafetySource.sendSafetyData(context); } Loading @@ -45,5 +61,9 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver { BiometricsSafetySource.sendSafetyData(context); } } private static void refreshAllSafetySources(Context context) { LockScreenSafetySource.sendSafetyData(context); BiometricsSafetySource.sendSafetyData(context); } }
tests/unit/src/com/android/settings/safetycenter/SafetySourceBroadcastReceiverTest.java +47 −11 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settings.safetycenter; import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES; import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -66,11 +67,23 @@ public class SafetySourceBroadcastReceiverTest { SafetyCenterStatusHolder.sInstance = null; } @Test public void sendSafetyData_whenSafetyCenterIsEnabled_withNoIntentAction_sendsNoData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent().putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{}); new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent); verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any()); } @Test public void sendSafetyData_whenSafetyCenterIsDisabled_sendsNoData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(false); Intent intent = new Intent().putExtra( new Intent() .setAction(ACTION_REFRESH_SAFETY_SOURCES) .putExtra( EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{ LockScreenSafetySource.SAFETY_SOURCE_ID }); Loading @@ -82,7 +95,7 @@ public class SafetySourceBroadcastReceiverTest { @Test public void sendSafetyData_whenSafetyCenterIsEnabled_withNullSourceIds_sendsNoData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent(); Intent intent = new Intent().setAction(ACTION_REFRESH_SAFETY_SOURCES); new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent); Loading @@ -92,7 +105,10 @@ public class SafetySourceBroadcastReceiverTest { @Test public void sendSafetyData_whenSafetyCenterIsEnabled_withNoSourceIds_sendsNoData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent().putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{}); Intent intent = new Intent() .setAction(ACTION_REFRESH_SAFETY_SOURCES) .putExtra(EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{}); new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent); Loading @@ -103,7 +119,9 @@ public class SafetySourceBroadcastReceiverTest { public void sendSafetyData_withLockscreenSourceId_sendsLockscreenData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent().putExtra( new Intent() .setAction(ACTION_REFRESH_SAFETY_SOURCES) .putExtra( EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{ LockScreenSafetySource.SAFETY_SOURCE_ID }); Loading @@ -120,7 +138,9 @@ public class SafetySourceBroadcastReceiverTest { public void sendSafetyData_withBiometricsSourceId_sendsBiometricData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent().putExtra( new Intent() .setAction(ACTION_REFRESH_SAFETY_SOURCES) .putExtra( EXTRA_REFRESH_SAFETY_SOURCE_IDS, new String[]{ BiometricsSafetySource.SAFETY_SOURCE_ID }); Loading @@ -129,4 +149,20 @@ public class SafetySourceBroadcastReceiverTest { // TODO(b/215517420): Update this test when BiometricSafetySource is implemented. verify(mSafetyCenterManagerWrapper, never()).sendSafetyCenterUpdate(any(), any()); } @Test public void sendSafetyData_onBootCompleted_sendsBiometricAndLockscreenData() { when(mSafetyCenterStatusHolder.isEnabled(mApplicationContext)).thenReturn(true); Intent intent = new Intent().setAction(Intent.ACTION_BOOT_COMPLETED); // TODO(b/215517420): Update this test when BiometricSafetySource is implemented to test // that biometrics data is also sent. new SafetySourceBroadcastReceiver().onReceive(mApplicationContext, intent); ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class); verify(mSafetyCenterManagerWrapper, times(1)) .sendSafetyCenterUpdate(any(), captor.capture()); SafetySourceData safetySourceData = captor.getValue(); assertThat(safetySourceData.getId()).isEqualTo(LockScreenSafetySource.SAFETY_SOURCE_ID); } }