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

Commit 8f4bd238 authored by Dave Mankoff's avatar Dave Mankoff Committed by Android (Google) Code Review
Browse files

Merge "Inject SystemUIDialog into BiometricNotificationDialogFactory." into main

parents 035e13c0 167170fd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public class SystemUIDialogTest extends SysuiTestCase {
    @Mock
    private BroadcastDispatcher mBroadcastDispatcher;
    @Mock
    private DialogDelegate<SystemUIDialog> mDelegate;
    private SystemUIDialog.Delegate mDelegate;

    @Before
    public void setup() {
+8 −9
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.UserSwitcherController;

import dagger.Lazy;
import dagger.assisted.Assisted;
import dagger.assisted.AssistedFactory;
import dagger.assisted.AssistedInject;
@@ -141,23 +140,23 @@ public final class GuestResetOrExitSessionReceiver extends BroadcastReceiver {
     * reset and restart of guest user.
     */
    public static final class ResetSessionDialogFactory {
        private final Lazy<SystemUIDialog> mDialogLazy;
        private final SystemUIDialog.Factory mDialogFactory;
        private final Resources mResources;
        private final ResetSessionDialogClickListener.Factory mClickListenerFactory;

        @Inject
        public ResetSessionDialogFactory(
                Lazy<SystemUIDialog> dialogLazy,
                SystemUIDialog.Factory dialogFactory,
                @Main Resources resources,
                ResetSessionDialogClickListener.Factory clickListenerFactory) {
            mDialogLazy = dialogLazy;
            mDialogFactory = dialogFactory;
            mResources = resources;
            mClickListenerFactory = clickListenerFactory;
        }

        /** Create a guest reset dialog instance */
        public AlertDialog create(int userId) {
            SystemUIDialog dialog = mDialogLazy.get();
            SystemUIDialog dialog = mDialogFactory.create();
            ResetSessionDialogClickListener listener = mClickListenerFactory.create(
                    userId, dialog);
            dialog.setTitle(com.android.settingslib.R.string.guest_reset_and_restart_dialog_title);
@@ -216,22 +215,22 @@ public final class GuestResetOrExitSessionReceiver extends BroadcastReceiver {
     * exit of guest user.
     */
    public static final class ExitSessionDialogFactory {
        private final Lazy<SystemUIDialog> mDialogLazy;
        private final SystemUIDialog.Factory mDialogFactory;
        private final ExitSessionDialogClickListener.Factory mClickListenerFactory;
        private final Resources mResources;

        @Inject
        public ExitSessionDialogFactory(
                Lazy<SystemUIDialog> dialogLazy,
                SystemUIDialog.Factory dialogFactory,
                ExitSessionDialogClickListener.Factory clickListenerFactory,
                @Main Resources resources) {
            mDialogLazy = dialogLazy;
            mDialogFactory = dialogFactory;
            mClickListenerFactory = clickListenerFactory;
            mResources = resources;
        }

        public AlertDialog create(boolean isEphemeral, int userId) {
            SystemUIDialog dialog = mDialogLazy.get();
            SystemUIDialog dialog = mDialogFactory.create();
            ExitSessionDialogClickListener clickListener = mClickListenerFactory.create(
                    isEphemeral, userId, dialog);
            if (isEphemeral) {
+7 −6
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.content.Intent;
import android.hardware.biometrics.BiometricSourceType;

import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.statusbar.phone.SystemUIDialog;

import javax.inject.Inject;

@@ -41,7 +40,8 @@ public class BiometricNotificationBroadcastReceiver extends BroadcastReceiver {
    private final Context mContext;
    private final BiometricNotificationDialogFactory mNotificationDialogFactory;
    @Inject
    BiometricNotificationBroadcastReceiver(Context context,
    BiometricNotificationBroadcastReceiver(
            Context context,
            BiometricNotificationDialogFactory notificationDialogFactory) {
        mContext = context;
        mNotificationDialogFactory = notificationDialogFactory;
@@ -53,15 +53,16 @@ public class BiometricNotificationBroadcastReceiver extends BroadcastReceiver {

        switch (action) {
            case ACTION_SHOW_FACE_REENROLL_DIALOG:
                mNotificationDialogFactory.createReenrollDialog(mContext,
                        new SystemUIDialog(mContext),
                mNotificationDialogFactory.createReenrollDialog(
                        mContext.getUserId(),
                        mContext::startActivity,
                        BiometricSourceType.FACE)
                        .show();
                break;
            case ACTION_SHOW_FINGERPRINT_REENROLL_DIALOG:
                mNotificationDialogFactory.createReenrollDialog(
                        mContext,
                        new SystemUIDialog(mContext),
                        mContext.getUserId(),
                        mContext::startActivity,
                        BiometricSourceType.FINGERPRINT)
                        .show();
                break;
+62 −42
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package com.android.systemui.biometrics;

import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.hardware.biometrics.BiometricSourceType;
import android.hardware.face.Face;
import android.hardware.face.FaceManager;
@@ -29,9 +31,11 @@ import android.util.Log;

import com.android.systemui.res.R;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.statusbar.phone.SystemUIDialog;

import javax.inject.Inject;
import javax.inject.Provider;

/**
 * Manages the creation of dialogs to be shown for biometric re enroll notifications.
@@ -39,44 +43,56 @@ import javax.inject.Inject;
@SysUISingleton
public class BiometricNotificationDialogFactory {
    private static final String TAG = "BiometricNotificationDialogFactory";
    private final Resources mResources;
    private final SystemUIDialog.Factory mSystemUIDialogFactory;
    @Nullable private final FingerprintManager mFingerprintManager;
    @Nullable private final FaceManager mFaceManager;

    @Inject
    BiometricNotificationDialogFactory() {}

    Dialog createReenrollDialog(final Context context, final SystemUIDialog sysuiDialog,
            BiometricSourceType biometricSourceType) {
    BiometricNotificationDialogFactory(
            @Main Resources resources,
            SystemUIDialog.Factory systemUIDialogFactory,
            @Nullable FingerprintManager fingerprintManager,
            @Nullable FaceManager faceManager) {
        mResources = resources;
        mSystemUIDialogFactory = systemUIDialogFactory;
        mFingerprintManager = fingerprintManager;
        mFaceManager = faceManager;
    }

    Dialog createReenrollDialog(
            int userId, ActivityStarter activityStarter, BiometricSourceType biometricSourceType) {
        SystemUIDialog sysuiDialog = mSystemUIDialogFactory.create();
        if (biometricSourceType == BiometricSourceType.FACE) {
            sysuiDialog.setTitle(context.getString(R.string.face_re_enroll_dialog_title));
            sysuiDialog.setMessage(context.getString(R.string.face_re_enroll_dialog_content));
            sysuiDialog.setTitle(mResources.getString(R.string.face_re_enroll_dialog_title));
            sysuiDialog.setMessage(mResources.getString(R.string.face_re_enroll_dialog_content));
        } else if (biometricSourceType == BiometricSourceType.FINGERPRINT) {
            FingerprintManager fingerprintManager = context.getSystemService(
                    FingerprintManager.class);
            sysuiDialog.setTitle(context.getString(R.string.fingerprint_re_enroll_dialog_title));
            if (fingerprintManager.getEnrolledFingerprints().size() == 1) {
                sysuiDialog.setMessage(context.getString(
            sysuiDialog.setTitle(mResources.getString(R.string.fingerprint_re_enroll_dialog_title));
            if (mFingerprintManager.getEnrolledFingerprints().size() == 1) {
                sysuiDialog.setMessage(mResources.getString(
                        R.string.fingerprint_re_enroll_dialog_content_singular));
            } else {
                sysuiDialog.setMessage(context.getString(
                sysuiDialog.setMessage(mResources.getString(
                        R.string.fingerprint_re_enroll_dialog_content));
            }
        }

        sysuiDialog.setPositiveButton(R.string.biometric_re_enroll_dialog_confirm,
                (dialog, which) -> onReenrollDialogConfirm(context, biometricSourceType));
                (dialog, which) -> onReenrollDialogConfirm(
                        userId, biometricSourceType, activityStarter));
        sysuiDialog.setNegativeButton(R.string.biometric_re_enroll_dialog_cancel,
                (dialog, which) -> {});
        return sysuiDialog;
    }

    private static Dialog createReenrollFailureDialog(Context context,
            BiometricSourceType biometricType) {
        final SystemUIDialog sysuiDialog = new SystemUIDialog(context);
    private Dialog createReenrollFailureDialog(BiometricSourceType biometricType) {
        final SystemUIDialog sysuiDialog = mSystemUIDialogFactory.create();

        if (biometricType == BiometricSourceType.FACE) {
            sysuiDialog.setMessage(context.getString(
            sysuiDialog.setMessage(mResources.getString(
                    R.string.face_reenroll_failure_dialog_content));
        } else if (biometricType == BiometricSourceType.FINGERPRINT) {
            sysuiDialog.setMessage(context.getString(
            sysuiDialog.setMessage(mResources.getString(
                    R.string.fingerprint_reenroll_failure_dialog_content));
        }

@@ -84,41 +100,41 @@ public class BiometricNotificationDialogFactory {
        return sysuiDialog;
    }

    private static void onReenrollDialogConfirm(final Context context,
            BiometricSourceType biometricType) {
    private void onReenrollDialogConfirm(
            int userId, BiometricSourceType biometricType, ActivityStarter activityStarter) {
        if (biometricType == BiometricSourceType.FACE) {
            reenrollFace(context);
            reenrollFace(userId, activityStarter);
        } else if (biometricType == BiometricSourceType.FINGERPRINT) {
            reenrollFingerprint(context);
            reenrollFingerprint(userId, activityStarter);
        }
    }

    private static void reenrollFingerprint(Context context) {
        FingerprintManager fingerprintManager = context.getSystemService(FingerprintManager.class);
        if (fingerprintManager == null) {
    @SuppressLint("MissingPermission")
    private void reenrollFingerprint(int userId, ActivityStarter activityStarter) {
        if (mFingerprintManager == null) {
            Log.e(TAG, "Not launching enrollment. Fingerprint manager was null!");
            createReenrollFailureDialog(context, BiometricSourceType.FINGERPRINT).show();
            createReenrollFailureDialog(BiometricSourceType.FINGERPRINT).show();
            return;
        }

        if (!fingerprintManager.hasEnrolledTemplates(context.getUserId())) {
            createReenrollFailureDialog(context, BiometricSourceType.FINGERPRINT).show();
        if (!mFingerprintManager.hasEnrolledTemplates(userId)) {
            createReenrollFailureDialog(BiometricSourceType.FINGERPRINT).show();
            return;
        }

        // Remove all enrolled fingerprint. Launch enrollment if successful.
        fingerprintManager.removeAll(context.getUserId(),
        mFingerprintManager.removeAll(userId,
                new FingerprintManager.RemovalCallback() {
                    boolean mDidShowFailureDialog;

                    @Override
                    public void onRemovalError(Fingerprint fingerprint, int errMsgId,
                            CharSequence errString) {
                    public void onRemovalError(
                            Fingerprint fingerprint, int errMsgId, CharSequence errString) {
                        Log.e(TAG, "Not launching enrollment."
                                + "Failed to remove existing face(s).");
                        if (!mDidShowFailureDialog) {
                            mDidShowFailureDialog = true;
                            createReenrollFailureDialog(context, BiometricSourceType.FINGERPRINT)
                            createReenrollFailureDialog(BiometricSourceType.FINGERPRINT)
                                    .show();
                        }
                    }
@@ -129,27 +145,27 @@ public class BiometricNotificationDialogFactory {
                            Intent intent = new Intent(Settings.ACTION_FINGERPRINT_ENROLL);
                            intent.setPackage("com.android.settings");
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(intent);
                            activityStarter.startActivity(intent);
                        }
                    }
                });
    }

    private static void reenrollFace(Context context) {
        FaceManager faceManager = context.getSystemService(FaceManager.class);
        if (faceManager == null) {
    @SuppressLint("MissingPermission")
    private void reenrollFace(int userId, ActivityStarter activityStarter) {
        if (mFaceManager == null) {
            Log.e(TAG, "Not launching enrollment. Face manager was null!");
            createReenrollFailureDialog(context, BiometricSourceType.FACE).show();
            createReenrollFailureDialog(BiometricSourceType.FACE).show();
            return;
        }

        if (!faceManager.hasEnrolledTemplates(context.getUserId())) {
            createReenrollFailureDialog(context, BiometricSourceType.FACE).show();
        if (!mFaceManager.hasEnrolledTemplates(userId)) {
            createReenrollFailureDialog(BiometricSourceType.FACE).show();
            return;
        }

        // Remove all enrolled faces. Launch enrollment if successful.
        faceManager.removeAll(context.getUserId(),
        mFaceManager.removeAll(userId,
                new FaceManager.RemovalCallback() {
                    boolean mDidShowFailureDialog;

@@ -159,7 +175,7 @@ public class BiometricNotificationDialogFactory {
                                + "Failed to remove existing face(s).");
                        if (!mDidShowFailureDialog) {
                            mDidShowFailureDialog = true;
                            createReenrollFailureDialog(context, BiometricSourceType.FACE).show();
                            createReenrollFailureDialog(BiometricSourceType.FACE).show();
                        }
                    }

@@ -169,9 +185,13 @@ public class BiometricNotificationDialogFactory {
                            Intent intent = new Intent("android.settings.FACE_ENROLL");
                            intent.setPackage("com.android.settings");
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(intent);
                            activityStarter.startActivity(intent);
                        }
                    }
                });
    }

    interface ActivityStarter {
        void startActivity(Intent intent);
    }
}
+10 −26
Original line number Diff line number Diff line
@@ -16,16 +16,11 @@

package com.android.systemui.bluetooth;

import android.annotation.Nullable;
import android.content.Context;
import android.view.View;

import com.android.internal.logging.UiEventLogger;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.systemui.animation.DialogLaunchAnimator;
import com.android.systemui.broadcast.BroadcastSender;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.media.dialog.MediaOutputDialogFactory;
import com.android.systemui.statusbar.phone.SystemUIDialog;

import javax.inject.Inject;

@@ -35,25 +30,15 @@ import javax.inject.Inject;
@SysUISingleton
public class BroadcastDialogController {

    private Context mContext;
    private UiEventLogger mUiEventLogger;
    private DialogLaunchAnimator mDialogLaunchAnimator;
    private MediaOutputDialogFactory mMediaOutputDialogFactory;
    private final LocalBluetoothManager mLocalBluetoothManager;
    private BroadcastSender mBroadcastSender;
    private final DialogLaunchAnimator mDialogLaunchAnimator;
    private final BroadcastDialogDelegate.Factory mBroadcastDialogFactory;

    @Inject
    public BroadcastDialogController(Context context, UiEventLogger uiEventLogger,
    public BroadcastDialogController(
            DialogLaunchAnimator dialogLaunchAnimator,
            MediaOutputDialogFactory mediaOutputDialogFactory,
            @Nullable LocalBluetoothManager localBluetoothManager,
            BroadcastSender broadcastSender) {
        mContext = context;
        mUiEventLogger = uiEventLogger;
            BroadcastDialogDelegate.Factory broadcastDialogFactory) {
        mDialogLaunchAnimator = dialogLaunchAnimator;
        mMediaOutputDialogFactory = mediaOutputDialogFactory;
        mLocalBluetoothManager = localBluetoothManager;
        mBroadcastSender = broadcastSender;
        mBroadcastDialogFactory = broadcastDialogFactory;
    }

    /** Creates a [BroadcastDialog] for the user to switch broadcast or change the output device
@@ -61,11 +46,10 @@ public class BroadcastDialogController {
     * @param currentBroadcastAppName Indicates the APP name currently broadcasting
     * @param outputPkgName Indicates the output media package name to be switched
     */
    public void createBroadcastDialog(String currentBroadcastAppName, String outputPkgName,
            boolean aboveStatusBar, View view) {
        BroadcastDialog broadcastDialog = new BroadcastDialog(mContext, mMediaOutputDialogFactory,
                mLocalBluetoothManager, currentBroadcastAppName, outputPkgName, mUiEventLogger,
                mBroadcastSender);
    public void createBroadcastDialog(
            String currentBroadcastAppName, String outputPkgName, View view) {
        SystemUIDialog broadcastDialog = mBroadcastDialogFactory.create(
                currentBroadcastAppName, outputPkgName).createDialog();
        if (view != null) {
            mDialogLaunchAnimator.showFromView(broadcastDialog, view);
        } else {
Loading