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

Commit 8744e021 authored by Elliot Sisteron's avatar Elliot Sisteron
Browse files

Handle "Blocked by your IT admin" better.

Instead of allowing the user to click the entry, make the entry
non-clickable and mention that it's blocked by IT admin.

Bug: 297965563
Test: atest LockScreenSafetySourceTest
Change-Id: I821d661dd924358a5e7b033118b63e104ade9eaf
parent 25825c83
Loading
Loading
Loading
Loading
+72 −70
Original line number Diff line number Diff line
@@ -46,11 +46,11 @@ public final class LockScreenSafetySource {
    private static final int REQUEST_CODE_SCREEN_LOCK = 1;
    private static final int REQUEST_CODE_SCREEN_LOCK_SETTINGS = 2;

    private LockScreenSafetySource() {
    }
    private LockScreenSafetySource() {}

    /** Sets lock screen safety data for Safety Center. */
    public static void setSafetySourceData(Context context,
    public static void setSafetySourceData(
            Context context,
            ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils,
            SafetyEvent safetyEvent) {
        if (!SafetyCenterManagerWrapper.get().isEnabled(context)) {
@@ -63,59 +63,61 @@ public final class LockScreenSafetySource {
        }

        if (!screenLockPreferenceDetailsUtils.isAvailable()) {
            SafetyCenterManagerWrapper.get().setSafetySourceData(
                    context,
                    SAFETY_SOURCE_ID,
                    /* safetySourceData= */ null,
                    safetyEvent
            );
            SafetyCenterManagerWrapper.get()
                    .setSafetySourceData(
                            context, SAFETY_SOURCE_ID, /* safetySourceData= */ null, safetyEvent);
            return;
        }

        final int userId = UserHandle.myUserId();
        final RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtilsInternal
                .checkIfPasswordQualityIsSet(context, userId);
        final PendingIntent pendingIntent = createPendingIntent(context,
        final RestrictedLockUtils.EnforcedAdmin admin =
                RestrictedLockUtilsInternal.checkIfPasswordQualityIsSet(context, userId);
        final PendingIntent pendingIntent =
                createPendingIntent(
                        context,
                        screenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent(
                        SettingsEnums.SAFETY_CENTER), REQUEST_CODE_SCREEN_LOCK);
        final IconAction gearMenuIconAction = createGearMenuIconAction(context,
                screenLockPreferenceDetailsUtils);
        final boolean enabled =
                                SettingsEnums.SAFETY_CENTER),
                        REQUEST_CODE_SCREEN_LOCK);
        final IconAction gearMenuIconAction =
                createGearMenuIconAction(context, screenLockPreferenceDetailsUtils);
        final boolean lockScreenAllowedByAdmin =
                !screenLockPreferenceDetailsUtils.isPasswordQualityManaged(userId, admin);
        final boolean isLockPatternSecure = screenLockPreferenceDetailsUtils.isLockPatternSecure();
        final int severityLevel = enabled
        final int severityLevel =
                lockScreenAllowedByAdmin
                        ? isLockPatternSecure
                                ? SafetySourceData.SEVERITY_LEVEL_INFORMATION
                                : SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION
                        : SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;


        final SafetySourceStatus status = new SafetySourceStatus.Builder(
        final SafetySourceStatus status =
                new SafetySourceStatus.Builder(
                                context.getString(R.string.unlock_set_unlock_launch_picker_title),
                screenLockPreferenceDetailsUtils.getSummary(UserHandle.myUserId()),
                                lockScreenAllowedByAdmin
                                        ? screenLockPreferenceDetailsUtils.getSummary(
                                                UserHandle.myUserId())
                                        : context.getString(R.string.disabled_by_policy_title),
                                severityLevel)
                .setPendingIntent(pendingIntent)
                .setEnabled(enabled)
                .setIconAction(gearMenuIconAction).build();
                        .setPendingIntent(lockScreenAllowedByAdmin ? pendingIntent : null)
                        .setEnabled(lockScreenAllowedByAdmin)
                        .setIconAction(lockScreenAllowedByAdmin ? gearMenuIconAction : null)
                        .build();
        final SafetySourceData.Builder safetySourceDataBuilder =
                new SafetySourceData.Builder().setStatus(status);
        if (enabled && !isLockPatternSecure) {
        if (lockScreenAllowedByAdmin && !isLockPatternSecure) {
            safetySourceDataBuilder.addIssue(createNoScreenLockIssue(context, pendingIntent));
        }
        final SafetySourceData safetySourceData = safetySourceDataBuilder.build();

        SafetyCenterManagerWrapper.get().setSafetySourceData(
                context,
                SAFETY_SOURCE_ID,
                safetySourceData,
                safetyEvent
        );
        SafetyCenterManagerWrapper.get()
                .setSafetySourceData(context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent);
    }

    /** Notifies Safety Center of a change in lock screen settings. */
    public static void onLockScreenChange(Context context) {
        setSafetySourceData(
                context, new ScreenLockPreferenceDetailsUtils(context),
                context,
                new ScreenLockPreferenceDetailsUtils(context),
                new SafetyEvent.Builder(SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build());

        // Also send refreshed safety center data for biometrics, since changing lockscreen settings
@@ -123,33 +125,33 @@ public final class LockScreenSafetySource {
        BiometricsSafetySource.onBiometricsChanged(context);
    }

    private static IconAction createGearMenuIconAction(Context context,
            ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) {
        return screenLockPreferenceDetailsUtils.shouldShowGearMenu() ? new IconAction(
    private static IconAction createGearMenuIconAction(
            Context context, ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) {
        return screenLockPreferenceDetailsUtils.shouldShowGearMenu()
                ? new IconAction(
                        IconAction.ICON_TYPE_GEAR,
                createPendingIntent(context,
                        createPendingIntent(
                                context,
                                screenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent(
                                        SettingsEnums.SAFETY_CENTER),
                                REQUEST_CODE_SCREEN_LOCK_SETTINGS))
                : null;
    }

    private static PendingIntent createPendingIntent(Context context, Intent intent,
            int requestCode) {
        return PendingIntent
                .getActivity(
                        context,
                        requestCode,
                        intent,
                        PendingIntent.FLAG_IMMUTABLE);
    private static PendingIntent createPendingIntent(
            Context context, Intent intent, int requestCode) {
        return PendingIntent.getActivity(
                context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE);
    }

    private static SafetySourceIssue createNoScreenLockIssue(Context context,
            PendingIntent pendingIntent) {
        final SafetySourceIssue.Action action = new SafetySourceIssue.Action.Builder(
    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();
                                pendingIntent)
                        .build();
        // Custom notification deliberately has zero actions
        final SafetySourceIssue.Notification customNotification =
                new SafetySourceIssue.Notification.Builder(