Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6cadee43 authored by Yuri Ufimtsev's avatar Yuri Ufimtsev
Browse files

Add warning card for Safety Center when no screen lock is set

Test: atest SettingsUnitTests

Bug: 218868097
Change-Id: I4cbc50559dd1d32b5b916a19f7d0b2b27d67510d
parent 40caac3c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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 />
+26 −2
Original line number Diff line number Diff line
@@ -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();
    }
}
+54 −0
Original line number Diff line number Diff line
@@ -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<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();