diff --git a/universal7885-common/apps/aidl-support/fm/default/Android.bp b/universal7885-common/apps/aidl-support/fm/default/Android.bp new file mode 100644 index 0000000..6c0aec3 --- /dev/null +++ b/universal7885-common/apps/aidl-support/fm/default/Android.bp @@ -0,0 +1,17 @@ +cc_binary { + name: "vendor.eureka.hardware.fmradio-service", + srcs: [ + "FMRadio.cpp", + "service.cpp", + ], + defaults: ["eureka_defaults"], + shared_libs: [ + "libbase", + "libbinder_ndk", + "liblog", + "libfileio", + "vendor.eureka.hardware.fmradio-ndk", + ], + init_rc: ["vendor.eureka.hardware.fmradio-service.rc"], + vintf_fragments: ["vendor.eureka.hardware.fmradio.xml"], +} diff --git a/universal7885-common/apps/aidl-support/fm/default/FMRadio.cpp b/universal7885-common/apps/aidl-support/fm/default/FMRadio.cpp new file mode 100644 index 0000000..9730dbb --- /dev/null +++ b/universal7885-common/apps/aidl-support/fm/default/FMRadio.cpp @@ -0,0 +1,84 @@ +// 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 "FMRadio.h" +#include +#include +#include +#include +#include + +#include + +static int mChannelSpacing = 3; + +namespace aidl::vendor::eureka::hardware::fmradio { + +constexpr const char *FM_FREQ_CTL = + "/sys/devices/virtual/s610_radio/s610_radio/radio_freq_ctrl"; +constexpr const char *FM_FREQ_SEEK = + "/sys/devices/virtual/s610_radio/s610_radio/radio_freq_seek"; + +::ndk::ScopedAStatus FMRadio::setManualFreq(float freq) { + FileIO::writeline(FM_FREQ_CTL, freq * 1000); + return ndk::ScopedAStatus::ok(); +} + +::ndk::ScopedAStatus FMRadio::adjustFreqByStep(Direction dir) { + std::string value = ""; + if (dir == Direction::UP) { + value = "1 " + std::to_string(mChannelSpacing * 10); + } else if (dir == Direction::DOWN) { + value = "0 " + std::to_string(mChannelSpacing * 10); + } + FileIO::writeline(FM_FREQ_SEEK, value); + return ndk::ScopedAStatus::ok(); +} +::ndk::ScopedAStatus FMRadio::isAvailable(bool *_aidl_return) { + struct stat info; + *_aidl_return = + stat("/sys/devices/virtual/s610_radio/s610_radio/", &info) != 0; + return ndk::ScopedAStatus::ok(); +} +::ndk::ScopedAStatus FMRadio::setChannelSpacing(Space space) { + mChannelSpacing = static_cast(space); + return ndk::ScopedAStatus::ok(); +} +::ndk::ScopedAStatus FMRadio::getFreqFromSysfs(int32_t *_aidl_return) { + *_aidl_return = FileIO::readline(FM_FREQ_CTL); + return ndk::ScopedAStatus::ok(); +} +::ndk::ScopedAStatus FMRadio::getChannelSpacing(Space *_aidl_return) { + switch (mChannelSpacing) { + case 1: + *_aidl_return = Space::CHANNEL_SPACING_10HZ; + break; + case 2: + *_aidl_return = Space::CHANNEL_SPACING_20HZ; + break; + case 3: + *_aidl_return = Space::CHANNEL_SPACING_30HZ; + break; + case 4: + *_aidl_return = Space::CHANNEL_SPACING_40HZ; + break; + case 5: + *_aidl_return = Space::CHANNEL_SPACING_50HZ; + break; + default: + break; + } + return ndk::ScopedAStatus::ok(); +} +} // namespace vendor::eureka::hardware::fmradio::V1_2 diff --git a/universal7885-common/apps/aidl-support/fm/default/FMRadio.h b/universal7885-common/apps/aidl-support/fm/default/FMRadio.h new file mode 100644 index 0000000..5ff0526 --- /dev/null +++ b/universal7885-common/apps/aidl-support/fm/default/FMRadio.h @@ -0,0 +1,32 @@ +// 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 + +namespace aidl::vendor::eureka::hardware::fmradio { + +struct FMRadio : public BnFMRadio { +public: + FMRadio() = default; + // Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow. + ::ndk::ScopedAStatus setManualFreq(float freq) override; + ::ndk::ScopedAStatus adjustFreqByStep(Direction dir) override; + ::ndk::ScopedAStatus isAvailable(bool *aidl_return) override; + ::ndk::ScopedAStatus getFreqFromSysfs(int32_t *aidl_return) override; + ::ndk::ScopedAStatus setChannelSpacing(Space space) override; + ::ndk::ScopedAStatus getChannelSpacing(Space *_aidl_return) override; +}; +} // namespace aidl::vendor::eureka::hardware::fmradio diff --git a/universal7885-common/apps/aidl-support/fm/default/service.cpp b/universal7885-common/apps/aidl-support/fm/default/service.cpp new file mode 100644 index 0000000..9128b78 --- /dev/null +++ b/universal7885-common/apps/aidl-support/fm/default/service.cpp @@ -0,0 +1,33 @@ +// 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 +#include +#include + +#include "FMRadio.h" + +using ::aidl::vendor::eureka::hardware::fmradio::FMRadio; + +int main() { + ABinderProcess_setThreadPoolMaxThreadCount(0); + + std::shared_ptr fm_service = ndk::SharedRefBase::make(); + + const std::string instance = std::string() + FMRadio::descriptor + "/default"; + binder_status_t status = AServiceManager_addService(fm_service->asBinder().get(), instance.c_str()); + CHECK(status == STATUS_OK); + ABinderProcess_joinThreadPool(); + return -1; // should never get here +} diff --git a/universal7885-common/apps/aidl-support/fm/default/vendor.eureka.hardware.fmradio-service.rc b/universal7885-common/apps/aidl-support/fm/default/vendor.eureka.hardware.fmradio-service.rc new file mode 100644 index 0000000..f3d3c1f --- /dev/null +++ b/universal7885-common/apps/aidl-support/fm/default/vendor.eureka.hardware.fmradio-service.rc @@ -0,0 +1,4 @@ +service fm-hal-aidl /system/bin/vendor.eureka.hardware.fmradio-service + class hal + user root + group root diff --git a/universal7885-common/apps/aidl-support/fm/default/vendor.eureka.hardware.fmradio.xml b/universal7885-common/apps/aidl-support/fm/default/vendor.eureka.hardware.fmradio.xml new file mode 100644 index 0000000..ea321f7 --- /dev/null +++ b/universal7885-common/apps/aidl-support/fm/default/vendor.eureka.hardware.fmradio.xml @@ -0,0 +1,6 @@ + + + vendor.eureka.hardware.fmradio + IFMRadio/default + +