diff options
| author | dianlujitao <dianlujitao@lineageos.org> | 2021-01-25 16:20:39 +0800 |
|---|---|---|
| committer | Timi <timi.rautamaki@gmail.com> | 2021-01-29 15:33:56 +0100 |
| commit | 3bd15f29b42e10a73d866c06c9e45f82fe433952 (patch) | |
| tree | ce509892a6b81581f86d84cbeebd93a8a0f0b604 | |
| parent | a117bf93e4b9b7c348bd1740bd0e2e3561e88380 (diff) | |
cheeseburger: touch: Implement key swapper interface
Apply minor clean-ups while at it
Change-Id: I007624124997b46a0ed2961b938cd488efad45f2
| -rw-r--r-- | BoardConfig.mk | 2 | ||||
| -rw-r--r-- | touch/Android.bp | 4 | ||||
| -rw-r--r-- | touch/KeyDisabler.cpp | 24 | ||||
| -rw-r--r-- | touch/KeyDisabler.h | 9 | ||||
| -rw-r--r-- | touch/KeySwapper.cpp | 63 | ||||
| -rw-r--r-- | touch/KeySwapper.h | 44 | ||||
| -rw-r--r-- | touch/service.cpp | 33 | ||||
| -rw-r--r-- | touch/vendor.lineage.touch@1.0-service.cheeseburger.rc | 4 | ||||
| -rw-r--r-- | touch/vendor.lineage.touch@1.0-service.cheeseburger.xml (renamed from manifest.xml) | 10 |
9 files changed, 149 insertions, 44 deletions
diff --git a/BoardConfig.mk b/BoardConfig.mk index c4d75f7..5225e6e 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -38,5 +38,3 @@ BOARD_PLAT_PRIVATE_SEPOLICY_DIR += $(DEVICE_PATH)/sepolicy/private # inherit from the proprietary version -include vendor/oneplus/cheeseburger/BoardConfigVendor.mk - -DEVICE_MANIFEST_FILE += $(DEVICE_PATH)/manifest.xml diff --git a/touch/Android.bp b/touch/Android.bp index c421f32..6347618 100644 --- a/touch/Android.bp +++ b/touch/Android.bp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 The LineageOS Project +// Copyright (C) 2019,2021 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. @@ -16,10 +16,12 @@ cc_binary { name: "vendor.lineage.touch@1.0-service.cheeseburger", init_rc: ["vendor.lineage.touch@1.0-service.cheeseburger.rc"], defaults: ["hidl_defaults"], + vintf_fragments: ["vendor.lineage.touch@1.0-service.cheeseburger.xml"], relative_install_path: "hw", vendor: true, srcs: [ "KeyDisabler.cpp", + "KeySwapper.cpp", "service.cpp" ], shared_libs: [ diff --git a/touch/KeyDisabler.cpp b/touch/KeyDisabler.cpp index 110ad91..fbf1f48 100644 --- a/touch/KeyDisabler.cpp +++ b/touch/KeyDisabler.cpp @@ -20,27 +20,25 @@ #include "KeyDisabler.h" +namespace { +constexpr const char kControlPath[] = "/proc/touchpanel/key_disable"; +constexpr const char kFpcPath[] = + "/sys/module/fpc1020_tee/parameters/ignor_home_for_ESD"; +}; // anonymous namespace + namespace vendor { namespace lineage { namespace touch { namespace V1_0 { namespace implementation { -constexpr const char kControlPath[] = - "/proc/touchpanel/key_disable"; -constexpr const char kFpcPath[] = - "/sys/module/fpc1020_tee/parameters/ignor_home_for_ESD"; - -KeyDisabler::KeyDisabler() { - mHasKeyDisabler = !access(kControlPath, F_OK) && !access(kFpcPath, F_OK); -} +KeyDisabler::KeyDisabler() : has_key_disabler_(!access(kControlPath, R_OK | W_OK)) {} // Methods from ::vendor::lineage::touch::V1_0::IKeyDisabler follow. Return<bool> KeyDisabler::isEnabled() { - std::string buf; - - if (!mHasKeyDisabler) return false; + if (!has_key_disabler_) return false; + std::string buf; if (!android::base::ReadFileToString(kControlPath, &buf)) { LOG(ERROR) << "Failed to read " << kControlPath; return false; @@ -55,9 +53,9 @@ Return<bool> KeyDisabler::isEnabled() { } Return<bool> KeyDisabler::setEnabled(bool enabled) { - if (!mHasKeyDisabler) return false; + if (!has_key_disabler_) return false; - if (!android::base::WriteStringToFile((enabled ? "1" : "0"), kControlPath)) { + if (!android::base::WriteStringToFile(std::to_string(enabled), kControlPath)) { LOG(ERROR) << "Failed to write " << kControlPath; return false; } diff --git a/touch/KeyDisabler.h b/touch/KeyDisabler.h index d855c2a..f33327d 100644 --- a/touch/KeyDisabler.h +++ b/touch/KeyDisabler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The LineageOS Project + * Copyright (C) 2021 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. @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef VENDOR_LINEAGE_TOUCH_V1_0_KEYDISABLER_H -#define VENDOR_LINEAGE_TOUCH_V1_0_KEYDISABLER_H +#pragma once #include <vendor/lineage/touch/1.0/IKeyDisabler.h> @@ -37,7 +36,7 @@ class KeyDisabler : public IKeyDisabler { Return<bool> setEnabled(bool enabled) override; private: - bool mHasKeyDisabler; + const bool has_key_disabler_; }; } // namespace implementation @@ -45,5 +44,3 @@ class KeyDisabler : public IKeyDisabler { } // namespace touch } // namespace lineage } // namespace vendor - -#endif // VENDOR_LINEAGE_TOUCH_V1_0_KEYDISABLER_H diff --git a/touch/KeySwapper.cpp b/touch/KeySwapper.cpp new file mode 100644 index 0000000..cc95140 --- /dev/null +++ b/touch/KeySwapper.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2019,2021 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. + */ + +#include <android-base/file.h> +#include <android-base/logging.h> +#include <android-base/strings.h> + +#include "KeySwapper.h" + +namespace { +constexpr const char kControlPath[] = "/proc/s1302/key_rep"; +}; // anonymous namespace + +namespace vendor { +namespace lineage { +namespace touch { +namespace V1_0 { +namespace implementation { + +KeySwapper::KeySwapper() : has_key_swapper_(!access(kControlPath, R_OK | W_OK)) {} + +// Methods from ::vendor::lineage::touch::V1_0::IKeySwapper follow. +Return<bool> KeySwapper::isEnabled() { + if (!has_key_swapper_) return false; + + std::string buf; + if (!android::base::ReadFileToString(kControlPath, &buf)) { + LOG(ERROR) << "Failed to read " << kControlPath; + return false; + } + + return std::stoi(android::base::Trim(buf)) == 1; +} + +Return<bool> KeySwapper::setEnabled(bool enabled) { + if (!has_key_swapper_) return false; + + if (!android::base::WriteStringToFile(std::to_string(enabled), kControlPath)) { + LOG(ERROR) << "Failed to write " << kControlPath; + return false; + } + + return true; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace touch +} // namespace lineage +} // namespace vendor diff --git a/touch/KeySwapper.h b/touch/KeySwapper.h new file mode 100644 index 0000000..e6fb451 --- /dev/null +++ b/touch/KeySwapper.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019,2021 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. + */ + +#pragma once + +#include <vendor/lineage/touch/1.0/IKeySwapper.h> + +namespace vendor { +namespace lineage { +namespace touch { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::Return; + +class KeySwapper : public IKeySwapper { + public: + KeySwapper(); + // Methods from ::vendor::lineage::touch::V1_0::IKeySwapper follow. + Return<bool> isEnabled() override; + Return<bool> setEnabled(bool enabled) override; + + private: + const bool has_key_swapper_; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace touch +} // namespace lineage +} // namespace vendor diff --git a/touch/service.cpp b/touch/service.cpp index a3b17c1..18fb00d 100644 --- a/touch/service.cpp +++ b/touch/service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The LineageOS Project + * Copyright (C) 2019,2021 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. @@ -20,43 +20,38 @@ #include <hidl/HidlTransportSupport.h> #include "KeyDisabler.h" +#include "KeySwapper.h" using android::OK; using android::sp; -using android::status_t; using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; using ::vendor::lineage::touch::V1_0::IKeyDisabler; +using ::vendor::lineage::touch::V1_0::IKeySwapper; using ::vendor::lineage::touch::V1_0::implementation::KeyDisabler; +using ::vendor::lineage::touch::V1_0::implementation::KeySwapper; int main() { - sp<KeyDisabler> keyDisabler; - status_t status; + sp<IKeyDisabler> key_disabler = new KeyDisabler(); + sp<IKeySwapper> key_swapper = new KeySwapper(); - LOG(INFO) << "Touch HAL service is starting."; + configureRpcThreadpool(1, true /*callerWillJoin*/); - keyDisabler = new KeyDisabler(); - if (keyDisabler == nullptr) { - LOG(ERROR) << "Can not create an instance of Touch HAL KeyDisabler Iface, exiting."; - goto shutdown; + if (key_disabler->registerAsService() != OK) { + LOG(ERROR) << "Cannot register keydisabler HAL service."; + return 1; } - configureRpcThreadpool(1, true /*callerWillJoin*/); - - status = keyDisabler->registerAsService(); - if (status != OK) { - LOG(ERROR) << "Could not register service for Touch HAL KeyDisabler Iface (" - << status << ")"; - goto shutdown; + if (key_swapper->registerAsService() != OK) { + LOG(ERROR) << "Cannot register keyswapper HAL service."; + return 1; } LOG(INFO) << "Touch HAL service is ready."; joinRpcThreadpool(); // Should not pass this line -shutdown: - // In normal operation, we don't expect the thread pool to shutdown - LOG(ERROR) << "Touch HAL service is shutting down."; + LOG(ERROR) << "Touchscreen HAL service failed to join thread pool."; return 1; } diff --git a/touch/vendor.lineage.touch@1.0-service.cheeseburger.rc b/touch/vendor.lineage.touch@1.0-service.cheeseburger.rc index 16cbd4f..e387fca 100644 --- a/touch/vendor.lineage.touch@1.0-service.cheeseburger.rc +++ b/touch/vendor.lineage.touch@1.0-service.cheeseburger.rc @@ -1,3 +1,7 @@ +on boot + chown system system /proc/s1302/key_rep + chmod 0660 /proc/s1302/key_rep + service vendor.touch-hal-1-0-cheeseburger /vendor/bin/hw/vendor.lineage.touch@1.0-service.cheeseburger class hal user system diff --git a/manifest.xml b/touch/vendor.lineage.touch@1.0-service.cheeseburger.xml index 211b923..d0815dc 100644 --- a/manifest.xml +++ b/touch/vendor.lineage.touch@1.0-service.cheeseburger.xml @@ -1,14 +1,18 @@ -<manifest version="1.0" type="device" target-level="3"> +<manifest version="1.0" type="device"> <hal format="hidl"> <name>vendor.lineage.touch</name> <transport>hwbinder</transport> <version>1.0</version> <interface> - <name>ITouchscreenGesture</name> + <name>IKeyDisabler</name> <instance>default</instance> </interface> <interface> - <name>IKeyDisabler</name> + <name>IKeySwapper</name> + <instance>default</instance> + </interface> + <interface> + <name>ITouchscreenGesture</name> <instance>default</instance> </interface> </hal> |
