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

Commit 5906c17c authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Clean up interface between controller and view

Fixes: 110753321

Test: tested with test app, no regression
Change-Id: I482d9733bc5e1380d251a82ad2747807608e6d6c
parent aa0dce2d
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.systemui.fingerprint;

/**
 * Callback interface for dialog views. These should be implemented by the controller (e.g.
 * FingerprintDialogImpl) and passed into their views (e.g. FingerprintDialogView).
 */
public interface DialogViewCallback {
    /**
     * Invoked when the user cancels authentication by tapping outside the prompt, etc. The dialog
     * should be dismissed.
     */
    void onUserCanceled();

    /**
     * Invoked when an error is shown. The dialog should be dismissed after a set amount of time.
     */
    void onErrorShown();

    /**
     * Invoked when the negative button is pressed. The client should be notified and the dialog
     * should be dismissed.
     */
    void onNegativePressed();

    /**
     * Invoked when the positive button is pressed. The client should be notified and the dialog
     * should be dismissed.
     */
    void onPositivePressed();
}
+33 −18
Original line number Diff line number Diff line
@@ -35,21 +35,20 @@ public class FingerprintDialogImpl extends SystemUI implements CommandQueue.Call
    private static final String TAG = "FingerprintDialogImpl";
    private static final boolean DEBUG = true;

    protected static final int MSG_SHOW_DIALOG = 1;
    protected static final int MSG_FINGERPRINT_AUTHENTICATED = 2;
    protected static final int MSG_FINGERPRINT_HELP = 3;
    protected static final int MSG_FINGERPRINT_ERROR = 4;
    protected static final int MSG_HIDE_DIALOG = 5;
    protected static final int MSG_BUTTON_NEGATIVE = 6;
    protected static final int MSG_USER_CANCELED = 7;
    protected static final int MSG_BUTTON_POSITIVE = 8;
    protected static final int MSG_CLEAR_MESSAGE = 9;

    private static final int MSG_SHOW_DIALOG = 1;
    private static final int MSG_FINGERPRINT_AUTHENTICATED = 2;
    private static final int MSG_FINGERPRINT_HELP = 3;
    private static final int MSG_FINGERPRINT_ERROR = 4;
    private static final int MSG_FINGERPRINT_DIALOG = 5;
    private static final int MSG_BUTTON_NEGATIVE = 6;
    private static final int MSG_USER_CANCELED = 7;
    private static final int MSG_BUTTON_POSITIVE = 8;

    private FingerprintDialogView mDialogView;
    private WindowManager mWindowManager;
    private IBiometricPromptReceiver mReceiver;
    private boolean mDialogShowing;
    private Callback mCallback = new Callback();

    private Handler mHandler = new Handler() {
        @Override
@@ -79,13 +78,33 @@ public class FingerprintDialogImpl extends SystemUI implements CommandQueue.Call
                case MSG_BUTTON_POSITIVE:
                    handleButtonPositive();
                    break;
                case MSG_CLEAR_MESSAGE:
                    handleClearMessage();
                    break;
            }
        }
    };

    private class Callback implements DialogViewCallback {
        @Override
        public void onUserCanceled() {
            mHandler.obtainMessage(FingerprintDialogImpl.MSG_USER_CANCELED).sendToTarget();
        }

        @Override
        public void onErrorShown() {
            mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_HIDE_DIALOG,
                    false /* userCanceled */), BiometricPrompt.HIDE_DIALOG_DELAY);
        }

        @Override
        public void onNegativePressed() {
            mHandler.obtainMessage(FingerprintDialogImpl.MSG_BUTTON_NEGATIVE).sendToTarget();
        }

        @Override
        public void onPositivePressed() {
            mHandler.obtainMessage(FingerprintDialogImpl.MSG_BUTTON_POSITIVE).sendToTarget();
        }
    }

    @Override
    public void start() {
        if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
@@ -93,7 +112,7 @@ public class FingerprintDialogImpl extends SystemUI implements CommandQueue.Call
        }
        getComponent(CommandQueue.class).addCallbacks(this);
        mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        mDialogView = new FingerprintDialogView(mContext, mHandler);
        mDialogView = new FingerprintDialogView(mContext, mCallback);
    }

    @Override
@@ -216,10 +235,6 @@ public class FingerprintDialogImpl extends SystemUI implements CommandQueue.Call
        handleHideDialog(false /* userCanceled */);
    }

    private void handleClearMessage() {
        mDialogView.resetMessage();
    }

    private void handleUserCanceled() {
        handleHideDialog(true /* userCanceled */);
    }
+29 −15
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -56,6 +57,8 @@ public class FingerprintDialogView extends LinearLayout {
    private static final int ANIMATION_DURATION_SHOW = 250; // ms
    private static final int ANIMATION_DURATION_AWAY = 350; // ms

    private static final int MSG_CLEAR_MESSAGE = 1;

    private static final int STATE_NONE = 0;
    private static final int STATE_FINGERPRINT = 1;
    private static final int STATE_FINGERPRINT_ERROR = 2;
@@ -68,18 +71,17 @@ public class FingerprintDialogView extends LinearLayout {
    private final int mErrorColor;
    private final int mTextColor;
    private final int mFingerprintColor;
    private final float mDisplayWidth;
    private final DialogViewCallback mCallback;

    private ViewGroup mLayout;
    private final TextView mErrorText;
    private Handler mHandler;
    private Bundle mBundle;
    private final LinearLayout mDialog;
    private int mLastState;
    private boolean mAnimatingAway;
    private boolean mWasForceRemoved;

    private final float mDisplayWidth;

    private final Runnable mShowAnimationRunnable = new Runnable() {
        @Override
        public void run() {
@@ -98,9 +100,23 @@ public class FingerprintDialogView extends LinearLayout {
        }
    };

    public FingerprintDialogView(Context context, Handler handler) {
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch(msg.what) {
                case MSG_CLEAR_MESSAGE:
                    handleClearMessage();
                    break;
                default:
                    Log.e(TAG, "Unhandled message: " + msg.what);
                    break;
            }
        }
    };

    public FingerprintDialogView(Context context, DialogViewCallback callback) {
        super(context);
        mHandler = handler;
        mCallback = callback;
        mLinearOutSlowIn = Interpolators.LINEAR_OUT_SLOW_IN;
        mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        mAnimationTranslationOffset = getResources()
@@ -138,7 +154,7 @@ public class FingerprintDialogView extends LinearLayout {
                    downPressed = false;
                } else if (event.getAction() == KeyEvent.ACTION_UP && downPressed == true) {
                    downPressed = false;
                    mHandler.obtainMessage(FingerprintDialogImpl.MSG_USER_CANCELED).sendToTarget();
                    mCallback.onUserCanceled();
                }
                return true;
            }
@@ -155,11 +171,11 @@ public class FingerprintDialogView extends LinearLayout {
        setDismissesDialog(rightSpace);

        negative.setOnClickListener((View v) -> {
            mHandler.obtainMessage(FingerprintDialogImpl.MSG_BUTTON_NEGATIVE).sendToTarget();
            mCallback.onNegativePressed();
        });

        positive.setOnClickListener((View v) -> {
            mHandler.obtainMessage(FingerprintDialogImpl.MSG_BUTTON_POSITIVE).sendToTarget();
            mCallback.onPositivePressed();
        });

        mLayout.setFocusableInTouchMode(true);
@@ -230,8 +246,7 @@ public class FingerprintDialogView extends LinearLayout {
    private void setDismissesDialog(View v) {
        v.setClickable(true);
        v.setOnTouchListener((View view, MotionEvent event) -> {
            mHandler.obtainMessage(FingerprintDialogImpl.MSG_HIDE_DIALOG, true /* userCanceled */)
                    .sendToTarget();
            mCallback.onUserCanceled();
            return true;
        });
    }
@@ -289,7 +304,7 @@ public class FingerprintDialogView extends LinearLayout {
    }

    // Clears the temporary message and shows the help message.
    protected void resetMessage() {
    private void handleClearMessage() {
        updateFingerprintIcon(STATE_FINGERPRINT);
        mErrorText.setText(R.string.fingerprint_dialog_touch_sensor);
        mErrorText.setTextColor(mTextColor);
@@ -297,12 +312,12 @@ public class FingerprintDialogView extends LinearLayout {

    // Shows an error/help message
    private void showTemporaryMessage(String message) {
        mHandler.removeMessages(FingerprintDialogImpl.MSG_CLEAR_MESSAGE);
        mHandler.removeMessages(MSG_CLEAR_MESSAGE);
        updateFingerprintIcon(STATE_FINGERPRINT_ERROR);
        mErrorText.setText(message);
        mErrorText.setTextColor(mErrorColor);
        mErrorText.setContentDescription(message);
        mHandler.sendMessageDelayed(mHandler.obtainMessage(FingerprintDialogImpl.MSG_CLEAR_MESSAGE),
        mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CLEAR_MESSAGE),
                BiometricPrompt.HIDE_DIALOG_DELAY);
    }

@@ -312,8 +327,7 @@ public class FingerprintDialogView extends LinearLayout {

    public void showErrorMessage(String error) {
        showTemporaryMessage(error);
        mHandler.sendMessageDelayed(mHandler.obtainMessage(FingerprintDialogImpl.MSG_HIDE_DIALOG,
                false /* userCanceled */), BiometricPrompt.HIDE_DIALOG_DELAY);
        mCallback.onErrorShown();
    }

    private void updateFingerprintIcon(int newState) {