1 /* 2 * Copyright (C) 2022 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.settings.biometrics2.ui.viewmodel; 18 19 import android.annotation.IntDef; 20 import android.app.Application; 21 import android.util.Log; 22 import android.view.accessibility.AccessibilityManager; 23 24 import androidx.annotation.NonNull; 25 import androidx.lifecycle.AndroidViewModel; 26 import androidx.lifecycle.LiveData; 27 import androidx.lifecycle.MutableLiveData; 28 29 import java.lang.annotation.Retention; 30 import java.lang.annotation.RetentionPolicy; 31 32 /** 33 * ViewModel explaining the fingerprint sensor location for fingerprint enrollment. 34 */ 35 public class FingerprintEnrollFindSensorViewModel extends AndroidViewModel { 36 37 private static final boolean DEBUG = false; 38 private static final String TAG = "FingerprintEnrollFindSensorViewModel"; 39 40 /** 41 * User clicks 'Skip' button on this page in Settings 42 */ 43 public static final int FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_SKIP = 0; 44 45 /** 46 * User clicks 'Skip' button on this page in SetupWizard flow 47 */ 48 public static final int FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_DIALOG = 1; 49 50 /** 51 * User clicks 'Start' button on this page 52 */ 53 public static final int FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_START = 2; 54 55 @IntDef(prefix = { "FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_" }, value = { 56 FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_SKIP, 57 FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_DIALOG, 58 FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_START 59 }) 60 @Retention(RetentionPolicy.SOURCE) 61 public @interface FingerprintEnrollFindSensorAction {} 62 63 private final AccessibilityManager mAccessibilityManager; 64 65 private final boolean mIsSuw; 66 @NonNull private final MutableLiveData<Integer> mActionLiveData = new MutableLiveData<>(); 67 FingerprintEnrollFindSensorViewModel(@onNull Application application, boolean isSuw)68 public FingerprintEnrollFindSensorViewModel(@NonNull Application application, boolean isSuw) { 69 super(application); 70 mAccessibilityManager = application.getSystemService(AccessibilityManager.class); 71 mIsSuw = isSuw; 72 } 73 74 /** 75 * Returns action live data that user chooses 76 */ getActionLiveData()77 public LiveData<Integer> getActionLiveData() { 78 return mActionLiveData; 79 } 80 81 /** 82 * Clear ActionLiveData to prevent get obsolete data 83 */ clearActionLiveData()84 public void clearActionLiveData() { 85 mActionLiveData.setValue(null); 86 } 87 88 /** 89 * User clicks skip button on dialog 90 */ onSkipDialogButtonClick()91 public void onSkipDialogButtonClick() { 92 final int action = FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_SKIP; 93 if (DEBUG) { 94 Log.d(TAG, "onSkipDialogButtonClick, post " + action); 95 } 96 mActionLiveData.postValue(action); 97 } 98 99 /** 100 * User clicks skip button 101 */ onSkipButtonClick()102 public void onSkipButtonClick() { 103 final int action = mIsSuw 104 ? FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_DIALOG 105 : FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_SKIP; 106 if (DEBUG) { 107 Log.d(TAG, "onSkipButtonClick, post action " + action); 108 } 109 mActionLiveData.postValue(action); 110 } 111 112 /** 113 * User clicks start button 114 */ onStartButtonClick()115 public void onStartButtonClick() { 116 final int action = FINGERPRINT_ENROLL_FIND_SENSOR_ACTION_START; 117 if (DEBUG) { 118 Log.d(TAG, "onStartButtonClick, post action " + action); 119 } 120 mActionLiveData.postValue(action); 121 } 122 123 /** 124 * Returns the info about accessibility is enabled or not 125 */ isAccessibilityEnabled()126 public boolean isAccessibilityEnabled() { 127 return mAccessibilityManager.isEnabled(); 128 } 129 } 130