Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9334d536 authored by Curtis Belmonte's avatar Curtis Belmonte Committed by Automerger Merge Worker
Browse files

Merge "Pass face AIDL frame data through to FaceManager" into sc-dev am: c2296965

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13500589

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Iab2223634b3499114c224ab2a4cfb9e5652b825d
parents 541e2f00 c2296965
Loading
Loading
Loading
Loading
+21 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.hardware.face;

/**
 * @hide
 */
parcelable FaceAuthenticationFrame;
+16 −0
Original line number Original line Diff line number Diff line
@@ -62,6 +62,22 @@ public final class FaceDataFrame implements Parcelable {
        mIsCancellable = isCancellable;
        mIsCancellable = isCancellable;
    }
    }


    /**
     * A container for data common to {@link FaceAuthenticationFrame} and {@link FaceEnrollFrame}.
     *
     * @param acquiredInfo An integer corresponding to a known acquired message.
     * @param vendorCode An integer representing a custom vendor-specific message. Ignored unless
     *  {@code acquiredInfo} is {@code FACE_ACQUIRED_VENDOR}.
     */
    public FaceDataFrame(int acquiredInfo, int vendorCode) {
        mAcquiredInfo = acquiredInfo;
        mVendorCode = vendorCode;
        mPan = 0f;
        mTilt = 0f;
        mDistance = 0f;
        mIsCancellable = false;
    }

    /**
    /**
     * @return An integer corresponding to a known acquired message.
     * @return An integer corresponding to a known acquired message.
     *
     *
+21 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.hardware.face;

/**
 * @hide
 */
parcelable FaceEnrollFrame;
+6 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import java.lang.annotation.RetentionPolicy;
 */
 */
@Retention(RetentionPolicy.SOURCE)
@Retention(RetentionPolicy.SOURCE)
@IntDef({
@IntDef({
    FaceEnrollStage.UNKNOWN,
    FaceEnrollStage.FIRST_FRAME_RECEIVED,
    FaceEnrollStage.FIRST_FRAME_RECEIVED,
    FaceEnrollStage.WAITING_FOR_CENTERING,
    FaceEnrollStage.WAITING_FOR_CENTERING,
    FaceEnrollStage.HOLD_STILL_IN_CENTER,
    FaceEnrollStage.HOLD_STILL_IN_CENTER,
@@ -36,6 +37,11 @@ import java.lang.annotation.RetentionPolicy;
    FaceEnrollStage.ENROLLMENT_FINISHED
    FaceEnrollStage.ENROLLMENT_FINISHED
})
})
public @interface FaceEnrollStage {
public @interface FaceEnrollStage {
    /**
     * The current enrollment stage is not known.
     */
    int UNKNOWN = -1;

    /**
    /**
     * Enrollment has just begun. No action is needed from the user yet.
     * Enrollment has just begun. No action is needed from the user yet.
     */
     */
+69 −14
Original line number Original line Diff line number Diff line
@@ -71,17 +71,19 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
    private static final int MSG_FACE_DETECTED = 109;
    private static final int MSG_FACE_DETECTED = 109;
    private static final int MSG_CHALLENGE_INTERRUPTED = 110;
    private static final int MSG_CHALLENGE_INTERRUPTED = 110;
    private static final int MSG_CHALLENGE_INTERRUPT_FINISHED = 111;
    private static final int MSG_CHALLENGE_INTERRUPT_FINISHED = 111;
    private static final int MSG_AUTHENTICATION_FRAME = 112;
    private static final int MSG_ENROLLMENT_FRAME = 113;


    private final IFaceService mService;
    private final IFaceService mService;
    private final Context mContext;
    private final Context mContext;
    private IBinder mToken = new Binder();
    private IBinder mToken = new Binder();
    private AuthenticationCallback mAuthenticationCallback;
    @Nullable private AuthenticationCallback mAuthenticationCallback;
    private FaceDetectionCallback mFaceDetectionCallback;
    @Nullable private FaceDetectionCallback mFaceDetectionCallback;
    private EnrollmentCallback mEnrollmentCallback;
    @Nullable private EnrollmentCallback mEnrollmentCallback;
    private RemovalCallback mRemovalCallback;
    @Nullable private RemovalCallback mRemovalCallback;
    private SetFeatureCallback mSetFeatureCallback;
    @Nullable private SetFeatureCallback mSetFeatureCallback;
    private GetFeatureCallback mGetFeatureCallback;
    @Nullable private GetFeatureCallback mGetFeatureCallback;
    private GenerateChallengeCallback mGenerateChallengeCallback;
    @Nullable private GenerateChallengeCallback mGenerateChallengeCallback;
    private CryptoObject mCryptoObject;
    private CryptoObject mCryptoObject;
    private Face mRemovalFace;
    private Face mRemovalFace;
    private Handler mHandler;
    private Handler mHandler;
@@ -154,6 +156,16 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
        public void onChallengeInterruptFinished(int sensorId) {
        public void onChallengeInterruptFinished(int sensorId) {
            mHandler.obtainMessage(MSG_CHALLENGE_INTERRUPT_FINISHED, sensorId).sendToTarget();
            mHandler.obtainMessage(MSG_CHALLENGE_INTERRUPT_FINISHED, sensorId).sendToTarget();
        }
        }

        @Override
        public void onAuthenticationFrame(FaceAuthenticationFrame frame) {
            mHandler.obtainMessage(MSG_AUTHENTICATION_FRAME, frame).sendToTarget();
        }

        @Override
        public void onEnrollmentFrame(FaceEnrollFrame frame) {
            mHandler.obtainMessage(MSG_ENROLLMENT_FRAME, frame).sendToTarget();
        }
    };
    };


    /**
    /**
@@ -1248,6 +1260,12 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan
                case MSG_CHALLENGE_INTERRUPT_FINISHED:
                case MSG_CHALLENGE_INTERRUPT_FINISHED:
                    sendChallengeInterruptFinished((int) msg.obj /* sensorId */);
                    sendChallengeInterruptFinished((int) msg.obj /* sensorId */);
                    break;
                    break;
                case MSG_AUTHENTICATION_FRAME:
                    sendAuthenticationFrame((FaceAuthenticationFrame) msg.obj /* frame */);
                    break;
                case MSG_ENROLLMENT_FRAME:
                    sendEnrollmentFrame((FaceEnrollFrame) msg.obj /* frame */);
                    break;
                default:
                default:
                    Slog.w(TAG, "Unknown message: " + msg.what);
                    Slog.w(TAG, "Unknown message: " + msg.what);
            }
            }
@@ -1349,15 +1367,52 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan


    private void sendAcquiredResult(int acquireInfo, int vendorCode) {
    private void sendAcquiredResult(int acquireInfo, int vendorCode) {
        if (mAuthenticationCallback != null) {
        if (mAuthenticationCallback != null) {
            final FaceAuthenticationFrame frame = new FaceAuthenticationFrame(
                    new FaceDataFrame(acquireInfo, vendorCode));
            sendAuthenticationFrame(frame);
        } else if (mEnrollmentCallback != null) {
            final FaceEnrollFrame frame = new FaceEnrollFrame(
                    null /* cell */,
                    FaceEnrollStage.UNKNOWN,
                    new FaceDataFrame(acquireInfo, vendorCode));
            sendEnrollmentFrame(frame);
        }
    }

    private void sendAuthenticationFrame(@Nullable FaceAuthenticationFrame frame) {
        if (frame == null) {
            Slog.w(TAG, "Received null authentication frame");
        } else if (mAuthenticationCallback != null) {
            // TODO(b/178414967): Send additional frame data to callback
            final int acquireInfo = frame.getData().getAcquiredInfo();
            final int vendorCode = frame.getData().getVendorCode();
            final int helpCode = getHelpCode(acquireInfo, vendorCode);
            final String helpMessage = getAcquiredString(mContext, acquireInfo, vendorCode);
            mAuthenticationCallback.onAuthenticationAcquired(acquireInfo);
            mAuthenticationCallback.onAuthenticationAcquired(acquireInfo);

            // Ensure that only non-null help messages are sent.
            if (helpMessage != null) {
                mAuthenticationCallback.onAuthenticationHelp(helpCode, helpMessage);
            }
        }
        }
        final String msg = getAcquiredString(mContext, acquireInfo, vendorCode);
        final int clientInfo = acquireInfo == FACE_ACQUIRED_VENDOR
                ? (vendorCode + FACE_ACQUIRED_VENDOR_BASE) : acquireInfo;
        if (mEnrollmentCallback != null) {
            mEnrollmentCallback.onEnrollmentHelp(clientInfo, msg);
        } else if (mAuthenticationCallback != null && msg != null) {
            mAuthenticationCallback.onAuthenticationHelp(clientInfo, msg);
    }
    }

    private void sendEnrollmentFrame(@Nullable FaceEnrollFrame frame) {
        if (frame == null) {
            Slog.w(TAG, "Received null enrollment frame");
        } else if (mEnrollmentCallback != null) {
            // TODO(b/178414967): Send additional frame data to callback
            final int acquireInfo = frame.getData().getAcquiredInfo();
            final int vendorCode = frame.getData().getVendorCode();
            final int helpCode = getHelpCode(acquireInfo, vendorCode);
            final String helpMessage = getAcquiredString(mContext, acquireInfo, vendorCode);
            mEnrollmentCallback.onEnrollmentHelp(helpCode, helpMessage);
        }
    }

    private static int getHelpCode(int acquireInfo, int vendorCode) {
        return acquireInfo == FACE_ACQUIRED_VENDOR
                ? vendorCode + FACE_ACQUIRED_VENDOR_BASE
                : acquireInfo;
    }
    }
}
}
Loading