/*
 * Copyright (C) 2017 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.biometrics.fingerprint@2.1;

/* This HAL interface communicates asynchronous results from the
   fingerprint driver in response to user actions on the fingerprint sensor
*/
interface IBiometricsFingerprintClientCallback {
    /**
     * Sent when one enrollment step is complete.
     * @param deviceId the instance of this fingerprint device
     * @param fingerId the fingerprint templetate being enrolled
     * @param groupId the groupid for the template being enrolled
     * @param remaining the number of remaining steps before enrolllment is complete
     */
    oneway onEnrollResult(uint64_t deviceId, uint32_t fingerId, uint32_t groupId, uint32_t remaining);

    /**
     * Sent when a fingerprint image is acquired by the sensor
     * @param deviceId the instance of this fingerprint device
     * @param acquiredInfo a message about the quality of the acquired image
     * @param vendorCode a vendor-specific message about the quality of the image. Only
     *        valid when acquiredInfo == ACQUIRED_VENDOR
     */
    oneway onAcquired(uint64_t deviceId, FingerprintAcquiredInfo acquiredInfo, int32_t vendorCode);

    /**
     * Sent when a fingerprint is authenticated
     * @param deviceId the instance of this fingerprint device
     * @param fingerId the fingerprint templetate that was authenticated
     * @param groupId the groupid for the template that was authenticated
     * @param token the hardware authentication token to pass to Keystore.addAuthToken()
     */
    oneway onAuthenticated(uint64_t deviceId, uint32_t fingerId, uint32_t groupId, vec<uint8_t> token);

    /**
     * Sent when a fingerprint error occurs
     * @param deviceId the instance of this fingerprint device
     * @param error a message about the error that occurred
     * @param vendorCode a vendor-speicifc error message. Only valid
     *        when error == ERROR_VENDOR
     */
    oneway onError(uint64_t deviceId, FingerprintError error, int32_t vendorCode);

    /**
     * Sent when one template is removed
     * @param deviceId the instance of this fingerprint device
     * @param fingerId the fingerprint templetate being removed
     * @param groupId the groupid for the template being removed
     * @param remaining the number of remaining templates that will be removed.
     */
    oneway onRemoved(uint64_t deviceId, uint32_t fingerId, uint32_t groupId, uint32_t remaining);

    /**
     * Sent when one fingerprint template is enumerated
     * @param deviceId the instance of this fingerprint device
     * @param fingerId the fingerprint for this templetate
     * @param groupId the groupid for this template
     * @param remaining the number of remaining steps before enumeration is complete
     */
    oneway onEnumerate(uint64_t deviceId, uint32_t fingerId, uint32_t groupId, uint32_t remaining);
};
