1 /* 2 * Copyright (C) 2023 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 23 import androidx.annotation.NonNull; 24 import androidx.lifecycle.AndroidViewModel; 25 import androidx.lifecycle.LiveData; 26 import androidx.lifecycle.MutableLiveData; 27 28 import com.android.settings.biometrics2.data.repository.FingerprintRepository; 29 import com.android.settings.biometrics2.ui.model.EnrollmentRequest; 30 31 import java.lang.annotation.Retention; 32 import java.lang.annotation.RetentionPolicy; 33 34 /** 35 * Finish ViewModel handles the state of the fingerprint renroll final stage 36 */ 37 public class FingerprintEnrollFinishViewModel extends AndroidViewModel { 38 39 private static final String TAG = FingerprintEnrollFinishViewModel.class.getSimpleName(); 40 private static final boolean DEBUG = false; 41 42 /** 43 * User clicks "Add" button 44 */ 45 public static final int FINGERPRINT_ENROLL_FINISH_ACTION_ADD_BUTTON_CLICK = 0; 46 47 /** 48 * User clicks "Next" button 49 */ 50 public static final int FINGERPRINT_ENROLL_FINISH_ACTION_NEXT_BUTTON_CLICK = 1; 51 52 @IntDef(prefix = { "FINGERPRINT_ENROLL_FINISH_ACTION_" }, value = { 53 FINGERPRINT_ENROLL_FINISH_ACTION_ADD_BUTTON_CLICK, 54 FINGERPRINT_ENROLL_FINISH_ACTION_NEXT_BUTTON_CLICK 55 }) 56 @Retention(RetentionPolicy.SOURCE) 57 public @interface FingerprintEnrollFinishAction {} 58 59 @NonNull private final FingerprintRepository mFingerprintRepository; 60 @NonNull private final EnrollmentRequest mRequest; 61 private final int mUserId; 62 63 private final MutableLiveData<Integer> mActionLiveData = new MutableLiveData<>(); 64 FingerprintEnrollFinishViewModel(@onNull Application application, int userId, @NonNull EnrollmentRequest request, @NonNull FingerprintRepository fingerprintRepository)65 public FingerprintEnrollFinishViewModel(@NonNull Application application, int userId, 66 @NonNull EnrollmentRequest request, 67 @NonNull FingerprintRepository fingerprintRepository) { 68 super(application); 69 mUserId = userId; 70 mRequest = request; 71 mFingerprintRepository = fingerprintRepository; 72 } 73 74 @NonNull getRequest()75 public EnrollmentRequest getRequest() { 76 return mRequest; 77 } 78 79 /** 80 * The first sensor type is Side fps sensor or not 81 */ canAssumeSfps()82 public boolean canAssumeSfps() { 83 return mFingerprintRepository.canAssumeSfps(); 84 } 85 86 /** 87 * Device allows user to enroll another fingerprint or not. 88 */ isAnotherFingerprintEnrollable()89 public boolean isAnotherFingerprintEnrollable() { 90 return mFingerprintRepository.getNumOfEnrolledFingerprintsSize(mUserId) 91 < mFingerprintRepository.getMaxFingerprints(); 92 } 93 94 /** 95 * Clear action LiveData 96 */ clearActionLiveData()97 public void clearActionLiveData() { 98 mActionLiveData.setValue(null); 99 } 100 101 /** 102 * Get action LiveData 103 */ getActionLiveData()104 public LiveData<Integer> getActionLiveData() { 105 return mActionLiveData; 106 } 107 108 /** 109 * Handle add button Click 110 */ onAddButtonClick()111 public void onAddButtonClick() { 112 final int action = FINGERPRINT_ENROLL_FINISH_ACTION_ADD_BUTTON_CLICK; 113 if (DEBUG) { 114 Log.d(TAG, "onAddButtonClick post(" + action + ")"); 115 } 116 mActionLiveData.postValue(action); 117 } 118 119 /** 120 * Handle next button Click 121 */ onNextButtonClick()122 public void onNextButtonClick() { 123 final int action = FINGERPRINT_ENROLL_FINISH_ACTION_NEXT_BUTTON_CLICK; 124 if (DEBUG) { 125 Log.d(TAG, "onNextButtonClick post(" + action + ")"); 126 } 127 mActionLiveData.postValue(action); 128 } 129 } 130