Merge "Launch work profile entries intent in the profile parent." into udc-dev
diff --git a/src/com/android/settings/safetycenter/BiometricsSafetySource.java b/src/com/android/settings/safetycenter/BiometricsSafetySource.java
index 74964ce..9dc5b4e 100644
--- a/src/com/android/settings/safetycenter/BiometricsSafetySource.java
+++ b/src/com/android/settings/safetycenter/BiometricsSafetySource.java
@@ -22,7 +22,9 @@
 import android.hardware.face.FaceManager;
 import android.hardware.fingerprint.FingerprintManager;
 import android.os.Bundle;
+import android.os.Process;
 import android.os.UserHandle;
+import android.os.UserManager;
 import android.safetycenter.SafetyEvent;
 import android.safetycenter.SafetySourceData;
 import android.safetycenter.SafetySourceStatus;
@@ -43,8 +45,7 @@
     private static final int REQUEST_CODE_FACE_SETTING = 20;
     private static final int REQUEST_CODE_FINGERPRINT_SETTING = 30;
 
-    private BiometricsSafetySource() {
-    }
+    private BiometricsSafetySource() {}
 
     /** Sets biometric safety data for Safety Center. */
     public static void setSafetySourceData(Context context, SafetyEvent safetyEvent) {
@@ -52,41 +53,59 @@
             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(
-                userId);
+        final BiometricNavigationUtils biometricNavigationUtils =
+                new BiometricNavigationUtils(userId);
         final CombinedBiometricStatusUtils combinedBiometricStatusUtils =
                 new CombinedBiometricStatusUtils(context, userId);
         final ActiveUnlockStatusUtils activeUnlockStatusUtils =
                 new ActiveUnlockStatusUtils(context);
-        if (activeUnlockStatusUtils.isAvailable()) {
+        if (!userManager.isProfile() && activeUnlockStatusUtils.isAvailable()) {
             final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
                     combinedBiometricStatusUtils.getDisablingAdmin();
-            setBiometricSafetySourceData(context,
+            setBiometricSafetySourceData(
+                    context,
                     activeUnlockStatusUtils.getTitleForActiveUnlock(),
                     combinedBiometricStatusUtils.getSummary(),
-                    createPendingIntent(context,
-                            biometricNavigationUtils.getBiometricSettingsIntent(context,
+                    createPendingIntent(
+                            context,
+                            biometricNavigationUtils.getBiometricSettingsIntent(
+                                    context,
                                     combinedBiometricStatusUtils.getSettingsClassName(),
-                                    disablingAdmin, Bundle.EMPTY),
+                                    disablingAdmin,
+                                    Bundle.EMPTY),
                             REQUEST_CODE_COMBINED_BIOMETRIC_SETTING),
                     disablingAdmin == null /* enabled */,
                     combinedBiometricStatusUtils.hasEnrolled(),
                     safetyEvent);
             return;
-
         }
         if (combinedBiometricStatusUtils.isAvailable()) {
             final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
                     combinedBiometricStatusUtils.getDisablingAdmin();
-            setBiometricSafetySourceData(context,
+            setBiometricSafetySourceData(
+                    context,
                     combinedBiometricStatusUtils.getTitle(),
                     combinedBiometricStatusUtils.getSummary(),
-                    createPendingIntent(context,
-                            biometricNavigationUtils.getBiometricSettingsIntent(context,
-                                    combinedBiometricStatusUtils.getSettingsClassNameBasedOnUser(),
-                                    disablingAdmin, Bundle.EMPTY),
+                    createPendingIntent(
+                            profileParentContext,
+                            biometricNavigationUtils
+                                    .getBiometricSettingsIntent(
+                                            context,
+                                            combinedBiometricStatusUtils
+                                                    .getSettingsClassNameBasedOnUser(),
+                                            disablingAdmin,
+                                            Bundle.EMPTY)
+                                    .setIdentifier(Integer.toString(userId)),
                             REQUEST_CODE_COMBINED_BIOMETRIC_SETTING),
                     disablingAdmin == null /* enabled */,
                     combinedBiometricStatusUtils.hasEnrolled(),
@@ -100,13 +119,19 @@
         if (faceStatusUtils.isAvailable()) {
             final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
                     faceStatusUtils.getDisablingAdmin();
-            setBiometricSafetySourceData(context,
+            setBiometricSafetySourceData(
+                    context,
                     faceStatusUtils.getTitle(),
                     faceStatusUtils.getSummary(),
-                    createPendingIntent(context,
-                            biometricNavigationUtils.getBiometricSettingsIntent(context,
-                                    faceStatusUtils.getSettingsClassName(), disablingAdmin,
-                                    Bundle.EMPTY),
+                    createPendingIntent(
+                            profileParentContext,
+                            biometricNavigationUtils
+                                    .getBiometricSettingsIntent(
+                                            context,
+                                            faceStatusUtils.getSettingsClassName(),
+                                            disablingAdmin,
+                                            Bundle.EMPTY)
+                                    .setIdentifier(Integer.toString(userId)),
                             REQUEST_CODE_FACE_SETTING),
                     disablingAdmin == null /* enabled */,
                     faceStatusUtils.hasEnrolled(),
@@ -116,19 +141,25 @@
         }
 
         final FingerprintManager fingerprintManager = Utils.getFingerprintManagerOrNull(context);
-        final FingerprintStatusUtils fingerprintStatusUtils = new FingerprintStatusUtils(context,
-                fingerprintManager, userId);
+        final FingerprintStatusUtils fingerprintStatusUtils =
+                new FingerprintStatusUtils(context, fingerprintManager, userId);
 
         if (fingerprintStatusUtils.isAvailable()) {
             final RestrictedLockUtils.EnforcedAdmin disablingAdmin =
                     fingerprintStatusUtils.getDisablingAdmin();
-            setBiometricSafetySourceData(context,
+            setBiometricSafetySourceData(
+                    context,
                     fingerprintStatusUtils.getTitle(),
                     fingerprintStatusUtils.getSummary(),
-                    createPendingIntent(context,
-                            biometricNavigationUtils.getBiometricSettingsIntent(context,
-                                    fingerprintStatusUtils.getSettingsClassName(), disablingAdmin,
-                                    Bundle.EMPTY),
+                    createPendingIntent(
+                            profileParentContext,
+                            biometricNavigationUtils
+                                    .getBiometricSettingsIntent(
+                                            context,
+                                            fingerprintStatusUtils.getSettingsClassName(),
+                                            disablingAdmin,
+                                            Bundle.EMPTY)
+                                    .setIdentifier(Integer.toString(userId)),
                             REQUEST_CODE_FINGERPRINT_SETTING),
                     disablingAdmin == null /* enabled */,
                     fingerprintStatusUtils.hasEnrolled(),
@@ -140,33 +171,38 @@
     public static void onBiometricsChanged(Context context) {
         setSafetySourceData(
                 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,
-            PendingIntent pendingIntent, boolean enabled, boolean hasEnrolled,
+    private static void setBiometricSafetySourceData(
+            Context context,
+            String title,
+            String summary,
+            PendingIntent pendingIntent,
+            boolean enabled,
+            boolean hasEnrolled,
             SafetyEvent safetyEvent) {
         final int severityLevel =
-                enabled && hasEnrolled ? SafetySourceData.SEVERITY_LEVEL_INFORMATION
+                enabled && hasEnrolled
+                        ? SafetySourceData.SEVERITY_LEVEL_INFORMATION
                         : SafetySourceData.SEVERITY_LEVEL_UNSPECIFIED;
 
-        final SafetySourceStatus status = new SafetySourceStatus.Builder(title, summary,
-                severityLevel).setPendingIntent(pendingIntent).setEnabled(enabled).build();
+        final SafetySourceStatus status =
+                new SafetySourceStatus.Builder(title, summary, severityLevel)
+                        .setPendingIntent(pendingIntent)
+                        .setEnabled(enabled)
+                        .build();
         final SafetySourceData safetySourceData =
                 new SafetySourceData.Builder().setStatus(status).build();
 
-        SafetyCenterManagerWrapper.get().setSafetySourceData(
-                context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent);
+        SafetyCenterManagerWrapper.get()
+                .setSafetySourceData(context, SAFETY_SOURCE_ID, safetySourceData, safetyEvent);
     }
 
-    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);
     }
 }