diff --git a/hidl/fingerprint/Android.mk b/hidl/fingerprint/Android.mk index 4af8e8b9..dfe81d19 100644 --- a/hidl/fingerprint/Android.mk +++ b/hidl/fingerprint/Android.mk @@ -51,3 +51,5 @@ LOCAL_MODULE_OWNER := samsung LOCAL_VENDOR_MODULE := true include $(BUILD_EXECUTABLE) + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/hidl/fingerprint/inscreen/Android.mk b/hidl/fingerprint/inscreen/Android.mk new file mode 100644 index 00000000..e024fbcc --- /dev/null +++ b/hidl/fingerprint/inscreen/Android.mk @@ -0,0 +1,44 @@ +# +# Copyright (C) 2020 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. +# + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + FingerprintInscreen.cpp \ + service.cpp + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/include + +LOCAL_SHARED_LIBRARIES := \ + libbase \ + libhardware \ + libhidlbase \ + libhidltransport \ + liblog \ + libhwbinder \ + libutils \ + vendor.lineage.biometrics.fingerprint.inscreen@1.0 + +LOCAL_MODULE := vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung +LOCAL_INIT_RC := vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.rc +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_OWNER := samsung +LOCAL_VENDOR_MODULE := true + +include $(BUILD_EXECUTABLE) diff --git a/hidl/fingerprint/inscreen/FingerprintInscreen.cpp b/hidl/fingerprint/inscreen/FingerprintInscreen.cpp new file mode 100644 index 00000000..47211b16 --- /dev/null +++ b/hidl/fingerprint/inscreen/FingerprintInscreen.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2020 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 +#include + +#include + +namespace vendor { +namespace lineage { +namespace biometrics { +namespace fingerprint { +namespace inscreen { +namespace V1_0 { +namespace implementation { + +/* + * Write value to path and close file. + */ +template +static void set(const std::string& path, const T& value) { + std::ofstream file(path); + + if (!file) { + PLOG(ERROR) << "Failed to open: " << path; + return; + } + + LOG(DEBUG) << "write: " << path << " value: " << value; + + file << value << std::endl; + + if (!file) { + PLOG(ERROR) << "Failed to write: " << path << " value: " << value; + } +} + +template +static T get(const std::string& path, const T& def) { + std::ifstream file(path); + + if (!file) { + PLOG(ERROR) << "Failed to open: " << path; + return def; + } + + T result; + + file >> result; + + if (file.fail()) { + PLOG(ERROR) << "Failed to read: " << path; + return def; + } else { + LOG(DEBUG) << "read: " << path << " value: " << result; + return result; + } +} + +FingerprintInscreen::FingerprintInscreen() {} + +Return FingerprintInscreen::onStartEnroll() { return Void(); } + +Return FingerprintInscreen::onFinishEnroll() { return Void(); } + +Return FingerprintInscreen::onPress() { + set(TSP_CMD_PATH, FOD_ENABLE); + return Void(); +} + +Return FingerprintInscreen::onRelease() { + set(TSP_CMD_PATH, FOD_DISABLE); + return Void(); +} + +Return FingerprintInscreen::onShowFODView() { return Void(); } + +Return FingerprintInscreen::onHideFODView() { + set(TSP_CMD_PATH, FOD_DISABLE); + return Void(); +} + +Return FingerprintInscreen::handleAcquired(int32_t acquiredInfo, int32_t vendorCode) { + std::lock_guard _lock(mCallbackLock); + + if (mCallback == nullptr) { + return false; + } + + if (acquiredInfo == FINGERPRINT_ACQUIRED_VENDOR) { + if (vendorCode == VENDORCODE_FINGER_DOWN) { + Return ret = mCallback->onFingerDown(); + if (!ret.isOk()) { + LOG(ERROR) << "FingerDown() error: " << ret.description(); + } + return true; + } else if (vendorCode == VENDORCODE_FINGER_UP) { + Return ret = mCallback->onFingerUp(); + if (!ret.isOk()) { + LOG(ERROR) << "FingerUp() error: " << ret.description(); + } + return true; + } + } + + return false; +} + +Return FingerprintInscreen::handleError(int32_t, int32_t) { return false; } + +Return FingerprintInscreen::setLongPressEnabled(bool) { return Void(); } + +Return FingerprintInscreen::getDimAmount(int32_t cur_brightness) { + return cur_brightness / 2; +} + +Return FingerprintInscreen::shouldBoostBrightness() { return false; } + +Return FingerprintInscreen::setCallback(const sp& callback) { + mCallback = callback; + + return Void(); +} + +Return FingerprintInscreen::getPositionX() { return FOD_SENSOR_X; } + +Return FingerprintInscreen::getPositionY() { return FOD_SENSOR_Y; } + +Return FingerprintInscreen::getSize() { return FOD_SENSOR_SIZE; } + +} // namespace implementation +} // namespace V1_0 +} // namespace inscreen +} // namespace fingerprint +} // namespace biometrics +} // namespace lineage +} // namespace vendor diff --git a/hidl/fingerprint/inscreen/FingerprintInscreen.h b/hidl/fingerprint/inscreen/FingerprintInscreen.h new file mode 100644 index 00000000..be357034 --- /dev/null +++ b/hidl/fingerprint/inscreen/FingerprintInscreen.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2020 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 + +#include "samsung_fingerprint_inscreen.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; + +class FingerprintInscreen : public IFingerprintInscreen { + public: + FingerprintInscreen(); + + Return onStartEnroll() override; + Return onFinishEnroll() override; + Return onPress() override; + Return onRelease() override; + Return onShowFODView() override; + Return onHideFODView() override; + Return handleAcquired(int32_t acquiredInfo, int32_t vendorCode) override; + Return handleError(int32_t error, int32_t vendorCode) override; + Return setLongPressEnabled(bool enabled) override; + Return getDimAmount(int32_t cur_brightness) override; + Return shouldBoostBrightness() override; + Return setCallback(const sp& callback) override; + Return getPositionX() override; + Return getPositionY() override; + Return getSize() override; + + private: + std::mutex mCallbackLock; + sp mCallback; +}; + +} // 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 diff --git a/hidl/fingerprint/inscreen/include/samsung_fingerprint_inscreen.h b/hidl/fingerprint/inscreen/include/samsung_fingerprint_inscreen.h new file mode 100644 index 00000000..92ea3b41 --- /dev/null +++ b/hidl/fingerprint/inscreen/include/samsung_fingerprint_inscreen.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2020 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 SAMSUNG_FINGERPRINT_INSCREEN_H +#define SAMSUNG_FINGERPRINT_INSCREEN_H + +#define FOD_SENSOR_X 435 +#define FOD_SENSOR_Y 2025 +#define FOD_SENSOR_SIZE 210 + +#define FOD_ENABLE "fod_enable,1,1" +#define FOD_DISABLE "fod_enable,0" + +#define FINGERPRINT_ACQUIRED_VENDOR 6 +#define VENDORCODE_FINGER_DOWN 9002 +#define VENDORCODE_FINGER_UP 9001 + +#define TSP_CMD_PATH "/sys/class/sec/tsp/cmd" + +#endif // SAMSUNG_FINGERPRINT_INSCREEN_H diff --git a/hidl/fingerprint/inscreen/service.cpp b/hidl/fingerprint/inscreen/service.cpp new file mode 100644 index 00000000..1a678952 --- /dev/null +++ b/hidl/fingerprint/inscreen/service.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 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.samsung" + +#include +#include + +#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 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; +} diff --git a/hidl/fingerprint/inscreen/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.rc b/hidl/fingerprint/inscreen/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.rc new file mode 100644 index 00000000..6b453642 --- /dev/null +++ b/hidl/fingerprint/inscreen/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung.rc @@ -0,0 +1,6 @@ +service vendor.fingerprint-inscreen-1-0 /vendor/bin/hw/vendor.lineage.biometrics.fingerprint.inscreen@1.0-service.samsung + interface vendor.lineage.biometrics.fingerprint.inscreen@1.0::IFingerprintInscreen default + class hal + user system + group system + shutdown critical