Merge "Handle "Blocked by your IT admin" better." into main

This commit is contained in:
Elliot Sisteron
2023-09-15 14:19:32 +00:00
committed by Android (Google) Code Review
2 changed files with 234 additions and 174 deletions

View File

@@ -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,
screenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent(
SettingsEnums.SAFETY_CENTER), REQUEST_CODE_SCREEN_LOCK);
final IconAction gearMenuIconAction = createGearMenuIconAction(context,
screenLockPreferenceDetailsUtils);
final boolean enabled =
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 lockScreenAllowedByAdmin =
!screenLockPreferenceDetailsUtils.isPasswordQualityManaged(userId, admin);
final boolean isLockPatternSecure = screenLockPreferenceDetailsUtils.isLockPatternSecure();
final int severityLevel = enabled
? isLockPatternSecure
? SafetySourceData.SEVERITY_LEVEL_INFORMATION
: SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION
: SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
final int severityLevel =
lockScreenAllowedByAdmin
? isLockPatternSecure
? SafetySourceData.SEVERITY_LEVEL_INFORMATION
: SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION
: SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
final SafetySourceStatus status = new SafetySourceStatus.Builder(
context.getString(R.string.unlock_set_unlock_launch_picker_title),
screenLockPreferenceDetailsUtils.getSummary(UserHandle.myUserId()),
severityLevel)
.setPendingIntent(pendingIntent)
.setEnabled(enabled)
.setIconAction(gearMenuIconAction).build();
final SafetySourceStatus status =
new SafetySourceStatus.Builder(
context.getString(R.string.unlock_set_unlock_launch_picker_title),
lockScreenAllowedByAdmin
? screenLockPreferenceDetailsUtils.getSummary(
UserHandle.myUserId())
: context.getString(R.string.disabled_by_policy_title),
severityLevel)
.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,45 +125,45 @@ public final class LockScreenSafetySource {
BiometricsSafetySource.onBiometricsChanged(context);
}
private static IconAction createGearMenuIconAction(Context context,
ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) {
return screenLockPreferenceDetailsUtils.shouldShowGearMenu() ? new IconAction(
IconAction.ICON_TYPE_GEAR,
createPendingIntent(context,
screenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent(
SettingsEnums.SAFETY_CENTER),
REQUEST_CODE_SCREEN_LOCK_SETTINGS))
private static IconAction createGearMenuIconAction(
Context context, ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) {
return screenLockPreferenceDetailsUtils.shouldShowGearMenu()
? new IconAction(
IconAction.ICON_TYPE_GEAR,
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(
SET_SCREEN_LOCK_ACTION_ID,
context.getString(R.string.no_screen_lock_issue_action_label),
pendingIntent).build();
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();
// Custom notification deliberately has zero actions
final SafetySourceIssue.Notification customNotification =
new SafetySourceIssue.Notification.Builder(
context.getString(R.string.no_screen_lock_issue_notification_title),
context.getString(R.string.no_screen_lock_issue_notification_text))
.build();
new SafetySourceIssue.Notification.Builder(
context.getString(R.string.no_screen_lock_issue_notification_title),
context.getString(R.string.no_screen_lock_issue_notification_text))
.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),
SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION,
NO_SCREEN_LOCK_ISSUE_TYPE_ID)
NO_SCREEN_LOCK_ISSUE_ID,
context.getString(R.string.no_screen_lock_issue_title),
context.getString(R.string.no_screen_lock_issue_summary),
SafetySourceData.SEVERITY_LEVEL_RECOMMENDATION,
NO_SCREEN_LOCK_ISSUE_TYPE_ID)
.setIssueCategory(SafetySourceIssue.ISSUE_CATEGORY_DEVICE)
.addAction(action)
.setIssueActionability(SafetySourceIssue.ISSUE_ACTIONABILITY_MANUAL)