From e07865c670f41ad2ed6e3e6d5f5d75cf9ec68eb2 Mon Sep 17 00:00:00 2001 From: roynatech2544 Date: Sun, 20 Feb 2022 13:24:15 +0900 Subject: [PATCH] universal7885: interfaces: Implement FMRadio HAL V1.2 * Also, track our fork of OneUI theme lib * Implement read from sysfs interface which can fix channel searching on some cases * Commit link: https://github.com/eurekadevelopment/Eureka-Kernel-Exynos7885-Q-R-S/commit/fead45ba0e252a09e414a4dd96724c2cea9f8679 Change-Id: I81532b7f8169637fdcad0f678790a2b1f1888ecc Signed-off-by: roynatech2544 --- universal7885-common/apps/FMRadio/Android.bp | 1 + .../apps/FMRadio/jni/Android.bp | 8 ++++ .../apps/FMRadio/jni/fm_ioctl.cpp | 17 ++++++- .../hardware/fmradio/1.1/IFMRadio.hal | 1 + .../hardware/fmradio/1.2/Android.bp | 14 ++++++ .../hardware/fmradio/1.2/IFMRadio.hal | 22 +++++++++ .../fmradio/{1.1 => 1.2}/default/Android.bp | 7 +-- .../fmradio/{1.1 => 1.2}/default/FMRadio.cpp | 46 ++++++++++++++----- .../fmradio/{1.1 => 1.2}/default/FMRadio.h | 12 +++-- .../fmradio/{1.1 => 1.2}/default/service.cpp | 8 ++-- ...or.eureka.hardware.fmradio@1.2-service.rc} | 3 +- .../vendor.eureka.hardware.fmradio@1.2.xml} | 2 +- .../interfaces/hardware/fmradio/1.2/types.hal | 23 ++++++++++ universal7885-common/vendorsetup.sh | 1 + 14 files changed, 140 insertions(+), 25 deletions(-) create mode 100644 universal7885-common/interfaces/hardware/fmradio/1.2/Android.bp create mode 100644 universal7885-common/interfaces/hardware/fmradio/1.2/IFMRadio.hal rename universal7885-common/interfaces/hardware/fmradio/{1.1 => 1.2}/default/Android.bp (60%) rename universal7885-common/interfaces/hardware/fmradio/{1.1 => 1.2}/default/FMRadio.cpp (50%) rename universal7885-common/interfaces/hardware/fmradio/{1.1 => 1.2}/default/FMRadio.h (75%) rename universal7885-common/interfaces/hardware/fmradio/{1.1 => 1.2}/default/service.cpp (84%) rename universal7885-common/interfaces/hardware/fmradio/{1.1/default/vendor.eureka.hardware.fmradio@1.1-service.rc => 1.2/default/vendor.eureka.hardware.fmradio@1.2-service.rc} (73%) rename universal7885-common/interfaces/hardware/fmradio/{1.1/default/vendor.eureka.hardware.fmradio@1.1.xml => 1.2/default/vendor.eureka.hardware.fmradio@1.2.xml} (90%) create mode 100644 universal7885-common/interfaces/hardware/fmradio/1.2/types.hal diff --git a/universal7885-common/apps/FMRadio/Android.bp b/universal7885-common/apps/FMRadio/Android.bp index 57dc145..4eb94c2 100644 --- a/universal7885-common/apps/FMRadio/Android.bp +++ b/universal7885-common/apps/FMRadio/Android.bp @@ -14,6 +14,7 @@ android_app { ], required: [ "privapp_whitelist_com.eurekateam.fmradio.xml", + "vendor.eureka.hardware.fmradio@1.2-service", ], optimize: { proguard_flags_files: ["rules.pro"], diff --git a/universal7885-common/apps/FMRadio/jni/Android.bp b/universal7885-common/apps/FMRadio/jni/Android.bp index f746390..56e7e41 100644 --- a/universal7885-common/apps/FMRadio/jni/Android.bp +++ b/universal7885-common/apps/FMRadio/jni/Android.bp @@ -4,6 +4,14 @@ cc_library_shared { "-Wno-unused-parameter", ], srcs: ["fm_ioctl.cpp"], + shared_libs: [ + "libhidlbase", + "liblog", + "libutils", + "vendor.eureka.hardware.fmradio@1.0", + "vendor.eureka.hardware.fmradio@1.1", + "vendor.eureka.hardware.fmradio@1.2", + ], header_libs: ["jni_headers"], } diff --git a/universal7885-common/apps/FMRadio/jni/fm_ioctl.cpp b/universal7885-common/apps/FMRadio/jni/fm_ioctl.cpp index 2ac1ce8..c6e6cf6 100644 --- a/universal7885-common/apps/FMRadio/jni/fm_ioctl.cpp +++ b/universal7885-common/apps/FMRadio/jni/fm_ioctl.cpp @@ -11,6 +11,16 @@ #include "kernel_internal.h" #include #include +#include +#include +#include +#include +#include + +using android::sp; +using vendor::eureka::hardware::fmradio::V1_2::IFMRadio; +using vendor::eureka::hardware::fmradio::V1_0::Direction; +using vendor::eureka::hardware::fmradio::V1_1::Status; //#define DEBUG #define TRACK_SIZE 30 @@ -185,7 +195,12 @@ static long fm_radio_get_freqs(int fd){ long ret = 0; fm_radio_set_mute(fd, true); for (long & track : tracks){ - fm_radio_channel_searching(fd, 1, 0, FM_CHANNEL_SPACING_50KHZ, &ret); + if (mSysfs) { + service->adjustFreqByStep(Direction::UP); + ret = (long) service->getFreqFromSysfs(); + } else { + fm_radio_channel_searching(fd, 1, 0, FM_CHANNEL_SPACING_50KHZ, &ret); + } if (contains(tracks, ret)) break; track = ret; printf("Found Freq %ld\n", ret); diff --git a/universal7885-common/interfaces/hardware/fmradio/1.1/IFMRadio.hal b/universal7885-common/interfaces/hardware/fmradio/1.1/IFMRadio.hal index f76b0eb..4ac9a13 100644 --- a/universal7885-common/interfaces/hardware/fmradio/1.1/IFMRadio.hal +++ b/universal7885-common/interfaces/hardware/fmradio/1.1/IFMRadio.hal @@ -17,5 +17,6 @@ package vendor.eureka.hardware.fmradio@1.1; import @1.0::IFMRadio; interface IFMRadio extends @1.0::IFMRadio { + getFreqFromSysfs() generates (int32_t freq); isAvailable() generates (Status status); }; diff --git a/universal7885-common/interfaces/hardware/fmradio/1.2/Android.bp b/universal7885-common/interfaces/hardware/fmradio/1.2/Android.bp new file mode 100644 index 0000000..0cf124b --- /dev/null +++ b/universal7885-common/interfaces/hardware/fmradio/1.2/Android.bp @@ -0,0 +1,14 @@ +hidl_interface { + name: "vendor.eureka.hardware.fmradio@1.2", + root: "vendor.eureka", + srcs: [ + "types.hal", + "IFMRadio.hal", + ], + interfaces: [ + "android.hidl.base@1.0", + "vendor.eureka.hardware.fmradio@1.1", + "vendor.eureka.hardware.fmradio@1.0", + ], + gen_java: true, +} diff --git a/universal7885-common/interfaces/hardware/fmradio/1.2/IFMRadio.hal b/universal7885-common/interfaces/hardware/fmradio/1.2/IFMRadio.hal new file mode 100644 index 0000000..fe078f8 --- /dev/null +++ b/universal7885-common/interfaces/hardware/fmradio/1.2/IFMRadio.hal @@ -0,0 +1,22 @@ +// 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.fmradio@1.2; + +import @1.1::IFMRadio; + +interface IFMRadio extends @1.1::IFMRadio { + setChannelSpacing(Space space); + getChannelSpacing() generates (Space space); +}; diff --git a/universal7885-common/interfaces/hardware/fmradio/1.1/default/Android.bp b/universal7885-common/interfaces/hardware/fmradio/1.2/default/Android.bp similarity index 60% rename from universal7885-common/interfaces/hardware/fmradio/1.1/default/Android.bp rename to universal7885-common/interfaces/hardware/fmradio/1.2/default/Android.bp index 6cd759a..c48e785 100644 --- a/universal7885-common/interfaces/hardware/fmradio/1.1/default/Android.bp +++ b/universal7885-common/interfaces/hardware/fmradio/1.2/default/Android.bp @@ -1,7 +1,7 @@ // FIXME: your file license if you have one cc_binary { - name: "vendor.eureka.hardware.fmradio@1.1-service", + name: "vendor.eureka.hardware.fmradio@1.2-service", relative_install_path: "hw", proprietary: true, srcs: [ @@ -14,7 +14,8 @@ cc_binary { "liblog", "vendor.eureka.hardware.fmradio@1.0", "vendor.eureka.hardware.fmradio@1.1", + "vendor.eureka.hardware.fmradio@1.2", ], - init_rc: [ "vendor.eureka.hardware.fmradio@1.1-service.rc" ], - vintf_fragments: [ "vendor.eureka.hardware.fmradio@1.1.xml" ], + init_rc: [ "vendor.eureka.hardware.fmradio@1.2-service.rc" ], + vintf_fragments: [ "vendor.eureka.hardware.fmradio@1.2.xml" ], } diff --git a/universal7885-common/interfaces/hardware/fmradio/1.1/default/FMRadio.cpp b/universal7885-common/interfaces/hardware/fmradio/1.2/default/FMRadio.cpp similarity index 50% rename from universal7885-common/interfaces/hardware/fmradio/1.1/default/FMRadio.cpp rename to universal7885-common/interfaces/hardware/fmradio/1.2/default/FMRadio.cpp index 9238d70..43096d6 100644 --- a/universal7885-common/interfaces/hardware/fmradio/1.1/default/FMRadio.cpp +++ b/universal7885-common/interfaces/hardware/fmradio/1.2/default/FMRadio.cpp @@ -19,9 +19,11 @@ #include #include -namespace vendor::eureka::hardware::fmradio::V1_1 { +static int mChannelSpacing = 3; -Return IFMRadio::setManualFreq(float freq) { +namespace vendor::eureka::hardware::fmradio::V1_2 { + +Return FMRadio::setManualFreq(float freq) { std::ofstream file; file.open("/sys/devices/virtual/s610_radio/s610_radio/radio_freq_ctrl"); file << freq * 1000; @@ -29,13 +31,13 @@ Return IFMRadio::setManualFreq(float freq) { return Void(); } -Return IFMRadio::adjustFreqByStep(fmradio::V1_0::Direction dir) { +Return FMRadio::adjustFreqByStep(fmradio::V1_0::Direction dir) { std::ofstream file; std::string value = ""; - if (dir == Direction::UP){ - value = "1 50"; - } else if (dir == Direction::DOWN){ - value = "0 50"; + if (dir == V1_0::Direction::UP){ + value = "1 " + std::to_string(mChannelSpacing * 10); + } else if (dir == V1_0::Direction::DOWN){ + value = "0 " + std::to_string(mChannelSpacing * 10); } file.open("/sys/devices/virtual/s610_radio/s610_radio/radio_freq_seek"); file << value; @@ -45,12 +47,34 @@ Return IFMRadio::adjustFreqByStep(fmradio::V1_0::Direction dir) { Return IFMRadio::isAvailable(){ struct stat info; if(stat("/sys/devices/virtual/s610_radio/s610_radio/", &info ) != 0) { - return Status::NO; - else - return Status::YES; + return V1_1::Status::NO; + } else { + return V1_1::Status::YES; } } -IFMRadio* IFMRadio::getInstance(void) { +Return FMRadio::setChannelSpacing(V1_2::Space space){ + mChannelSpacing = (int) space; + return Void(); +} +Return FMRadio::getFreqFromSysfs(){ + std::ifstream file; + std::string value; + file.open("/sys/devices/virtual/s610_radio/s610_radio/radio_freq_ctrl"); + std::getline(file, value); + file.close(); + return std::stoi(value); +} +Return FMRadio::getChannelSpacing(){ + switch (mChannelSpacing) { + case 1: return V1_2::Space::CHANNEL_SPACING_10HZ; + case 2: return V1_2::Space::CHANNEL_SPACING_20HZ; + case 3: return V1_2::Space::CHANNEL_SPACING_30HZ; + case 4: return V1_2::Space::CHANNEL_SPACING_40HZ; + case 5: return V1_2::Space::CHANNEL_SPACING_50HZ; + default: return V1_2::Space::CHANNEL_SPACING_30HZ; + } +} +IFMRadio* FMRadio::getInstance(void) { return new FMRadio(); } } // namespace vendor::eureka::hardware::fmradio::V1_0 diff --git a/universal7885-common/interfaces/hardware/fmradio/1.1/default/FMRadio.h b/universal7885-common/interfaces/hardware/fmradio/1.2/default/FMRadio.h similarity index 75% rename from universal7885-common/interfaces/hardware/fmradio/1.1/default/FMRadio.h rename to universal7885-common/interfaces/hardware/fmradio/1.2/default/FMRadio.h index 3b2580e..a8b535c 100644 --- a/universal7885-common/interfaces/hardware/fmradio/1.1/default/FMRadio.h +++ b/universal7885-common/interfaces/hardware/fmradio/1.2/default/FMRadio.h @@ -16,9 +16,9 @@ #include #include -#include +#include -namespace vendor::eureka::hardware::fmradio::V1_1 { +namespace vendor::eureka::hardware::fmradio::V1_2 { using ::android::sp; using ::android::hardware::hidl_array; @@ -31,9 +31,13 @@ using ::android::hardware::Void; struct FMRadio : public IFMRadio { // Methods from ::vendor::eureka::hardware::fmradio::V1_0::IFMRadio follow. Return setManualFreq(float freq); - Return adjustFreqByStep(Direction dir); + Return adjustFreqByStep(V1_0::Direction dir); // Methods from ::vendor::eureka::hardware::fmradio::V1_1::IFMRadio follow. - Return isAvailable(); + Return isAvailable(); + Return getFreqFromSysfs(); + // Methods from ::vendor::eureka::hardware::fmradio::V1_2::IFMRadio follow. + Return setChannelSpacing(V1_2::Space space); + Return getChannelSpacing(); // Methods from ::android::hidl::base::V1_0::IBase follow. static IFMRadio* getInstance(void); }; diff --git a/universal7885-common/interfaces/hardware/fmradio/1.1/default/service.cpp b/universal7885-common/interfaces/hardware/fmradio/1.2/default/service.cpp similarity index 84% rename from universal7885-common/interfaces/hardware/fmradio/1.1/default/service.cpp rename to universal7885-common/interfaces/hardware/fmradio/1.2/default/service.cpp index 142d163..a8154d2 100644 --- a/universal7885-common/interfaces/hardware/fmradio/1.1/default/service.cpp +++ b/universal7885-common/interfaces/hardware/fmradio/1.2/default/service.cpp @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#define LOG_TAG "vendor.eureka.hardware.fmradio@1.0-service" +#define LOG_TAG "vendor.eureka.hardware.fmradio@1.2-service" -#include +#include #include @@ -23,8 +23,8 @@ using android::sp; using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; -using vendor::eureka::hardware::fmradio::V1_1::FMRadio; -using vendor::eureka::hardware::fmradio::V1_1::IFMRadio; +using vendor::eureka::hardware::fmradio::V1_2::FMRadio; +using vendor::eureka::hardware::fmradio::V1_2::IFMRadio; int main() { int ret; diff --git a/universal7885-common/interfaces/hardware/fmradio/1.1/default/vendor.eureka.hardware.fmradio@1.1-service.rc b/universal7885-common/interfaces/hardware/fmradio/1.2/default/vendor.eureka.hardware.fmradio@1.2-service.rc similarity index 73% rename from universal7885-common/interfaces/hardware/fmradio/1.1/default/vendor.eureka.hardware.fmradio@1.1-service.rc rename to universal7885-common/interfaces/hardware/fmradio/1.2/default/vendor.eureka.hardware.fmradio@1.2-service.rc index 1c36326..689cf7b 100644 --- a/universal7885-common/interfaces/hardware/fmradio/1.1/default/vendor.eureka.hardware.fmradio@1.1-service.rc +++ b/universal7885-common/interfaces/hardware/fmradio/1.2/default/vendor.eureka.hardware.fmradio@1.2-service.rc @@ -1,6 +1,7 @@ -service vendor.parts-hal /vendor/bin/hw/vendor.eureka.hardware.fmradio@1.1-service +service vendor.parts-hal /vendor/bin/hw/vendor.eureka.hardware.fmradio@1.2-service interface vendor.eureka.hardware.fmradio@1.0::IFMRadio default interface vendor.eureka.hardware.fmradio@1.1::IFMRadio default + interface vendor.eureka.hardware.fmradio@1.2::IFMRadio default class hal user root group root diff --git a/universal7885-common/interfaces/hardware/fmradio/1.1/default/vendor.eureka.hardware.fmradio@1.1.xml b/universal7885-common/interfaces/hardware/fmradio/1.2/default/vendor.eureka.hardware.fmradio@1.2.xml similarity index 90% rename from universal7885-common/interfaces/hardware/fmradio/1.1/default/vendor.eureka.hardware.fmradio@1.1.xml rename to universal7885-common/interfaces/hardware/fmradio/1.2/default/vendor.eureka.hardware.fmradio@1.2.xml index c6c8381..4a061cb 100644 --- a/universal7885-common/interfaces/hardware/fmradio/1.1/default/vendor.eureka.hardware.fmradio@1.1.xml +++ b/universal7885-common/interfaces/hardware/fmradio/1.2/default/vendor.eureka.hardware.fmradio@1.2.xml @@ -2,7 +2,7 @@ vendor.eureka.hardware.fmradio hwbinder - 1.1 + 1.2 IFMRadio default diff --git a/universal7885-common/interfaces/hardware/fmradio/1.2/types.hal b/universal7885-common/interfaces/hardware/fmradio/1.2/types.hal new file mode 100644 index 0000000..a3d55e0 --- /dev/null +++ b/universal7885-common/interfaces/hardware/fmradio/1.2/types.hal @@ -0,0 +1,23 @@ +// 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.fmradio@1.2; + +enum Space : int32_t { + CHANNEL_SPACING_10HZ = 1, + CHANNEL_SPACING_20HZ, + CHANNEL_SPACING_30HZ, + CHANNEL_SPACING_40HZ, + CHANNEL_SPACING_50HZ = 5, +}; diff --git a/universal7885-common/vendorsetup.sh b/universal7885-common/vendorsetup.sh index 76d9ef3..ea873df 100644 --- a/universal7885-common/vendorsetup.sh +++ b/universal7885-common/vendorsetup.sh @@ -11,6 +11,7 @@ git clone https://github.com/lineageos/android_hardware_samsung_nfc hardware/sam git clone https://github.com/lineageos/android_hardware_samsung_slsi_libbt hardware/samsung_slsi/libbt git clone https://github.com/eurekadevelopment/android_hardware_samsung_slsi_scsc_wifibt_wifi_hal.git hardware/samsung_slsi/scsc_wifibt/wifi_hal git clone https://github.com/lineageos/android_hardware_samsung_slsi_scsc_wifibt_wpa_supplicant_lib hardware/samsung_slsi/scsc_wifibt/wpa_supplicant_lib +git clone https://github.com/eurekadevelopment/OneUI-Design-Library external/OneUI --depth=1 # Vendors git clone --depth=1 https://github.com/eurekadevelopment/android_vendor_samsung_exynos7885.git -b master vendor/samsung if test -f device/samsung/universal7885-common/vendor_name; then