mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-22 12:05:32 -04:00
universal7885: Move FM HAL to AIDL impl
This commit is contained in:
parent
402ea33acb
commit
7beedaa4e4
6 changed files with 176 additions and 0 deletions
17
universal7885-common/apps/aidl-support/fm/default/Android.bp
Normal file
17
universal7885-common/apps/aidl-support/fm/default/Android.bp
Normal file
|
|
@ -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"],
|
||||||
|
}
|
||||||
|
|
@ -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 <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <FileIO.h>
|
||||||
|
|
||||||
|
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<int>(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
|
||||||
32
universal7885-common/apps/aidl-support/fm/default/FMRadio.h
Normal file
32
universal7885-common/apps/aidl-support/fm/default/FMRadio.h
Normal file
|
|
@ -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 <aidl/vendor/eureka/hardware/fmradio/BnFMRadio.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -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 <android/binder_manager.h>
|
||||||
|
#include <android/binder_process.h>
|
||||||
|
#include <android-base/logging.h>
|
||||||
|
|
||||||
|
#include "FMRadio.h"
|
||||||
|
|
||||||
|
using ::aidl::vendor::eureka::hardware::fmradio::FMRadio;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||||
|
|
||||||
|
std::shared_ptr<FMRadio> fm_service = ndk::SharedRefBase::make<FMRadio>();
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
service fm-hal-aidl /system/bin/vendor.eureka.hardware.fmradio-service
|
||||||
|
class hal
|
||||||
|
user root
|
||||||
|
group root
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<manifest version="1.0" type="framework">
|
||||||
|
<hal format="aidl">
|
||||||
|
<name>vendor.eureka.hardware.fmradio</name>
|
||||||
|
<fqname>IFMRadio/default</fqname>
|
||||||
|
</hal>
|
||||||
|
</manifest>
|
||||||
Loading…
Reference in a new issue