Merge "Provide data to LockScreenSafetySource" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6368af8bdf
@@ -17,51 +17,76 @@
|
||||
package com.android.settings.safetycenter;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.safetycenter.SafetySourceData;
|
||||
import android.safetycenter.SafetySourceStatus;
|
||||
import android.safetycenter.SafetySourceStatus.IconAction;
|
||||
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.password.ChooseLockGeneric;
|
||||
import com.android.settingslib.transition.SettingsTransitionHelper;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
|
||||
/** Lock Screen Safety Source for Safety Center. */
|
||||
public final class LockScreenSafetySource {
|
||||
|
||||
public static final String SAFETY_SOURCE_ID = "LockScreenSafetySource";
|
||||
|
||||
private LockScreenSafetySource() {}
|
||||
private LockScreenSafetySource() {
|
||||
}
|
||||
|
||||
/** Sends lock screen safety data to Safety Center. */
|
||||
public static void sendSafetyData(Context context) {
|
||||
public static void sendSafetyData(Context context,
|
||||
ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) {
|
||||
if (!SafetyCenterStatusHolder.get().isEnabled(context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(b/215515298): Replace placeholder SafetySourceData with real data.
|
||||
// TODO(b/217409995): Replace SECURITY_ALTERNATIVE with Safety Center metrics category.
|
||||
Intent clickIntent = new SubSettingLauncher(context)
|
||||
.setDestination(ChooseLockGeneric.ChooseLockGenericFragment.class.getName())
|
||||
.setSourceMetricsCategory(SettingsEnums.SECURITY_ALTERNATIVE)
|
||||
.setTransitionType(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE)
|
||||
.toIntent();
|
||||
PendingIntent pendingIntent = PendingIntent
|
||||
.getActivity(
|
||||
context,
|
||||
0 /* requestCode */,
|
||||
clickIntent,
|
||||
PendingIntent.FLAG_IMMUTABLE);
|
||||
SafetySourceData safetySourceData =
|
||||
new SafetySourceData.Builder(SAFETY_SOURCE_ID).setStatus(
|
||||
new SafetySourceStatus.Builder(
|
||||
"Lock Screen",
|
||||
"Lock screen settings",
|
||||
SafetySourceStatus.STATUS_LEVEL_OK,
|
||||
pendingIntent).build()
|
||||
).build();
|
||||
if (!screenLockPreferenceDetailsUtils.isAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int userId = UserHandle.myUserId();
|
||||
final RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtilsInternal
|
||||
.checkIfPasswordQualityIsSet(context, userId);
|
||||
final PendingIntent pendingIntent = createPendingIntent(context,
|
||||
screenLockPreferenceDetailsUtils.getLaunchChooseLockGenericFragmentIntent());
|
||||
final IconAction gearMenuIconAction = createGearMenuIconAction(context,
|
||||
screenLockPreferenceDetailsUtils);
|
||||
|
||||
final SafetySourceStatus status = new SafetySourceStatus.Builder(
|
||||
context.getString(R.string.unlock_set_unlock_launch_picker_title_profile),
|
||||
screenLockPreferenceDetailsUtils.getSummary(UserHandle.myUserId()),
|
||||
screenLockPreferenceDetailsUtils.isLockPatternSecure()
|
||||
? SafetySourceStatus.STATUS_LEVEL_OK
|
||||
: SafetySourceStatus.STATUS_LEVEL_RECOMMENDATION,
|
||||
pendingIntent)
|
||||
.setEnabled(
|
||||
!screenLockPreferenceDetailsUtils.isPasswordQualityManaged(userId, admin))
|
||||
.setIconAction(gearMenuIconAction).build();
|
||||
final SafetySourceData safetySourceData = new SafetySourceData.Builder(
|
||||
SAFETY_SOURCE_ID).setStatus(status).build();
|
||||
|
||||
SafetyCenterManagerWrapper.get().sendSafetyCenterUpdate(context, safetySourceData);
|
||||
}
|
||||
|
||||
private static IconAction createGearMenuIconAction(Context context,
|
||||
ScreenLockPreferenceDetailsUtils screenLockPreferenceDetailsUtils) {
|
||||
return screenLockPreferenceDetailsUtils.shouldShowGearMenu() ? new IconAction(
|
||||
IconAction.ICON_TYPE_GEAR,
|
||||
createPendingIntent(context,
|
||||
screenLockPreferenceDetailsUtils.getLaunchScreenLockSettingsIntent()))
|
||||
: null;
|
||||
}
|
||||
|
||||
private static PendingIntent createPendingIntent(Context context, Intent intent) {
|
||||
return PendingIntent
|
||||
.getActivity(
|
||||
context,
|
||||
0 /* requestCode */,
|
||||
intent,
|
||||
PendingIntent.FLAG_IMMUTABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,13 @@ import static android.content.Intent.ACTION_BOOT_COMPLETED;
|
||||
import static android.safetycenter.SafetyCenterManager.ACTION_REFRESH_SAFETY_SOURCES;
|
||||
import static android.safetycenter.SafetyCenterManager.EXTRA_REFRESH_SAFETY_SOURCE_IDS;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settings.security.ScreenLockPreferenceDetailsUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.List;
|
||||
@@ -54,7 +57,8 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
private static void refreshSafetySources(Context context, List<String> sourceIds) {
|
||||
if (sourceIds.contains(LockScreenSafetySource.SAFETY_SOURCE_ID)) {
|
||||
LockScreenSafetySource.sendSafetyData(context);
|
||||
LockScreenSafetySource.sendSafetyData(context,
|
||||
new ScreenLockPreferenceDetailsUtils(context, SettingsEnums.SAFETY_CENTER));
|
||||
}
|
||||
|
||||
if (sourceIds.contains(BiometricsSafetySource.SAFETY_SOURCE_ID)) {
|
||||
@@ -63,7 +67,8 @@ public class SafetySourceBroadcastReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
private static void refreshAllSafetySources(Context context) {
|
||||
LockScreenSafetySource.sendSafetyData(context);
|
||||
LockScreenSafetySource.sendSafetyData(context,
|
||||
new ScreenLockPreferenceDetailsUtils(context, SettingsEnums.SAFETY_CENTER));
|
||||
BiometricsSafetySource.sendSafetyData(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,14 @@ package com.android.settings.security;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.os.storage.StorageManager;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.android.internal.app.UnlaunchableAppActivity;
|
||||
import com.android.internal.widget.LockPatternUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
@@ -81,21 +83,35 @@ public class ScreenLockPreferenceDetailsUtils {
|
||||
== DevicePolicyManager.PASSWORD_QUALITY_MANAGED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the lock pattern is secure.
|
||||
*/
|
||||
public boolean isLockPatternSecure() {
|
||||
return mLockPatternUtils.isSecure(mUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the Gear Menu should be shown.
|
||||
*/
|
||||
public boolean shouldShowGearMenu() {
|
||||
return mLockPatternUtils.isSecure(mUserId);
|
||||
return isLockPatternSecure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches the {@link ScreenLockSettings}.
|
||||
*/
|
||||
public void openScreenLockSettings() {
|
||||
new SubSettingLauncher(mContext)
|
||||
mContext.startActivity(getLaunchScreenLockSettingsIntent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@link Intent} to launch the {@link ScreenLockSettings}.
|
||||
*/
|
||||
public Intent getLaunchScreenLockSettingsIntent() {
|
||||
return new SubSettingLauncher(mContext)
|
||||
.setDestination(ScreenLockSettings.class.getName())
|
||||
.setSourceMetricsCategory(mSourceMetricsCategory)
|
||||
.launch();
|
||||
.toIntent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,6 +121,29 @@ public class ScreenLockPreferenceDetailsUtils {
|
||||
* @return true if the {@link ChooseLockGenericFragment} is launching.
|
||||
*/
|
||||
public boolean openChooseLockGenericFragment() {
|
||||
final Intent quietModeDialogIntent = getQuietModeDialogIntent();
|
||||
if (quietModeDialogIntent != null) {
|
||||
mContext.startActivity(quietModeDialogIntent);
|
||||
return false;
|
||||
}
|
||||
mContext.startActivity(getChooseLockGenericFragmentIntent());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@link Intent} to launch an appropriate Settings screen.
|
||||
*
|
||||
* <p>If Quiet Mode is enabled for managed profile, returns {@link Intent} to launch a dialog
|
||||
* to disable the Quiet Mode, otherwise returns {@link Intent} to launch
|
||||
* {@link ChooseLockGenericFragment}.
|
||||
*/
|
||||
public Intent getLaunchChooseLockGenericFragmentIntent() {
|
||||
final Intent quietModeDialogIntent = getQuietModeDialogIntent();
|
||||
return quietModeDialogIntent != null ? quietModeDialogIntent
|
||||
: getChooseLockGenericFragmentIntent();
|
||||
}
|
||||
|
||||
private Intent getQuietModeDialogIntent() {
|
||||
// TODO(b/35930129): Remove once existing password can be passed into vold directly.
|
||||
// Currently we need this logic to ensure that the QUIET_MODE is off for any work
|
||||
// profile with unified challenge on FBE-enabled devices. Otherwise, vold would not be
|
||||
@@ -112,17 +151,20 @@ public class ScreenLockPreferenceDetailsUtils {
|
||||
if (mProfileChallengeUserId != UserHandle.USER_NULL
|
||||
&& !mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)
|
||||
&& StorageManager.isFileEncryptedNativeOnly()) {
|
||||
if (Utils.startQuietModeDialogIfNecessary(mContext, mUm, mProfileChallengeUserId)) {
|
||||
return false;
|
||||
if (mUm.isQuietModeEnabled(UserHandle.of(mProfileChallengeUserId))) {
|
||||
return UnlaunchableAppActivity.createInQuietModeDialogIntent(
|
||||
mProfileChallengeUserId);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
new SubSettingLauncher(mContext)
|
||||
private Intent getChooseLockGenericFragmentIntent() {
|
||||
return new SubSettingLauncher(mContext)
|
||||
.setDestination(ChooseLockGenericFragment.class.getName())
|
||||
.setSourceMetricsCategory(mSourceMetricsCategory)
|
||||
.setTransitionType(SettingsTransitionHelper.TransitionType.TRANSITION_SLIDE)
|
||||
.launch();
|
||||
return true;
|
||||
.toIntent();
|
||||
}
|
||||
|
||||
@StringRes
|
||||
|
||||
Reference in New Issue
Block a user