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

Commit 366cc537 authored by Ilya Matyukhin's avatar Ilya Matyukhin
Browse files

Add default implementation for biometrics.face@1.1

Bug: 145027036
Test: vts-tradefed run commandAndExit vts-hal -m VtsHalBiometricsFaceV1_0Target
Test: vts-tradefed run commandAndExit vts-hal -m VtsHalBiometricsFaceV1_1Target
Change-Id: I1aa682644b9b60705a1a8bf40867414b9fc99cd6
parent d711c108
Loading
Loading
Loading
Loading
+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",
    ],
}
+121 −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::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
+84 −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> 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
+11 −0
Original line number Diff line number Diff line
<manifest version="2.0" type="device">
    <hal format="hidl">
        <name>android.hardware.biometrics.face</name>
        <transport>hwbinder</transport>
        <version>1.1</version>
        <interface>
            <name>IBiometricsFace</name>
            <instance>default</instance>
        </interface>
    </hal>
</manifest>
Loading