Home | History | Annotate | Download | only in biometrics
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.systemui.biometrics;
     18 
     19 import android.content.Context;
     20 import android.graphics.drawable.AnimatedVectorDrawable;
     21 import android.graphics.drawable.Drawable;
     22 import android.util.Log;
     23 
     24 import com.android.systemui.R;
     25 
     26 /**
     27  * This class loads the view for the system-provided dialog. The view consists of:
     28  * Application Icon, Title, Subtitle, Description, Biometric Icon, Error/Help message area,
     29  * and positive/negative buttons.
     30  */
     31 public class FingerprintDialogView extends BiometricDialogView {
     32 
     33     private static final String TAG = "FingerprintDialogView";
     34 
     35     public FingerprintDialogView(Context context,
     36             DialogViewCallback callback) {
     37         super(context, callback);
     38     }
     39 
     40     @Override
     41     protected void handleResetMessage() {
     42         updateState(STATE_AUTHENTICATING);
     43         mErrorText.setText(getHintStringResourceId());
     44         mErrorText.setTextColor(mTextColor);
     45     }
     46 
     47     @Override
     48     protected int getHintStringResourceId() {
     49         return R.string.fingerprint_dialog_touch_sensor;
     50     }
     51 
     52     @Override
     53     protected int getAuthenticatedAccessibilityResourceId() {
     54         return com.android.internal.R.string.fingerprint_authenticated;
     55     }
     56 
     57     @Override
     58     protected int getIconDescriptionResourceId() {
     59         return R.string.accessibility_fingerprint_dialog_fingerprint_icon;
     60     }
     61 
     62     @Override
     63     protected void updateIcon(int lastState, int newState) {
     64         final Drawable icon = getAnimationForTransition(lastState, newState);
     65         if (icon == null) {
     66             Log.e(TAG, "Animation not found, " + lastState + " -> " + newState);
     67             return;
     68         }
     69 
     70         final AnimatedVectorDrawable animation = icon instanceof AnimatedVectorDrawable
     71                 ? (AnimatedVectorDrawable) icon
     72                 : null;
     73 
     74         mBiometricIcon.setImageDrawable(icon);
     75 
     76         if (animation != null && shouldAnimateForTransition(lastState, newState)) {
     77             animation.forceAnimationOnUI();
     78             animation.start();
     79         }
     80     }
     81 
     82     protected boolean shouldAnimateForTransition(int oldState, int newState) {
     83         if (newState == STATE_ERROR) {
     84             return true;
     85         } else if (oldState == STATE_ERROR && newState == STATE_AUTHENTICATING) {
     86             return true;
     87         } else if (oldState == STATE_AUTHENTICATING && newState == STATE_AUTHENTICATED) {
     88             // TODO(b/77328470): add animation when fingerprint is authenticated
     89             return false;
     90         } else if (oldState == STATE_ERROR && newState == STATE_AUTHENTICATED) {
     91             // TODO(b/77328470): add animation when fingerprint is authenticated
     92             return false;
     93         } else if (newState == STATE_AUTHENTICATING) {
     94             return false;
     95         }
     96         return false;
     97     }
     98 
     99     @Override
    100     protected int getDelayAfterAuthenticatedDurationMs() {
    101         return 0;
    102     }
    103 
    104     @Override
    105     protected boolean shouldGrayAreaDismissDialog() {
    106         // Fingerprint dialog always dismisses when region outside the dialog is tapped
    107         return true;
    108     }
    109 
    110     protected Drawable getAnimationForTransition(int oldState, int newState) {
    111         int iconRes;
    112         if (newState == STATE_ERROR) {
    113             iconRes = R.drawable.fingerprint_dialog_fp_to_error;
    114         } else if (oldState == STATE_ERROR && newState == STATE_AUTHENTICATING) {
    115             iconRes = R.drawable.fingerprint_dialog_error_to_fp;
    116         } else if (oldState == STATE_AUTHENTICATING && newState == STATE_AUTHENTICATED) {
    117             // TODO(b/77328470): add animation when fingerprint is authenticated
    118             iconRes = R.drawable.fingerprint_dialog_fp_to_error;
    119         } else if (oldState == STATE_ERROR && newState == STATE_AUTHENTICATED) {
    120             // TODO(b/77328470): add animation when fingerprint is authenticated
    121             iconRes = R.drawable.fingerprint_dialog_fp_to_error;
    122         } else if (newState == STATE_AUTHENTICATING) {
    123             iconRes = R.drawable.fingerprint_dialog_fp_to_error;
    124         } else {
    125             return null;
    126         }
    127         return mContext.getDrawable(iconRes);
    128     }
    129 }
    130