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

Commit 24178e09 authored by Ilya Matyukhin's avatar Ilya Matyukhin Committed by Android (Google) Code Review
Browse files

Merge changes from topic "biometrics.face@1.1"

* changes:
  Add biometrics.face@1.1 to current.txt
  Add enroll_1_1 with preview window id
  Add default implementation for biometrics.face@1.1
parents e6b7a711 7b8a5c99
Loading
Loading
Loading
Loading
+37 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

package android.hardware.biometrics.face@1.1;

import @1.0::IBiometricsFace;
import @1.0::Status;
import @1.0::Feature;
@@ -77,6 +78,40 @@ interface IBiometricsFace extends @1.0::IBiometricsFace {
     *     enrollment. Note that all features are enabled by default.
     * @return status The status of this method call.
     */
    enrollRemotely(vec<uint8_t> hat, uint32_t timeoutSec,
        vec<Feature> disabledFeatures) generates (Status status);
    enrollRemotely(vec<uint8_t> hat, uint32_t timeoutSec, vec<Feature> disabledFeatures)
        generates (Status status);

    /**
     * Enrolls a user's face.
     *
     * Note that the Hardware Authentication Token must be valid for the
     * duration of enrollment and thus should be explicitly invalidated by a
     * call to revokeChallenge() when enrollment is complete, to reduce the
     * window of opportunity to re-use the challenge and HAT. For example,
     * Settings calls generateChallenge() once to allow the user to enroll one
     * or more faces or toggle secure settings without having to re-enter the
     * PIN/pattern/password. Once the user completes the operation, Settings
     * invokes revokeChallenge() to close the transaction. If the HAT is expired,
     * the implementation must invoke onError with UNABLE_TO_PROCESS.
     *
     * This method triggers the IBiometricsFaceClientCallback#onEnrollResult()
     * method.
     *
     * @param hat A valid Hardware Authentication Token, generated as a result
     *     of a generateChallenge() challenge being wrapped by the gatekeeper
     *     after a successful strong authentication request.
     * @param timeoutSec A timeout in seconds, after which this enroll
     *     attempt is cancelled. Note that the framework can continue
     *     enrollment by calling this again with a valid HAT. This timeout is
     *     expected to be used to limit power usage if the device becomes idle
     *     during enrollment. The implementation is expected to send
     *     ERROR_TIMEOUT if this happens.
     * @param disabledFeatures A list of features to be disabled during
     *     enrollment. Note that all features are enabled by default.
     * @param windowId optional ID of a camera preview window for a
     *     single-camera device. Must be null if not used.
     * @return status The status of this method call.
     */
    enroll_1_1(vec<uint8_t> hat, uint32_t timeoutSec, vec<Feature> disabledFeatures,
        handle windowId) generates (Status status);
};
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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.
 */

cc_binary {
    name: "android.hardware.biometrics.face@1.1-service.example",
    defaults: ["hidl_defaults"],
    vendor: true,
    init_rc: ["android.hardware.biometrics.face@1.1-service.rc"],
    vintf_fragments: ["manifest_face_default.xml"],
    relative_install_path: "hw",
    proprietary: true,
    srcs: [
        "BiometricsFace.cpp",
        "service.cpp",
    ],
    shared_libs: [
        "libhidlbase",
        "libutils",
        "liblog",
        "android.hardware.biometrics.face@1.0",
        "android.hardware.biometrics.face@1.1",
    ],
}
+129 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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.
 */

#include "BiometricsFace.h"

namespace android::hardware::biometrics::face::implementation {
using android::hardware::biometrics::face::V1_0::FaceError;
using android::hardware::biometrics::face::V1_0::OptionalUint64;

// Arbitrary value.
constexpr uint64_t kDeviceId = 123;
// Arbitrary value.
constexpr uint64_t kAuthenticatorId = 987;
// Arbitrary value.
constexpr uint64_t kLockoutDuration = 555;

BiometricsFace::BiometricsFace() : mRandom(std::mt19937::default_seed) {}

// Methods from IBiometricsFace follow.
Return<void> BiometricsFace::setCallback(const sp<IBiometricsFaceClientCallback>& clientCallback,
                                         setCallback_cb _hidl_cb) {
    mClientCallback = clientCallback;
    _hidl_cb({Status::OK, kDeviceId});
    return Void();
}

Return<Status> BiometricsFace::setActiveUser(int32_t userId, const hidl_string& storePath) {
    if (userId < 0 || storePath.empty() || std::string(storePath).find("/data") != 0) {
        return Status::ILLEGAL_ARGUMENT;
    }
    mUserId = userId;
    mClientCallback->onLockoutChanged(kLockoutDuration);
    return Status::OK;
}

Return<void> BiometricsFace::generateChallenge(uint32_t /* challengeTimeoutSec */,
                                               generateChallenge_cb _hidl_cb) {
    std::uniform_int_distribution<uint64_t> dist;
    _hidl_cb({Status::OK, dist(mRandom)});
    return Void();
}

Return<Status> BiometricsFace::enroll(const hidl_vec<uint8_t>& /* hat */, uint32_t /* timeoutSec */,
                                      const hidl_vec<Feature>& /* disabledFeatures */) {
    // hat can never be valid in this implementation.
    mClientCallback->onError(kDeviceId, mUserId, FaceError::UNABLE_TO_PROCESS, 0 /* vendorCode */);
    return Status::OK;
}

Return<Status> BiometricsFace::revokeChallenge() {
    return Status::OK;
}

Return<Status> BiometricsFace::setFeature(Feature /* feature */, bool /* enabled */,
                                          const hidl_vec<uint8_t>& /* hat */,
                                          uint32_t /* faceId */) {
    // hat can never be valid in this implementation.
    return Status::ILLEGAL_ARGUMENT;
}

Return<void> BiometricsFace::getFeature(Feature /* feature */, uint32_t /* faceId */,
                                        getFeature_cb _hidl_cb) {
    // hat can never be valid in this implementation.
    _hidl_cb({Status::ILLEGAL_ARGUMENT, false});
    return Void();
}

Return<void> BiometricsFace::getAuthenticatorId(getAuthenticatorId_cb _hidl_cb) {
    _hidl_cb({Status::OK, kAuthenticatorId});
    return Void();
}

Return<Status> BiometricsFace::cancel() {
    mClientCallback->onError(kDeviceId, mUserId, FaceError::CANCELED, 0 /* vendorCode */);
    return Status::OK;
}

Return<Status> BiometricsFace::enumerate() {
    mClientCallback->onEnumerate(kDeviceId, {}, mUserId);
    return Status::OK;
}

Return<Status> BiometricsFace::remove(uint32_t /* faceId */) {
    return Status::OK;
}

Return<Status> BiometricsFace::authenticate(uint64_t /* operationId */) {
    mClientCallback->onError(kDeviceId, mUserId, FaceError::HW_UNAVAILABLE, 0 /* vendorCode */);
    return Status::OK;
}

Return<Status> BiometricsFace::userActivity() {
    return Status::OK;
}

Return<Status> BiometricsFace::resetLockout(const hidl_vec<uint8_t>& /* hat */) {
    return Status::OK;
}

// Methods from ::android::hardware::biometrics::face::V1_1::IBiometricsFace follow.
Return<Status> BiometricsFace::enroll_1_1(const hidl_vec<uint8_t>& /* hat */,
                                          uint32_t /* timeoutSec */,
                                          const hidl_vec<Feature>& /* disabledFeatures */,
                                          const hidl_handle& /* windowId */) {
    mClientCallback->onError(kDeviceId, mUserId, FaceError::UNABLE_TO_PROCESS, 0 /* vendorCode */);
    return Status::OK;
}

Return<Status> BiometricsFace::enrollRemotely(const hidl_vec<uint8_t>& /* hat */,
                                              uint32_t /* timeoutSec */,
                                              const hidl_vec<Feature>& /* disabledFeatures */) {
    mClientCallback->onError(kDeviceId, mUserId, FaceError::UNABLE_TO_PROCESS, 0 /* vendorCode */);
    return Status::OK;
}

}  // namespace android::hardware::biometrics::face::implementation
+88 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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.
 */

#pragma once

#include <android/hardware/biometrics/face/1.1/IBiometricsFace.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
#include <random>

namespace android::hardware::biometrics::face::implementation {

using ::android::sp;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::biometrics::face::V1_0::Feature;
using ::android::hardware::biometrics::face::V1_0::IBiometricsFaceClientCallback;
using ::android::hardware::biometrics::face::V1_0::Status;

class BiometricsFace : public V1_1::IBiometricsFace {
  public:
    BiometricsFace();

    // Methods from ::android::hardware::biometrics::face::V1_0::IBiometricsFace follow.
    Return<void> setCallback(const sp<IBiometricsFaceClientCallback>& clientCallback,
                             setCallback_cb _hidl_cb) override;

    Return<Status> setActiveUser(int32_t userId, const hidl_string& storePath) override;

    Return<void> generateChallenge(uint32_t challengeTimeoutSec,
                                   generateChallenge_cb _hidl_cb) override;

    Return<Status> enroll(const hidl_vec<uint8_t>& hat, uint32_t timeoutSec,
                          const hidl_vec<Feature>& disabledFeatures) override;

    Return<Status> revokeChallenge() override;

    Return<Status> setFeature(Feature feature, bool enabled, const hidl_vec<uint8_t>& hat,
                              uint32_t faceId) override;

    Return<void> getFeature(Feature feature, uint32_t faceId, getFeature_cb _hidl_cb) override;

    Return<void> getAuthenticatorId(getAuthenticatorId_cb _hidl_cb) override;

    Return<Status> cancel() override;

    Return<Status> enumerate() override;

    Return<Status> remove(uint32_t faceId) override;

    Return<Status> authenticate(uint64_t operationId) override;

    Return<Status> userActivity() override;

    Return<Status> resetLockout(const hidl_vec<uint8_t>& hat) override;

    // Methods from ::android::hardware::biometrics::face::V1_1::IBiometricsFace follow.
    Return<Status> enroll_1_1(const hidl_vec<uint8_t>& hat, uint32_t timeoutSec,
                              const hidl_vec<Feature>& disabledFeatures,
                              const hidl_handle& windowId) override;

    Return<Status> enrollRemotely(const hidl_vec<uint8_t>& hat, uint32_t timeoutSec,
                                  const hidl_vec<Feature>& disabledFeatures) override;

  private:
    std::mt19937 mRandom;
    int32_t mUserId;
    sp<IBiometricsFaceClientCallback> mClientCallback;
};

}  // namespace android::hardware::biometrics::face::implementation
+10 −0
Original line number Diff line number Diff line
service vendor.face-hal-1-1-default /vendor/bin/hw/android.hardware.biometrics.face@1.1-service.example
    # "class hal" causes a race condition on some devices due to files created
    # in /data. As a workaround, postpone startup until later in boot once
    # /data is mounted.
    class late_start
    user system
    group system
    writepid /dev/cpuset/foreground/tasks
    capabilities SYS_NICE
    rlimit rtprio 10 10
Loading