Launch work profile entries intent in the profile parent.
The screens don't work as expected if they're launched in the work profile. The reason for this is that Settings handle the user separately with an extra inside the intent. I assume launching the actual screen in a separate user is not supported. Note that I've also: 1. Added a safeguard to make sure that the "active unlock" code path only occurs in the profile parent — it seems preferrable (see b/277877289#comment4) 2. Added the user id as an identifier on the intents lauched by the entries. The reason we do this is to make sure the user id is taken into account in the PendingIntent#equals implementation. This was automatically taken care of when launching with the profile context, but now that we launch everything in the profile parent context we have to make sure the user id is taken into account Bug: 278665241 Bug: 277877289 Test: manual Change-Id: Idcaa31cd56ed64768aa8f069d30d2adeb7269099
This commit is contained in:
@@ -22,7 +22,9 @@ import android.content.Intent;
|
|||||||
import android.hardware.face.FaceManager;
|
import android.hardware.face.FaceManager;
|
||||||
import android.hardware.fingerprint.FingerprintManager;
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Process;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.safetycenter.SafetyEvent;
|
import android.safetycenter.SafetyEvent;
|
||||||
import android.safetycenter.SafetySourceData;
|
import android.safetycenter.SafetySourceData;
|
||||||
import android.safetycenter.SafetySourceStatus;
|
import android.safetycenter.SafetySourceStatus;
|
||||||
@@ -43,8 +45,7 @@ public final class BiometricsSafetySource {
|
|||||||
private static final int REQUEST_CODE_FACE_SETTING = 20;
|
private static final int REQUEST_CODE_FACE_SETTING = 20;
|
||||||
private static final int REQUEST_CODE_FINGERPRINT_SETTING = 30;
|
private static final int REQUEST_CODE_FINGERPRINT_SETTING = 30;
|
||||||
|
|
||||||
private BiometricsSafetySource() {
|
private BiometricsSafetySource() {}
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets biometric safety data for Safety Center. */
|
/** Sets biometric safety data for Safety Center. */
|
||||||
public static void setSafetySourceData(Context context, SafetyEvent safetyEvent) {
|
public static void setSafetySourceData(Context context, SafetyEvent safetyEvent) {
|
||||||
@@ -52,41 +53,59 @@ public final class BiometricsSafetySource {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int userId = UserHandle.myUserId();
|
final UserHandle userHandle = Process.myUserHandle();
|
||||||
|
final int userId = userHandle.getIdentifier();
|
||||||
|
final UserManager userManager = UserManager.get(context);
|
||||||
|
UserHandle profileParentUserHandle = userManager.getProfileParent(userHandle);
|
||||||
|
if (profileParentUserHandle == null) {
|
||||||
|
profileParentUserHandle = userHandle;
|
||||||
|
}
|
||||||
|
final Context profileParentContext =
|
||||||
|
context.createContextAsUser(profileParentUserHandle, 0);
|
||||||
|
|
||||||
final BiometricNavigationUtils biometricNavigationUtils = new BiometricNavigationUtils(
|
final BiometricNavigationUtils biometricNavigationUtils =
|
||||||
userId);
|
new BiometricNavigationUtils(userId);
|
||||||
final CombinedBiometricStatusUtils combinedBiometricStatusUtils =
|
final CombinedBiometricStatusUtils combinedBiometricStatusUtils =
|
||||||
new CombinedBiometricStatusUtils(context, userId);
|
new CombinedBiometricStatusUtils(context, userId);
|
||||||
final ActiveUnlockStatusUtils activeUnlockStatusUtils =
|
final ActiveUnlockStatusUtils activeUnlockStatusUtils =
|
||||||
new ActiveUnlockStatusUtils(context);
|
new ActiveUnlockStatusUtils(context);
|
||||||
if (activeUnlockStatusUtils.isAvailable()) {
|
if (!userManager.isProfile() && activeUnlockStatusUtils.isAvailable()) {
|
||||||
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
|
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
|
||||||
combinedBiometricStatusUtils.getDisablingAdmin();
|
combinedBiometricStatusUtils.getDisablingAdmin();
|
||||||
setBiometricSafetySourceData(context,
|
setBiometricSafetySourceData(
|
||||||
|
context,
|
||||||
activeUnlockStatusUtils.getTitleForActiveUnlock(),
|
activeUnlockStatusUtils.getTitleForActiveUnlock(),
|
||||||
combinedBiometricStatusUtils.getSummary(),
|
combinedBiometricStatusUtils.getSummary(),
|
||||||
createPendingIntent(context,
|
createPendingIntent(
|
||||||
biometricNavigationUtils.getBiometricSettingsIntent(context,
|
context,
|
||||||
|
biometricNavigationUtils.getBiometricSettingsIntent(
|
||||||
|
context,
|
||||||
combinedBiometricStatusUtils.getSettingsClassName(),
|
combinedBiometricStatusUtils.getSettingsClassName(),
|
||||||
disablingAdmin, Bundle.EMPTY),
|
disablingAdmin,
|
||||||
|
Bundle.EMPTY),
|
||||||
REQUEST_CODE_COMBINED_BIOMETRIC_SETTING),
|
REQUEST_CODE_COMBINED_BIOMETRIC_SETTING),
|
||||||
disablingAdmin == null /* enabled */,
|
disablingAdmin == null /* enabled */,
|
||||||
combinedBiometricStatusUtils.hasEnrolled(),
|
combinedBiometricStatusUtils.hasEnrolled(),
|
||||||
safetyEvent);
|
safetyEvent);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (combinedBiometricStatusUtils.isAvailable()) {
|
if (combinedBiometricStatusUtils.isAvailable()) {
|
||||||
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
|
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
|
||||||
combinedBiometricStatusUtils.getDisablingAdmin();
|
combinedBiometricStatusUtils.getDisablingAdmin();
|
||||||
setBiometricSafetySourceData(context,
|
setBiometricSafetySourceData(
|
||||||
|
context,
|
||||||
combinedBiometricStatusUtils.getTitle(),
|
combinedBiometricStatusUtils.getTitle(),
|
||||||
combinedBiometricStatusUtils.getSummary(),
|
combinedBiometricStatusUtils.getSummary(),
|
||||||
createPendingIntent(context,
|
createPendingIntent(
|
||||||
biometricNavigationUtils.getBiometricSettingsIntent(context,
|
profileParentContext,
|
||||||
combinedBiometricStatusUtils.getSettingsClassNameBasedOnUser(),
|
biometricNavigationUtils
|
||||||
disablingAdmin, Bundle.EMPTY),
|
.getBiometricSettingsIntent(
|
||||||
|
context,
|
||||||
|
combinedBiometricStatusUtils
|
||||||
|
.getSettingsClassNameBasedOnUser(),
|
||||||
|
disablingAdmin,
|
||||||
|
Bundle.EMPTY)
|
||||||
|
.setIdentifier(Integer.toString(userId)),
|
||||||
REQUEST_CODE_COMBINED_BIOMETRIC_SETTING),
|
REQUEST_CODE_COMBINED_BIOMETRIC_SETTING),
|
||||||
disablingAdmin == null /* enabled */,
|
disablingAdmin == null /* enabled */,
|
||||||
combinedBiometricStatusUtils.hasEnrolled(),
|
combinedBiometricStatusUtils.hasEnrolled(),
|
||||||
@@ -100,13 +119,19 @@ public final class BiometricsSafetySource {
|
|||||||
if (faceStatusUtils.isAvailable()) {
|
if (faceStatusUtils.isAvailable()) {
|
||||||
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
|
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
|
||||||
faceStatusUtils.getDisablingAdmin();
|
faceStatusUtils.getDisablingAdmin();
|
||||||
setBiometricSafetySourceData(context,
|
setBiometricSafetySourceData(
|
||||||
|
context,
|
||||||
faceStatusUtils.getTitle(),
|
faceStatusUtils.getTitle(),
|
||||||
faceStatusUtils.getSummary(),
|
faceStatusUtils.getSummary(),
|
||||||
createPendingIntent(context,
|
createPendingIntent(
|
||||||
biometricNavigationUtils.getBiometricSettingsIntent(context,
|
profileParentContext,
|
||||||
faceStatusUtils.getSettingsClassName(), disablingAdmin,
|
biometricNavigationUtils
|
||||||
Bundle.EMPTY),
|
.getBiometricSettingsIntent(
|
||||||
|
context,
|
||||||
|
faceStatusUtils.getSettingsClassName(),
|
||||||
|
disablingAdmin,
|
||||||
|
Bundle.EMPTY)
|
||||||
|
.setIdentifier(Integer.toString(userId)),
|
||||||
REQUEST_CODE_FACE_SETTING),
|
REQUEST_CODE_FACE_SETTING),
|
||||||
disablingAdmin == null /* enabled */,
|
disablingAdmin == null /* enabled */,
|
||||||
faceStatusUtils.hasEnrolled(),
|
faceStatusUtils.hasEnrolled(),
|
||||||
@@ -116,19 +141,25 @@ public final class BiometricsSafetySource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(context);
|
final FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(context);
|
||||||
final FingerprintStatusUtils fingerprintStatusUtils = new FingerprintStatusUtils(context,
|
final FingerprintStatusUtils fingerprintStatusUtils =
|
||||||
fingerprintManager, userId);
|
new FingerprintStatusUtils(context, fingerprintManager, userId);
|
||||||
|
|
||||||
if (fingerprintStatusUtils.isAvailable()) {
|
if (fingerprintStatusUtils.isAvailable()) {
|
||||||
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
|
final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
|
||||||
fingerprintStatusUtils.getDisablingAdmin();
|
fingerprintStatusUtils.getDisablingAdmin();
|
||||||
setBiometricSafetySourceData(context,
|
setBiometricSafetySourceData(
|
||||||
|
context,
|
||||||
fingerprintStatusUtils.getTitle(),
|
fingerprintStatusUtils.getTitle(),
|
||||||
fingerprintStatusUtils.getSummary(),
|
fingerprintStatusUtils.getSummary(),
|
||||||
createPendingIntent(context,
|
createPendingIntent(
|
||||||
biometricNavigationUtils.getBiometricSettingsIntent(context,
|
profileParentContext,
|
||||||
fingerprintStatusUtils.getSettingsClassName(), disablingAdmin,
|
biometricNavigationUtils
|
||||||
Bundle.EMPTY),
|
.getBiometricSettingsIntent(
|
||||||
|
context,
|
||||||
|
fingerprintStatusUtils.getSettingsClassName(),
|
||||||
|
disablingAdmin,
|
||||||
|
Bundle.EMPTY)
|
||||||
|
.setIdentifier(Integer.toString(userId)),
|
||||||
REQUEST_CODE_FINGERPRINT_SETTING),
|
REQUEST_CODE_FINGERPRINT_SETTING),
|
||||||
disablingAdmin == null /* enabled */,
|
disablingAdmin == null /* enabled */,
|
||||||
fingerprintStatusUtils.hasEnrolled(),
|
fingerprintStatusUtils.hasEnrolled(),
|
||||||
@@ -140,33 +171,38 @@ public final class BiometricsSafetySource {
|
|||||||
public static void onBiometricsChanged(Context context) {
|
public static void onBiometricsChanged(Context context) {
|
||||||
setSafetySourceData(
|
setSafetySourceData(
|
||||||
context,
|
context,
|
||||||
new SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build()
|
new SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED)
|
||||||
);
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setBiometricSafetySourceData(Context context, String title, String summary,
|
private static void setBiometricSafetySourceData(
|
||||||
PendingIntent pendingIntent, boolean enabled, boolean hasEnrolled,
|
Context context,
|
||||||
|
String title,
|
||||||
|
String summary,
|
||||||
|
PendingIntent pendingIntent,
|
||||||
|
boolean enabled,
|
||||||
|
boolean hasEnrolled,
|
||||||
SafetyEvent safetyEvent) {
|
SafetyEvent safetyEvent) {
|
||||||
final int severityLevel =
|
final int severityLevel =
|
||||||
enabled && hasEnrolled ? SafetySourceData.SEVERITY_LEVEL_INFORMATION
|
enabled && hasEnrolled
|
||||||
|
? SafetySourceData.SEVERITY_LEVEL_INFORMATION
|
||||||
: SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
|
: SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
|
||||||
|
|
||||||
final SafetySourceStatus status = new SafetySourceStatus.Builder(title, summary,
|
final SafetySourceStatus status =
|
||||||
severityLevel).setPendingIntent(pendingIntent).setEnabled(enabled).build();
|
new SafetySourceStatus.Builder(title, summary, severityLevel)
|
||||||
|
.setPendingIntent(pendingIntent)
|
||||||
|
.setEnabled(enabled)
|
||||||
|
.build();
|
||||||
final SafetySourceData safetySourceData =
|
final SafetySourceData safetySourceData =
|
||||||
new SafetySourceData.Builder().setStatus(status).build();
|
new SafetySourceData.Builder().setStatus(status).build();
|
||||||
|
|
||||||
SafetyCenterManagerWrapper.get().setSafetySourceData(
|
SafetyCenterManagerWrapper.get()
|
||||||
context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent);
|
.setSafetySourceData(context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PendingIntent createPendingIntent(Context context, Intent intent,
|
private static PendingIntent createPendingIntent(
|
||||||
int requestCode) {
|
Context context, Intent intent, int requestCode) {
|
||||||
return PendingIntent
|
return PendingIntent.getActivity(
|
||||||
.getActivity(
|
context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE);
|
||||||
context,
|
|
||||||
requestCode,
|
|
||||||
intent,
|
|
||||||
PendingIntent.FLAG_IMMUTABLE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user