1 /* 2 * Copyright (C) 2021 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.hardware.face; 18 19 import android.annotation.NonNull; 20 import android.hardware.biometrics.BiometricFaceConstants; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * A container for data common to {@link FaceAuthenticationFrame} and {@link FaceEnrollFrame}. 26 * 27 * @hide 28 */ 29 public final class FaceDataFrame implements Parcelable { 30 @BiometricFaceConstants.FaceAcquired private final int mAcquiredInfo; 31 private final int mVendorCode; 32 private final float mPan; 33 private final float mTilt; 34 private final float mDistance; 35 private final boolean mIsCancellable; 36 37 /** 38 * A container for data common to {@link FaceAuthenticationFrame} and {@link FaceEnrollFrame}. 39 * 40 * @param acquiredInfo An integer corresponding to a known acquired message. 41 * @param vendorCode An integer representing a custom vendor-specific message. Ignored unless 42 * {@code acquiredInfo} is {@code FACE_ACQUIRED_VENDOR}. 43 * @param pan The horizontal pan of the detected face. Values in the range [-1, 1] indicate a 44 * good capture. 45 * @param tilt The vertical tilt of the detected face. Values in the range [-1, 1] indicate a 46 * good capture. 47 * @param distance The distance of the detected face from the device. Values in the range 48 * [-1, 1] indicate a good capture. 49 * @param isCancellable Whether the ongoing face operation should be canceled. 50 */ FaceDataFrame( @iometricFaceConstants.FaceAcquired int acquiredInfo, int vendorCode, float pan, float tilt, float distance, boolean isCancellable)51 public FaceDataFrame( 52 @BiometricFaceConstants.FaceAcquired int acquiredInfo, 53 int vendorCode, 54 float pan, 55 float tilt, 56 float distance, 57 boolean isCancellable) { 58 mAcquiredInfo = acquiredInfo; 59 mVendorCode = vendorCode; 60 mPan = pan; 61 mTilt = tilt; 62 mDistance = distance; 63 mIsCancellable = isCancellable; 64 } 65 66 /** 67 * A container for data common to {@link FaceAuthenticationFrame} and {@link FaceEnrollFrame}. 68 * 69 * @param acquiredInfo An integer corresponding to a known acquired message. 70 * @param vendorCode An integer representing a custom vendor-specific message. Ignored unless 71 * {@code acquiredInfo} is {@code FACE_ACQUIRED_VENDOR}. 72 */ FaceDataFrame(@iometricFaceConstants.FaceAcquired int acquiredInfo, int vendorCode)73 public FaceDataFrame(@BiometricFaceConstants.FaceAcquired int acquiredInfo, int vendorCode) { 74 mAcquiredInfo = acquiredInfo; 75 mVendorCode = vendorCode; 76 mPan = 0f; 77 mTilt = 0f; 78 mDistance = 0f; 79 mIsCancellable = false; 80 } 81 82 /** 83 * @return An integer corresponding to a known acquired message. 84 * 85 * @see android.hardware.biometrics.BiometricFaceConstants 86 */ 87 @BiometricFaceConstants.FaceAcquired getAcquiredInfo()88 public int getAcquiredInfo() { 89 return mAcquiredInfo; 90 } 91 92 /** 93 * @return An integer representing a custom vendor-specific message. Ignored unless 94 * {@code acquiredInfo} is {@link 95 * android.hardware.biometrics.BiometricFaceConstants#FACE_ACQUIRED_VENDOR}. 96 * 97 * @see android.hardware.biometrics.BiometricFaceConstants 98 */ getVendorCode()99 public int getVendorCode() { 100 return mVendorCode; 101 } 102 103 /** 104 * @return The horizontal pan of the detected face. Values in the range [-1, 1] indicate a good 105 * capture. 106 */ getPan()107 public float getPan() { 108 return mPan; 109 } 110 111 /** 112 * @return The vertical tilt of the detected face. Values in the range [-1, 1] indicate a good 113 * capture. 114 */ getTilt()115 public float getTilt() { 116 return mTilt; 117 } 118 119 /** 120 * @return The distance of the detected face from the device. Values in the range [-1, 1] 121 * indicate a good capture. 122 */ getDistance()123 public float getDistance() { 124 return mDistance; 125 } 126 127 /** 128 * @return Whether the ongoing face operation should be canceled. 129 */ isCancellable()130 public boolean isCancellable() { 131 return mIsCancellable; 132 } 133 FaceDataFrame(@onNull Parcel source)134 private FaceDataFrame(@NonNull Parcel source) { 135 mAcquiredInfo = source.readInt(); 136 mVendorCode = source.readInt(); 137 mPan = source.readFloat(); 138 mTilt = source.readFloat(); 139 mDistance = source.readFloat(); 140 mIsCancellable = source.readBoolean(); 141 } 142 143 @Override describeContents()144 public int describeContents() { 145 return 0; 146 } 147 148 @Override writeToParcel(Parcel dest, int flags)149 public void writeToParcel(Parcel dest, int flags) { 150 dest.writeInt(mAcquiredInfo); 151 dest.writeInt(mVendorCode); 152 dest.writeFloat(mPan); 153 dest.writeFloat(mTilt); 154 dest.writeFloat(mDistance); 155 dest.writeBoolean(mIsCancellable); 156 } 157 158 public static final Creator<FaceDataFrame> CREATOR = new Creator<FaceDataFrame>() { 159 @Override 160 public FaceDataFrame createFromParcel(Parcel source) { 161 return new FaceDataFrame(source); 162 } 163 164 @Override 165 public FaceDataFrame[] newArray(int size) { 166 return new FaceDataFrame[size]; 167 } 168 }; 169 } 170