sm8350-common: implement inscreen fingerprint hal

This commit is contained in:
Cosmin Tanislav 2021-09-10 02:17:51 +03:00
parent 5243692261
commit f7d1849c0c
6 changed files with 312 additions and 0 deletions

36
fod/Android.bp Normal file
View File

@ -0,0 +1,36 @@
//
// Copyright (C) 2019 The LineageOS 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 {
relative_install_path: "hw",
defaults: ["hidl_defaults"],
name: "vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sm8350",
init_rc: ["vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sm8350.rc"],
vintf_fragments: ["vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sm8350.xml"],
srcs: [
"service.cpp",
"FingerprintInscreen.cpp",
],
vendor: true,
shared_libs: [
"libbase",
"libhardware",
"libhidlbase",
"liblog",
"libutils",
"vendor.lineage.biometrics.fingerprint.inscreen@1.0",
"//hardware/xiaomi:vendor.xiaomi.hardware.fingerprintextension@1.0",
],
}

135
fod/FingerprintInscreen.cpp Normal file
View File

@ -0,0 +1,135 @@
/*
* Copyright (C) 2019 The LineageOS 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.
*/
#define LOG_TAG "FingerprintInscreenService"
#include "FingerprintInscreen.h"
#include <android-base/logging.h>
#include <fstream>
#include <cmath>
#define COMMAND_NIT 10
#define PARAM_NIT_FOD 1
#define PARAM_NIT_NONE 0
#define FOD_STATUS_PATH "/sys/devices/virtual/touch/tp_dev/fod_status"
#define FOD_STATUS_ON 1
#define FOD_STATUS_OFF 0
#define FOD_HBM_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_hbm"
#define FOD_HBM_ON 1
#define FOD_HBM_OFF 0
#define FOD_SENSOR_X 588
#define FOD_SENSOR_Y 2358
#define FOD_SENSOR_SIZE 264
namespace {
template <typename T>
static void set(const std::string& path, const T& value) {
std::ofstream file(path);
file << value;
}
} // anonymous namespace
namespace vendor {
namespace lineage {
namespace biometrics {
namespace fingerprint {
namespace inscreen {
namespace V1_0 {
namespace implementation {
FingerprintInscreen::FingerprintInscreen() {
xiaomiFingerprintService = IXiaomiFingerprint::getService();
}
Return<int32_t> FingerprintInscreen::getPositionX() {
return FOD_SENSOR_X;
}
Return<int32_t> FingerprintInscreen::getPositionY() {
return FOD_SENSOR_Y;
}
Return<int32_t> FingerprintInscreen::getSize() {
return FOD_SENSOR_SIZE;
}
Return<void> FingerprintInscreen::onStartEnroll() {
return Void();
}
Return<void> FingerprintInscreen::onFinishEnroll() {
return Void();
}
Return<void> FingerprintInscreen::onPress() {
set(FOD_HBM_PATH, FOD_HBM_ON);
return Void();
}
Return<void> FingerprintInscreen::onRelease() {
set(FOD_HBM_PATH, FOD_HBM_OFF);
return Void();
}
Return<void> FingerprintInscreen::onShowFODView() {
set(FOD_STATUS_PATH, FOD_STATUS_ON);
return Void();
}
Return<void> FingerprintInscreen::onHideFODView() {
set(FOD_STATUS_PATH, FOD_STATUS_OFF);
return Void();
}
Return<bool> FingerprintInscreen::handleAcquired(int32_t acquiredInfo, int32_t vendorCode) {
LOG(ERROR) << "acquiredInfo: " << acquiredInfo << ", vendorCode: " << vendorCode;
return false;
}
Return<bool> FingerprintInscreen::handleError(int32_t error, int32_t vendorCode) {
LOG(ERROR) << "error: " << error << ", vendorCode: " << vendorCode;
return false;
}
Return<void> FingerprintInscreen::setLongPressEnabled(bool) {
return Void();
}
Return<int32_t> FingerprintInscreen::getDimAmount(int32_t /* brightness */) {
return 0;
}
Return<bool> FingerprintInscreen::shouldBoostBrightness() {
return false;
}
Return<void> FingerprintInscreen::setCallback(const sp<IFingerprintInscreenCallback>& /* callback */) {
return Void();
}
} // namespace implementation
} // namespace V1_0
} // namespace inscreen
} // namespace fingerprint
} // namespace biometrics
} // namespace lineage
} // namespace vendor

67
fod/FingerprintInscreen.h Normal file
View File

@ -0,0 +1,67 @@
/*
* Copyright (C) 2019 The LineageOS 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.
*/
#ifndef VENDOR_LINEAGE_BIOMETRICS_FINGERPRINT_INSCREEN_V1_0_FINGERPRINTINSCREEN_H
#define VENDOR_LINEAGE_BIOMETRICS_FINGERPRINT_INSCREEN_V1_0_FINGERPRINTINSCREEN_H
#include <vendor/lineage/biometrics/fingerprint/inscreen/1.0/IFingerprintInscreen.h>
#include <vendor/xiaomi/hardware/fingerprintextension/1.0/IXiaomiFingerprint.h>
namespace vendor {
namespace lineage {
namespace biometrics {
namespace fingerprint {
namespace inscreen {
namespace V1_0 {
namespace implementation {
using ::android::sp;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::vendor::xiaomi::hardware::fingerprintextension::V1_0::IXiaomiFingerprint;
class FingerprintInscreen : public IFingerprintInscreen {
public:
FingerprintInscreen();
Return<int32_t> getPositionX() override;
Return<int32_t> getPositionY() override;
Return<int32_t> getSize() override;
Return<void> onStartEnroll() override;
Return<void> onFinishEnroll() override;
Return<void> onPress() override;
Return<void> onRelease() override;
Return<void> onShowFODView() override;
Return<void> onHideFODView() override;
Return<bool> handleAcquired(int32_t acquiredInfo, int32_t vendorCode) override;
Return<bool> handleError(int32_t error, int32_t vendorCode) override;
Return<void> setLongPressEnabled(bool enabled) override;
Return<int32_t> getDimAmount(int32_t brightness) override;
Return<bool> shouldBoostBrightness() override;
Return<void> setCallback(const sp<IFingerprintInscreenCallback>& callback) override;
private:
sp<IXiaomiFingerprint> xiaomiFingerprintService;
};
} // namespace implementation
} // namespace V1_0
} // namespace inscreen
} // namespace fingerprint
} // namespace biometrics
} // namespace lineage
} // namespace vendor
#endif // VENDOR_LINEAGE_BIOMETRICS_FINGERPRINT_INSCREEN_V1_0_FINGERPRINTINSCREEN_H

50
fod/service.cpp Normal file
View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2019 The LineageOS 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.
*/
#define LOG_TAG "lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sm8350"
#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include "FingerprintInscreen.h"
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using vendor::lineage::biometrics::fingerprint::inscreen::V1_0::IFingerprintInscreen;
using vendor::lineage::biometrics::fingerprint::inscreen::V1_0::implementation::FingerprintInscreen;
using android::OK;
using android::status_t;
int main() {
android::sp<IFingerprintInscreen> service = new FingerprintInscreen();
configureRpcThreadpool(1, true);
status_t status = service->registerAsService();
if (status != OK) {
LOG(ERROR) << "Cannot register FOD HAL service.";
return 1;
}
LOG(INFO) << "FOD HAL service ready.";
joinRpcThreadpool();
LOG(ERROR) << "FOD HAL service failed to join thread pool.";
return 1;
}

View File

@ -0,0 +1,13 @@
on boot
chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_hbm
chown system system /sys/devices/virtual/touch/tp_dev/fod_status
chmod 0200 /sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_hbm
chmod 0644 /sys/devices/virtual/touch/tp_dev/fod_status
service fingerprint-inscreen-1-0 /vendor/bin/hw/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.xiaomi_sm8350
interface vendor.lineage.biometrics.fingerprint.inscreen@1.0::IFingerprintInscreen default
class hal
user system
group system
shutdown critical

View File

@ -0,0 +1,11 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<name>vendor.lineage.biometrics.fingerprint.inscreen</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>IFingerprintInscreen</name>
<instance>default</instance>
</interface>
</hal>
</manifest>