Add warning card for Safety Center when no screen lock is set
Test: atest SettingsUnitTests
Bug: 218868097
Change-Id: I4cbc50559dd1d32b5b916a19f7d0b2b27d67510d
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3363f92..43c1acd 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1301,6 +1301,13 @@
<!-- Summary of the preferences item to control encryption, when encryption is active -->
<string name="encrypted_summary">Encrypted</string>
+ <!-- Title of the issue card in Safety Center when no screen lock is set [CHAR LIMIT=50] -->
+ <string name="no_screen_lock_issue_title">Set a screen lock</string>
+ <!-- Summary of the issue card in Safety Center when no screen lock is set [CHAR LIMIT=NONE] -->
+ <string name="no_screen_lock_issue_summary">For added security, set a PIN, pattern, or password for this device.</string>
+ <!-- Action label for the issue card in Safety Center when no screen lock is set [CHAR LIMIT=50] -->
+ <string name="no_screen_lock_issue_action_label">Set screen lock</string>
+
<!-- Unlock Picker Settings --><skip />
<!-- Security Picker --><skip />
diff --git a/src/com/android/settings/safetycenter/LockScreenSafetySource.java b/src/com/android/settings/safetycenter/LockScreenSafetySource.java
index 4b92e06..d010821 100644
--- a/src/com/android/settings/safetycenter/LockScreenSafetySource.java
+++ b/src/com/android/settings/safetycenter/LockScreenSafetySource.java
@@ -22,6 +22,7 @@
import android.content.Intent;
import android.os.UserHandle;
import android.safetycenter.SafetySourceData;
+import android.safetycenter.SafetySourceIssue;
import android.safetycenter.SafetySourceStatus;
import android.safetycenter.SafetySourceStatus.IconAction;
@@ -34,6 +35,9 @@
public final class LockScreenSafetySource {
public static final String SAFETY_SOURCE_ID = "LockScreen";
+ public static final String NO_SCREEN_LOCK_ISSUE_ID = "NoScreenLockIssue";
+ public static final String NO_SCREEN_LOCK_ISSUE_TYPE_ID = "NoScreenLockIssueType";
+ public static final String SET_SCREEN_LOCK_ACTION_ID = "SetScreenLockAction";
private LockScreenSafetySource() {
}
@@ -67,8 +71,12 @@
.setEnabled(
!screenLockPreferenceDetailsUtils.isPasswordQualityManaged(userId, admin))
.setIconAction(gearMenuIconAction).build();
- final SafetySourceData safetySourceData = new SafetySourceData.Builder(
- SAFETY_SOURCE_ID).setStatus(status).build();
+ final SafetySourceData.Builder safetySourceDataBuilder = new SafetySourceData.Builder(
+ SAFETY_SOURCE_ID).setStatus(status);
+ if (!screenLockPreferenceDetailsUtils.isLockPatternSecure()) {
+ safetySourceDataBuilder.addIssue(createNoScreenLockIssue(context, pendingIntent));
+ }
+ final SafetySourceData safetySourceData = safetySourceDataBuilder.build();
SafetyCenterManagerWrapper.get().sendSafetyCenterUpdate(context, safetySourceData);
}
@@ -97,4 +105,20 @@
intent,
PendingIntent.FLAG_IMMUTABLE);
}
+
+ private static SafetySourceIssue createNoScreenLockIssue(Context context,
+ PendingIntent pendingIntent) {
+ final SafetySourceIssue.Action action = new SafetySourceIssue.Action.Builder(
+ SET_SCREEN_LOCK_ACTION_ID,
+ context.getString(R.string.no_screen_lock_issue_action_label),
+ pendingIntent).build();
+ return new SafetySourceIssue.Builder(
+ NO_SCREEN_LOCK_ISSUE_ID,
+ context.getString(R.string.no_screen_lock_issue_title),
+ context.getString(R.string.no_screen_lock_issue_summary),
+ SafetySourceStatus.STATUS_LEVEL_RECOMMENDATION,
+ NO_SCREEN_LOCK_ISSUE_TYPE_ID)
+ .setIssueCategory(SafetySourceIssue.ISSUE_CATEGORY_DEVICE)
+ .addAction(action).build();
+ }
}
diff --git a/tests/unit/src/com/android/settings/safetycenter/LockScreenSafetySourceTest.java b/tests/unit/src/com/android/settings/safetycenter/LockScreenSafetySourceTest.java
index 125f044..90a24aa 100644
--- a/tests/unit/src/com/android/settings/safetycenter/LockScreenSafetySourceTest.java
+++ b/tests/unit/src/com/android/settings/safetycenter/LockScreenSafetySourceTest.java
@@ -27,6 +27,7 @@
import android.content.Context;
import android.content.Intent;
import android.safetycenter.SafetySourceData;
+import android.safetycenter.SafetySourceIssue;
import android.safetycenter.SafetySourceStatus;
import android.safetycenter.SafetySourceStatus.IconAction;
@@ -164,6 +165,59 @@
}
@Test
+ public void sendSafetyData_whenLockPatternIsSecure_sendsNoIssues() {
+ whenScreenLockIsEnabled();
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(true);
+
+ LockScreenSafetySource.sendSafetyData(mApplicationContext,
+ mScreenLockPreferenceDetailsUtils);
+
+ ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
+ verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
+ SafetySourceData safetySourceData = captor.getValue();
+
+ assertThat(safetySourceData.getIssues()).isEmpty();
+ }
+
+ @Test
+ public void sendSafetyData_whenLockPatternIsNotSecure_sendsIssue() {
+ whenScreenLockIsEnabled();
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(false);
+
+ LockScreenSafetySource.sendSafetyData(mApplicationContext,
+ mScreenLockPreferenceDetailsUtils);
+
+ ArgumentCaptor<SafetySourceData> captor = ArgumentCaptor.forClass(SafetySourceData.class);
+ verify(mSafetyCenterManagerWrapper).sendSafetyCenterUpdate(any(), captor.capture());
+ SafetySourceData safetySourceData = captor.getValue();
+
+ assertThat(safetySourceData.getIssues()).hasSize(1);
+ SafetySourceIssue issue = safetySourceData.getIssues().get(0);
+ assertThat(issue.getId()).isEqualTo(LockScreenSafetySource.NO_SCREEN_LOCK_ISSUE_ID);
+ assertThat(issue.getTitle().toString()).isEqualTo(
+ ResourcesUtils.getResourcesString(mApplicationContext,
+ "no_screen_lock_issue_title"));
+ assertThat(issue.getSummary().toString()).isEqualTo(
+ ResourcesUtils.getResourcesString(mApplicationContext,
+ "no_screen_lock_issue_summary"));
+ assertThat(issue.getSeverityLevel()).isEqualTo(
+ SafetySourceStatus.STATUS_LEVEL_RECOMMENDATION);
+ assertThat(issue.getIssueTypeId()).isEqualTo(
+ LockScreenSafetySource.NO_SCREEN_LOCK_ISSUE_TYPE_ID);
+ assertThat(issue.getIssueCategory()).isEqualTo(SafetySourceIssue.ISSUE_CATEGORY_DEVICE);
+ assertThat(issue.getActions()).hasSize(1);
+ SafetySourceIssue.Action action = issue.getActions().get(0);
+ assertThat(action.getId()).isEqualTo(LockScreenSafetySource.SET_SCREEN_LOCK_ACTION_ID);
+ assertThat(action.getLabel().toString()).isEqualTo(
+ ResourcesUtils.getResourcesString(mApplicationContext,
+ "no_screen_lock_issue_action_label"));
+ assertThat(action.getPendingIntent().getIntent().getAction())
+ .isEqualTo(FAKE_ACTION_CHOOSE_LOCK_GENERIC_FRAGMENT);
+ }
+
+ @Test
public void sendSafetyData_whenPasswordQualityIsManaged_sendsDisabled() {
whenScreenLockIsEnabled();
when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);