Merge "Minor bug fixes for Lockscreen Safety Center source" into tm-dev

This commit is contained in:
Marie Matheson
2022-03-08 14:02:57 +00:00
committed by Android (Google) Code Review
2 changed files with 24 additions and 22 deletions

View File

@@ -96,6 +96,10 @@ public final class LockScreenSafetySource {
context, context,
new ScreenLockPreferenceDetailsUtils(context, SettingsEnums.SAFETY_CENTER), new ScreenLockPreferenceDetailsUtils(context, SettingsEnums.SAFETY_CENTER),
new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build()); new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build());
// Also send refreshed safety center data for biometrics, since changing lockscreen settings
// can unset biometrics.
BiometricsSafetySource.onBiometricsChanged(context);
} }
private static IconAction createGearMenuIconAction(Context context, private static IconAction createGearMenuIconAction(Context context,
@@ -126,7 +130,7 @@ public final class LockScreenSafetySource {
NO_SCREEN_LOCK_ISSUE_ID, NO_SCREEN_LOCK_ISSUE_ID,
context.getString(R.string.no_screen_lock_issue_title), context.getString(R.string.no_screen_lock_issue_title),
context.getString(R.string.no_screen_lock_issue_summary), context.getString(R.string.no_screen_lock_issue_summary),
SafetySourceStatus.STATUS_LEVEL_RECOMMENDATION, SafetySourceIssue.SEVERITY_LEVEL_RECOMMENDATION,
NO_SCREEN_LOCK_ISSUE_TYPE_ID) NO_SCREEN_LOCK_ISSUE_TYPE_ID)
.setIssueCategory(SafetySourceIssue.ISSUE_CATEGORY_DEVICE) .setIssueCategory(SafetySourceIssue.ISSUE_CATEGORY_DEVICE)
.addAction(action).build(); .addAction(action).build();

View File

@@ -22,6 +22,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -117,12 +118,9 @@ public class LockScreenSafetySourceTest {
LockScreenSafetySource.setSafetySourceData(mApplicationContext, LockScreenSafetySource.setSafetySourceData(mApplicationContext,
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED); mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), idCaptor.capture(), any(), any());
String safetySourceId = idCaptor.getValue();
assertThat(safetySourceId).isEqualTo(LockScreenSafetySource.SAFETY_SOURCE_ID); verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), any(), any());
} }
@Test @Test
@@ -132,12 +130,9 @@ public class LockScreenSafetySourceTest {
LockScreenSafetySource.setSafetySourceData(mApplicationContext, LockScreenSafetySource.setSafetySourceData(mApplicationContext,
mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED); mScreenLockPreferenceDetailsUtils, EVENT_SOURCE_STATE_CHANGED);
ArgumentCaptor<SafetyEvent> eventCaptor = ArgumentCaptor.forClass(SafetyEvent.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), any(), any(), eventCaptor.capture());
SafetyEvent safetyEvent = eventCaptor.getValue();
assertThat(safetyEvent).isEqualTo(EVENT_SOURCE_STATE_CHANGED); verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), any(), any(), eq(EVENT_SOURCE_STATE_CHANGED));
} }
@Test @Test
@@ -176,7 +171,7 @@ public class LockScreenSafetySourceTest {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class); ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData( verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), any(), captor.capture(), any()); any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceData safetySourceData = captor.getValue(); SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus(); SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
@@ -195,7 +190,7 @@ public class LockScreenSafetySourceTest {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class); ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData( verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), any(), captor.capture(), any()); any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceData safetySourceData = captor.getValue(); SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus(); SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
@@ -221,7 +216,7 @@ public class LockScreenSafetySourceTest {
} }
@Test @Test
public void setSafetySourceData_whenLockPatternIsNotSecure_setIssue() { public void setSafetySourceData_whenLockPatternIsNotSecure_setsIssue() {
whenScreenLockIsEnabled(); whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(false); when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(false);
@@ -231,7 +226,7 @@ public class LockScreenSafetySourceTest {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class); ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData( verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), any(), captor.capture(), any()); any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceData safetySourceData = captor.getValue(); SafetySourceData safetySourceData = captor.getValue();
assertThat(safetySourceData.getIssues()).hasSize(1); assertThat(safetySourceData.getIssues()).hasSize(1);
@@ -244,7 +239,7 @@ public class LockScreenSafetySourceTest {
ResourcesUtils.getResourcesString(mApplicationContext, ResourcesUtils.getResourcesString(mApplicationContext,
"no_screen_lock_issue_summary")); "no_screen_lock_issue_summary"));
assertThat(issue.getSeverityLevel()).isEqualTo( assertThat(issue.getSeverityLevel()).isEqualTo(
SafetySourceStatus.STATUS_LEVEL_RECOMMENDATION); SafetySourceIssue.SEVERITY_LEVEL_RECOMMENDATION);
assertThat(issue.getIssueTypeId()).isEqualTo( assertThat(issue.getIssueTypeId()).isEqualTo(
LockScreenSafetySource.NO_SCREEN_LOCK_ISSUE_TYPE_ID); LockScreenSafetySource.NO_SCREEN_LOCK_ISSUE_TYPE_ID);
assertThat(issue.getIssueCategory()).isEqualTo(SafetySourceIssue.ISSUE_CATEGORY_DEVICE); assertThat(issue.getIssueCategory()).isEqualTo(SafetySourceIssue.ISSUE_CATEGORY_DEVICE);
@@ -270,7 +265,7 @@ public class LockScreenSafetySourceTest {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class); ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData( verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), any(), captor.capture(), any()); any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceData safetySourceData = captor.getValue(); SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus(); SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
@@ -289,7 +284,7 @@ public class LockScreenSafetySourceTest {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class); ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData( verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), any(), captor.capture(), any()); any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceData safetySourceData = captor.getValue(); SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus(); SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
@@ -311,7 +306,7 @@ public class LockScreenSafetySourceTest {
final ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass( final ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(
SafetySourceData.class); SafetySourceData.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData( verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), any(), captor.capture(), any()); any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
final IconAction iconAction = captor.getValue().getStatus().getIconAction(); final IconAction iconAction = captor.getValue().getStatus().getIconAction();
assertThat(iconAction.getIconType()).isEqualTo(IconAction.ICON_TYPE_GEAR); assertThat(iconAction.getIconType()).isEqualTo(IconAction.ICON_TYPE_GEAR);
@@ -330,7 +325,7 @@ public class LockScreenSafetySourceTest {
ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class); ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
verify(mSafetyCenterManagerWrapper).setSafetySourceData( verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), any(), captor.capture(), any()); any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), captor.capture(), any());
SafetySourceData safetySourceData = captor.getValue(); SafetySourceData safetySourceData = captor.getValue();
SafetySourceStatus safetySourceStatus = safetySourceData.getStatus(); SafetySourceStatus safetySourceStatus = safetySourceData.getStatus();
@@ -338,13 +333,16 @@ public class LockScreenSafetySourceTest {
} }
@Test @Test
public void onLockScreenChange_whenSafetyCenterEnabled_setData() { public void onLockScreenChange_whenSafetyCenterEnabled_setsLockscreenAndBiometricData() {
whenScreenLockIsEnabled(); whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true); when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
LockScreenSafetySource.onLockScreenChange(mApplicationContext); LockScreenSafetySource.onLockScreenChange(mApplicationContext);
verify(mSafetyCenterManagerWrapper).setSafetySourceData(any(), any(), any(), any()); verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), eq(LockScreenSafetySource.SAFETY_SOURCE_ID), any(), any());
verify(mSafetyCenterManagerWrapper).setSafetySourceData(
any(), eq(BiometricsSafetySource.SAFETY_SOURCE_ID), any(), any());
} }
@Test @Test