1 /* 2 * Copyright (C) 2020 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 android.server.biometrics; 18 19 import static com.android.server.biometrics.nano.BiometricServiceStateProto.*; 20 21 import androidx.annotation.IntDef; 22 import androidx.annotation.NonNull; 23 24 import com.android.server.biometrics.nano.BiometricServiceStateProto; 25 import com.android.server.biometrics.nano.SensorServiceStateProto; 26 27 import java.lang.annotation.Retention; 28 import java.lang.annotation.RetentionPolicy; 29 import java.util.ArrayList; 30 import java.util.List; 31 32 public class BiometricServiceState { 33 34 /** 35 * Defined in biometrics.proto 36 */ 37 @IntDef({ 38 STATE_AUTH_IDLE, 39 STATE_AUTH_CALLED, 40 STATE_AUTH_STARTED, 41 STATE_AUTH_STARTED_UI_SHOWING, 42 STATE_AUTH_PAUSED, 43 STATE_AUTH_PAUSED_RESUMING, 44 STATE_AUTH_PENDING_CONFIRM, 45 STATE_AUTHENTICATED_PENDING_SYSUI, 46 STATE_ERROR_PENDING_SYSUI, 47 STATE_SHOWING_DEVICE_CREDENTIAL}) 48 @Retention(RetentionPolicy.SOURCE) 49 @interface AuthSessionState {} 50 51 @AuthSessionState public final int mState; 52 @NonNull public final SensorStates mSensorStates; 53 54 @NonNull parseFrom(@onNull BiometricServiceStateProto proto)55 public static BiometricServiceState parseFrom(@NonNull BiometricServiceStateProto proto) { 56 final List<SensorStates> sensorStates = new ArrayList<>(); 57 for (SensorServiceStateProto sensorServiceState : proto.sensorServiceStates) { 58 sensorStates.add(SensorStates.parseFrom(sensorServiceState)); 59 } 60 61 @AuthSessionState int state = proto.authSessionState; 62 63 return new BiometricServiceState(SensorStates.merge(sensorStates), state); 64 } 65 BiometricServiceState(@onNull SensorStates sensorStates, @AuthSessionState int state)66 private BiometricServiceState(@NonNull SensorStates sensorStates, @AuthSessionState int state) { 67 mSensorStates = sensorStates; 68 mState = state; 69 } 70 71 @Override toString()72 public String toString() { 73 final StringBuilder sb = new StringBuilder(); 74 sb.append("AuthSessionState: ").append(mState).append(". "); 75 sb.append(mSensorStates.toString()); 76 return sb.toString(); 77 } 78 } 79