From 1bcf57f719c59af0eb10432d1753acc8f8b7ffb6 Mon Sep 17 00:00:00 2001 From: roynatech2544 Date: Sun, 24 Oct 2021 22:58:50 +0900 Subject: [PATCH] universal7885: SamsungParts: Add new HIDL * Related to flashlight * Also, build it --- ...dor.eureka.hardware.battery@1.0-service.rc | 4 +- .../hardware/flashlight/1.0/Android.bp | 10 ++ .../hardware/flashlight/1.0/IFlashlight.hal | 21 ++++ .../flashlight/1.0/default/Android.bp | 19 +++ .../flashlight/1.0/default/Flashlight.cpp | 110 ++++++++++++++++++ .../flashlight/1.0/default/Flashlight.h | 40 +++++++ .../flashlight/1.0/default/service.cpp | 49 ++++++++ ....eureka.hardware.flashlight@1.0-service.rc | 5 + .../vendor.eureka.hardware.flashlight@1.0.xml | 11 ++ .../hardware/flashlight/1.0/types.hal | 38 ++++++ .../sepolicy/vendor/file_contexts | 1 + .../sepolicy/vendor/hal_flashlight_default.te | 4 + .../sepolicy/vendor/hwservice.te | 1 + .../sepolicy/vendor/hwservice_contexts | 1 + universal7885-common/universal7885-common.mk | 6 +- 15 files changed, 316 insertions(+), 4 deletions(-) create mode 100644 universal7885-common/interfaces/hardware/flashlight/1.0/Android.bp create mode 100644 universal7885-common/interfaces/hardware/flashlight/1.0/IFlashlight.hal create mode 100644 universal7885-common/interfaces/hardware/flashlight/1.0/default/Android.bp create mode 100644 universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.cpp create mode 100644 universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.h create mode 100644 universal7885-common/interfaces/hardware/flashlight/1.0/default/service.cpp create mode 100644 universal7885-common/interfaces/hardware/flashlight/1.0/default/vendor.eureka.hardware.flashlight@1.0-service.rc create mode 100644 universal7885-common/interfaces/hardware/flashlight/1.0/default/vendor.eureka.hardware.flashlight@1.0.xml create mode 100644 universal7885-common/interfaces/hardware/flashlight/1.0/types.hal create mode 100644 universal7885-common/sepolicy/vendor/hal_flashlight_default.te diff --git a/universal7885-common/interfaces/hardware/battery/1.0/default/vendor.eureka.hardware.battery@1.0-service.rc b/universal7885-common/interfaces/hardware/battery/1.0/default/vendor.eureka.hardware.battery@1.0-service.rc index 728b77d..721e17f 100644 --- a/universal7885-common/interfaces/hardware/battery/1.0/default/vendor.eureka.hardware.battery@1.0-service.rc +++ b/universal7885-common/interfaces/hardware/battery/1.0/default/vendor.eureka.hardware.battery@1.0-service.rc @@ -1,5 +1,5 @@ service vendor.battery-hal /vendor/bin/hw/vendor.eureka.hardware.battery@1.0-service interface vendor.eureka.hardware.battery@1.0::IBattery default class hal - user system - group system + user root + group root diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/Android.bp b/universal7885-common/interfaces/hardware/flashlight/1.0/Android.bp new file mode 100644 index 0000000..d7d6cf0 --- /dev/null +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/Android.bp @@ -0,0 +1,10 @@ +hidl_interface { + name: "vendor.eureka.hardware.flashlight@1.0", + root: "vendor.eureka", + srcs: [ + "types.hal", + "IFlashlight.hal", + ], + interfaces: [ "android.hidl.base@1.0" ], + gen_java: true, +} diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/IFlashlight.hal b/universal7885-common/interfaces/hardware/flashlight/1.0/IFlashlight.hal new file mode 100644 index 0000000..313c059 --- /dev/null +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/IFlashlight.hal @@ -0,0 +1,21 @@ +// Copyright (C) 2021 Eureka Team +// +// 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. + +package vendor.eureka.hardware.flashlight@1.0; + +interface IFlashLight { + setFlashlightWritable(Number value) generates (int32_t result); + setFlashlightEnable(Enable enable) generates (int32_t result); + readFlashlightstats(Device device) generates (int32_t value); +}; diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/default/Android.bp b/universal7885-common/interfaces/hardware/flashlight/1.0/default/Android.bp new file mode 100644 index 0000000..6596a3d --- /dev/null +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/default/Android.bp @@ -0,0 +1,19 @@ +// FIXME: your file license if you have one + +cc_binary { + name: "vendor.eureka.hardware.flashlight@1.0-service", + relative_install_path: "hw", + proprietary: true, + srcs: [ + "Flashlight.cpp", + "service.cpp", + ], + shared_libs: [ + "libhidlbase", + "libutils", + "liblog", + "vendor.eureka.hardware.flashlight@1.0", + ], + init_rc: [ "vendor.eureka.hardware.flashlight@1.0-service.rc" ], + vintf_fragments: [ "vendor.eureka.hardware.flashlight@1.0.xml" ], +} diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.cpp b/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.cpp new file mode 100644 index 0000000..083fee2 --- /dev/null +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.cpp @@ -0,0 +1,110 @@ +// Copyright (C) 2021 Eureka Team +// +// 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 "Flashlight.h" +#include +#include +#include +namespace vendor::eureka::hardware::flashlight::V1_0 { + +// Methods from ::android::hardware::flashlight::V1_0::IFlashlight follow. +Return Flashlight::getFlashlightStats(flashlight::V1_0::Enable enable) { + std::ofstream file; + std::string writevalue; + switch (enable){ + case Number::ENABLE: + writevalue = "1"; + break; + case Number::DISABLE: + writevalue = "0"; + break; + default: + filename = ""; + break; + } + file.open("/sys/class/camera/flash/torch_brightness_lvl_enable"); + file << writevalue; + file.close(); + return 0; +} + +Return Flashlight::setFlashlightWritable(flashlight::V1_0::Number value) { + std::ofstream file; + std::string writevalue; + switch (value){ + case Number::ONEUI: + writevalue = "1"; + break; + case Number::TWOUI: + writevalue = "2"; + break; + case Number::THREEUI: + writevalue = "3"; + break; + case Number::FOURUI: + writevalue = "4"; + break; + case Number::FIVEUI: + writevalue = "5"; + break; + case Number::SIXUI: + writevalue = "6"; + break; + case Number::SEVENUI: + writevalue = "7"; + break; + case Number::EIGHTUI: + writevalue = "8"; + break; + case Number::NINEUI: + writevalue = "9"; + break; + case Number::TENUI: + writevalue = "10"; + break; + default: + filename = ""; + break; + } + file.open("/sys/class/camera/flash/torch_brightness_lvl"); + file << writevalue; + file.close(); + return 0; +} + +Return Flashlight::readFlashlightstats(flashlight::V1_0::Device device) { + std::ifstream file; + std::string value; + int32_t intvalue; + file.open("/sys/class/camera/flash/torch_brightness_lvl"); + if (file.is_open()) { + getline(file, value); + file.close(); + std::stringstream val(value); + val >> intvalue; + if (device == Device::A10){ + return intvalue; + }else if (device == Device::NOTA10){ + return intvalue / 21; + } + // Never Here + return -1; + } + return -1; +} + +IFlashlight *Flashlight::getInstance(void){ + return new Flashlight(); +} +} // namespace android::hardware::flashlight::implementation diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.h b/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.h new file mode 100644 index 0000000..c8c4033 --- /dev/null +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/default/Flashlight.h @@ -0,0 +1,40 @@ +// Copyright (C) 2021 Eureka Team +// +// 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 +#include +#include + +namespace vendor::eureka::hardware::flashlight::V1_0 { + +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::sp; + +struct Flashlight : public IFlashlight { + // Methods from ::vendor::eureka::hardware::flashlight::V1_0::IFlashlight follow. + Return Flashlight::getFlashlightStats(flashlight::V1_0::Enable enable); + Return Flashlight::setFlashlightWritable(flashlight::V1_0::Number value); + Return Flashlight::readFlashlightstats(flashlight::V1_0::Device device); + // Methods from ::android::hidl::base::V1_0::IBase follow. + static IFlashlight* getInstance(void); + +}; +} // namespace android::hardware::flashlight::implementation diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/default/service.cpp b/universal7885-common/interfaces/hardware/flashlight/1.0/default/service.cpp new file mode 100644 index 0000000..2a748e5 --- /dev/null +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/default/service.cpp @@ -0,0 +1,49 @@ +// Copyright (C) 2021 Eureka Team +// +// 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.eureka.hardware.flashlight@1.0-service" + +#include + +#include + +#include "Flashlight.h" + +using vendor::eureka::hardware::flashlight::V1_0::IFlashlight; +using vendor::eureka::hardware::flashlight::V1_0::Flashlight; +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::sp; + +int main() { + int ret; + android::sp service = Flashlight::getInstance(); + configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (service != nullptr) { + ret = service->registerAsService(); + if(ret != 0) { + ALOGE("Can't register instance of Flashlight HAL, nullptr"); + }else{ + ALOGI("registered Flashlight HAL"); + } + } else { + ALOGE("Can't create instance of Flashlight HAL, nullptr"); + } + + joinRpcThreadpool(); + + return -1; // should never get here +} diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/default/vendor.eureka.hardware.flashlight@1.0-service.rc b/universal7885-common/interfaces/hardware/flashlight/1.0/default/vendor.eureka.hardware.flashlight@1.0-service.rc new file mode 100644 index 0000000..610da86 --- /dev/null +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/default/vendor.eureka.hardware.flashlight@1.0-service.rc @@ -0,0 +1,5 @@ +service vendor.flashlight-hal /vendor/bin/hw/vendor.eureka.hardware.flashlight@1.0-service + interface vendor.eureka.hardware.flashlight@1.0::IFlashlight default + class hal + user root + group root diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/default/vendor.eureka.hardware.flashlight@1.0.xml b/universal7885-common/interfaces/hardware/flashlight/1.0/default/vendor.eureka.hardware.flashlight@1.0.xml new file mode 100644 index 0000000..a7b7d1a --- /dev/null +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/default/vendor.eureka.hardware.flashlight@1.0.xml @@ -0,0 +1,11 @@ + + + vendor.eureka.hardware.flashlight + hwbinder + 1.0 + + IFlashlight + default + + + diff --git a/universal7885-common/interfaces/hardware/flashlight/1.0/types.hal b/universal7885-common/interfaces/hardware/flashlight/1.0/types.hal new file mode 100644 index 0000000..ae51633 --- /dev/null +++ b/universal7885-common/interfaces/hardware/flashlight/1.0/types.hal @@ -0,0 +1,38 @@ +// Copyright (C) 2021 Eureka Team +// +// 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. + +package vendor.eureka.hardware.flashlight@1.0; + +enum Device : int32_t { + A10, + NOTA10, +}; + +enum Number : int32_t { + ONEUI, + TWOUI, + THREEUI, + FOURUI, + FIVEUI, + SIXUI, + SEVENUI, + EIGHTUI, + NINEUI, + TENUI, +}; + +enum Enable : int32_t { + ENABLE, + DISABLE, +} diff --git a/universal7885-common/sepolicy/vendor/file_contexts b/universal7885-common/sepolicy/vendor/file_contexts index de929ca..7c6f72a 100644 --- a/universal7885-common/sepolicy/vendor/file_contexts +++ b/universal7885-common/sepolicy/vendor/file_contexts @@ -215,3 +215,4 @@ # SamsungParts /(vendor|system/vendor)/bin/hw/vendor\.eureka\.hardware\.battery@1\.0-service u:object_r:hal_battery_default_exec:s0 +/(vendor|system/vendor)/bin/hw/vendor\.eureka\.hardware\.flashlight@1\.0-service u:object_r:hal_flashlight_default_exec:s0 diff --git a/universal7885-common/sepolicy/vendor/hal_flashlight_default.te b/universal7885-common/sepolicy/vendor/hal_flashlight_default.te new file mode 100644 index 0000000..3830ecc --- /dev/null +++ b/universal7885-common/sepolicy/vendor/hal_flashlight_default.te @@ -0,0 +1,4 @@ +type hal_flashlight_default, domain; +type hal_flashlight_default_exec, exec_type, file_type, vendor_file_type; +add_hwservice(hal_flashlight_default, hal_flashlight_hwservice); +init_daemon_domain(hal_flashlight_default); diff --git a/universal7885-common/sepolicy/vendor/hwservice.te b/universal7885-common/sepolicy/vendor/hwservice.te index a7b1329..00e9f7c 100644 --- a/universal7885-common/sepolicy/vendor/hwservice.te +++ b/universal7885-common/sepolicy/vendor/hwservice.te @@ -1,2 +1,3 @@ type rild_hwservice, hwservice_manager_type; type hal_battery_hwservice, hwservice_manager_type; +type hal_flashlight_hwservice, hwservice_manager_type; diff --git a/universal7885-common/sepolicy/vendor/hwservice_contexts b/universal7885-common/sepolicy/vendor/hwservice_contexts index 09099bc..5f5a0eb 100644 --- a/universal7885-common/sepolicy/vendor/hwservice_contexts +++ b/universal7885-common/sepolicy/vendor/hwservice_contexts @@ -6,4 +6,5 @@ vendor.lineage.power::ILineagePower u:object_r:hal_power_hwservice:s0 # SamsungParts vendor.eureka.hardware.battery::IBattery u:object_r:hal_battery_hwservice:s0 +vendor.eureka.hardware.flashlight::IFlashlight u:object_r:hal_flashlight_hwservice:s0 diff --git a/universal7885-common/universal7885-common.mk b/universal7885-common/universal7885-common.mk index bc62b33..4350dab 100644 --- a/universal7885-common/universal7885-common.mk +++ b/universal7885-common/universal7885-common.mk @@ -278,8 +278,10 @@ PRODUCT_CFI_INCLUDE_PATHS += hardware/samsung_slsi/scsc_wifibt/wpa_supplicant_li # SamsungParts PRODUCT_PACKAGES += \ - SamsungParts \ - android.software.samsungparts@1.0-service + SamsungParts \ + init.samsungparts.rc \ + vendor.eureka.hardware.battery@1.0-service \ + vendor.eureka.hardware.flashlight@1.0-service # Debug ifeq ($(TARGET_BUILD_VARIENT),eng)