From 031d6ba43a9d601ef6cc50c58f66343e219f20dd Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Tue, 18 Jun 2019 02:26:16 +0200 Subject: [PATCH] sdm845-common: Switch to common Trust HAL implementation * OnePlus's OTG switch sysfs doesn't act the same as 'deny_new_usb' node breaking OTG entirely in some situations. Change-Id: I4f67d5cec5ded72ee835bfed9d34407eba1612d1 --- common.mk | 2 +- sepolicy/private/file.te | 1 - sepolicy/private/file_contexts | 2 +- sepolicy/private/hal_trust_default.te | 5 ++ sepolicy/private/hal_trust_sdm845.te | 9 --- trust/.clang-format | 11 ---- trust/Android.bp | 33 ---------- trust/UsbRestrict.cpp | 55 ---------------- trust/UsbRestrict.h | 48 -------------- ...ineage.trust@1.0-service.oneplus_sdm845.rc | 4 -- trust/service.cpp | 64 ------------------- 11 files changed, 7 insertions(+), 227 deletions(-) create mode 100644 sepolicy/private/hal_trust_default.te delete mode 100644 sepolicy/private/hal_trust_sdm845.te delete mode 100644 trust/.clang-format delete mode 100644 trust/Android.bp delete mode 100644 trust/UsbRestrict.cpp delete mode 100644 trust/UsbRestrict.h delete mode 100644 trust/lineage.trust@1.0-service.oneplus_sdm845.rc delete mode 100644 trust/service.cpp diff --git a/common.mk b/common.mk index aa0cdeb..45babb1 100644 --- a/common.mk +++ b/common.mk @@ -134,7 +134,7 @@ PRODUCT_PACKAGES += \ # Trust HAL PRODUCT_PACKAGES += \ - lineage.trust@1.0-service.oneplus_sdm845 + lineage.trust@1.0-service # Update engine PRODUCT_PACKAGES += \ diff --git a/sepolicy/private/file.te b/sepolicy/private/file.te index ed2d90e..9295686 100644 --- a/sepolicy/private/file.te +++ b/sepolicy/private/file.te @@ -14,7 +14,6 @@ type sysfs_battery_supply, sysfs_type, fs_type; type sysfs_fpc_proximity, sysfs_type, fs_type; type sysfs_graphics, sysfs_type, fs_type; type sysfs_oem, sysfs_type, fs_type; -type sysfs_usb_supply, sysfs_type, fs_type; # data type display_misc_file, file_type, data_file_type, core_data_file_type; diff --git a/sepolicy/private/file_contexts b/sepolicy/private/file_contexts index f053fad..31f4fa9 100644 --- a/sepolicy/private/file_contexts +++ b/sepolicy/private/file_contexts @@ -19,7 +19,7 @@ /system/bin/hw/android\.hardware\.light@2\.0-service\.oneplus_sdm845 u:object_r:hal_light_sdm845_exec:s0 /system/bin/hw/lineage\.livedisplay@2\.0-service\.oneplus_sdm845 u:object_r:hal_livedisplay_sdm845_exec:s0 /system/bin/hw/lineage\.touch@1\.0-service\.oneplus_sdm845 u:object_r:hal_touch_sdm845_exec:s0 -/system/bin/hw/lineage\.trust@1\.0-service\.oneplus_sdm845 u:object_r:hal_trust_sdm845_exec:s0 +/system/bin/hw/lineage\.trust@1\.0-service u:object_r:hal_trust_default_exec:s0 # Modules /system/lib/modules/wlan\.ko u:object_r:vendor_file:s0 diff --git a/sepolicy/private/hal_trust_default.te b/sepolicy/private/hal_trust_default.te new file mode 100644 index 0000000..e5bcf90 --- /dev/null +++ b/sepolicy/private/hal_trust_default.te @@ -0,0 +1,5 @@ +type hal_trust_default, coredomain, domain; +hal_server_domain(hal_trust_default, hal_lineage_trust) + +type hal_trust_default_exec, exec_type, file_type; +init_daemon_domain(hal_trust_default) diff --git a/sepolicy/private/hal_trust_sdm845.te b/sepolicy/private/hal_trust_sdm845.te deleted file mode 100644 index 944abdb..0000000 --- a/sepolicy/private/hal_trust_sdm845.te +++ /dev/null @@ -1,9 +0,0 @@ -type hal_trust_sdm845, coredomain, domain; -hal_server_domain(hal_trust_sdm845, hal_lineage_trust) - -type hal_trust_sdm845_exec, exec_type, file_type; -init_daemon_domain(hal_trust_sdm845) - -# Allow access to otg toggle node -allow hal_trust_sdm845 sysfs_usb_supply:dir search; -allow hal_trust_sdm845 sysfs_usb_supply:file rw_file_perms; diff --git a/trust/.clang-format b/trust/.clang-format deleted file mode 100644 index ae4a451..0000000 --- a/trust/.clang-format +++ /dev/null @@ -1,11 +0,0 @@ -BasedOnStyle: Google -AccessModifierOffset: -2 -AllowShortFunctionsOnASingleLine: Inline -ColumnLimit: 100 -CommentPragmas: NOLINT:.* -DerivePointerAlignment: false -IndentWidth: 4 -PointerAlignment: Left -TabWidth: 4 -UseTab: Never -PenaltyExcessCharacter: 32 diff --git a/trust/Android.bp b/trust/Android.bp deleted file mode 100644 index dbbb473..0000000 --- a/trust/Android.bp +++ /dev/null @@ -1,33 +0,0 @@ -// -// 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 { - name: "lineage.trust@1.0-service.oneplus_sdm845", - init_rc: ["lineage.trust@1.0-service.oneplus_sdm845.rc"], - defaults: ["hidl_defaults"], - relative_install_path: "hw", - srcs: [ - "UsbRestrict.cpp", - "service.cpp", - ], - shared_libs: [ - "libbase", - "libbinder", - "libhidlbase", - "libhidltransport", - "libutils", - "vendor.lineage.trust@1.0", - ], -} diff --git a/trust/UsbRestrict.cpp b/trust/UsbRestrict.cpp deleted file mode 100644 index 80758cb..0000000 --- a/trust/UsbRestrict.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - */ -#include - -#include "UsbRestrict.h" - -#include - -namespace vendor { -namespace lineage { -namespace trust { -namespace V1_0 { -namespace implementation { - -static constexpr const char* kControlPath = "/sys/class/power_supply/usb/otg_switch"; - -// Methods from ::vendor::lineage::trust::V1_0::IUsbRestrict follow. -Return UsbRestrict::isEnabled() { - std::ifstream file(kControlPath); - std::string content; - file >> content; - file.close(); - return !file.fail() && !std::stoi(content); -} - -Return UsbRestrict::setEnabled(bool enabled) { - std::ofstream file(kControlPath); - if (file.is_open()) { - file << (!enabled ? "1" : "0"); - file.close(); - } else { - LOG(ERROR) << "Failed to open " << kControlPath << ", error=" << errno << " (" - << strerror(errno) << ")"; - } - return Void(); -} - -} // namespace implementation -} // namespace V1_0 -} // namespace trust -} // namespace lineage -} // namespace vendor diff --git a/trust/UsbRestrict.h b/trust/UsbRestrict.h deleted file mode 100644 index bcda59b..0000000 --- a/trust/UsbRestrict.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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_TRUST_V1_0_USBRESTRICT_H -#define VENDOR_LINEAGE_TRUST_V1_0_USBRESTRICT_H - -#include -#include -#include - -namespace vendor { -namespace lineage { -namespace trust { -namespace V1_0 { -namespace implementation { - -using ::android::sp; -using ::android::hardware::Return; -using ::android::hardware::Void; - -class UsbRestrict : public IUsbRestrict { - public: - UsbRestrict() = default; - - // Methods from ::vendor::lineage::trust::V1_0::IUsbRestrict follow. - Return isEnabled() override; - Return setEnabled(bool enabled) override; -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace trust -} // namespace lineage -} // namespace vendor - -#endif // VENDOR_LINEAGE_TRUST_V1_0_USBRESTRICT_H diff --git a/trust/lineage.trust@1.0-service.oneplus_sdm845.rc b/trust/lineage.trust@1.0-service.oneplus_sdm845.rc deleted file mode 100644 index 70966b0..0000000 --- a/trust/lineage.trust@1.0-service.oneplus_sdm845.rc +++ /dev/null @@ -1,4 +0,0 @@ -service trust-hal-1-0 /system/bin/hw/lineage.trust@1.0-service.oneplus_sdm845 - class hal - user root - group root diff --git a/trust/service.cpp b/trust/service.cpp deleted file mode 100644 index 29675e5..0000000 --- a/trust/service.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 "vendor.lineage.trust@1.0-service" - -#include -#include -#include - -#include "UsbRestrict.h" - -using android::OK; -using android::sp; -using android::status_t; - -// libhwbinder: -using android::hardware::configureRpcThreadpool; -using android::hardware::joinRpcThreadpool; - -using ::vendor::lineage::trust::V1_0::IUsbRestrict; -using ::vendor::lineage::trust::V1_0::implementation::UsbRestrict; - -int main() { - sp usbRestrict; - status_t status; - - LOG(INFO) << "Trust HAL service is starting."; - - usbRestrict = new UsbRestrict(); - if (usbRestrict == nullptr) { - LOG(ERROR) << "Can not create an instance of Trust HAL UsbRestricted Iface, exiting."; - goto shutdown; - } - - configureRpcThreadpool(1, true /*callerWillJoin*/); - - status = usbRestrict->registerAsService(); - if (status != OK) { - LOG(ERROR) << "Could not register service for Trust HAL UsbRestricted Iface (" << status - << ")."; - } - - LOG(INFO) << "Trust 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) << "Trust HAL service is shutting down."; - return 1; -}