diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3363f929c25..43c1acd4808 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1301,6 +1301,13 @@
Encrypted
+
+ Set a screen lock
+
+ For added security, set a PIN, pattern, or password for this device.
+
+ Set screen lock
+
diff --git a/src/com/android/settings/safetycenter/LockScreenSafetySource.java b/src/com/android/settings/safetycenter/LockScreenSafetySource.java
index 4b92e0691ea..d0108210476 100644
--- a/src/com/android/settings/safetycenter/LockScreenSafetySource.java
+++ b/src/com/android/settings/safetycenter/LockScreenSafetySource.java
@@ -22,6 +22,7 @@ import android.content.Context;
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 @@ import com.android.settingslib.RestrictedLockUtilsInternal;
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 @@ public final class LockScreenSafetySource {
.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 @@ public final class LockScreenSafetySource {
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 125f044f06b..90a24aa5a11 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 static org.mockito.Mockito.when;
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;
@@ -163,6 +164,59 @@ public class LockScreenSafetySourceTest {
.isEqualTo(SafetySourceStatus.STATUS_LEVEL_RECOMMENDATION);
}
+ @Test
+ public void sendSafetyData_whenLockPatternIsSecure_sendsNoIssues() {
+ whenScreenLockIsEnabled();
+ when(mSafetyCenterManagerWrapper.isEnabled(mApplicationContext)).thenReturn(true);
+ when(mScreenLockPreferenceDetailsUtils.isLockPatternSecure()).thenReturn(true);
+
+ LockScreenSafetySource.sendSafetyData(mApplicationContext,
+ mScreenLockPreferenceDetailsUtils);
+
+ ArgumentCaptor 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 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();