universal7885: fm-aidl: Rename interfaces and fix errors

This commit is contained in:
roynatech2544 2022-10-06 12:00:11 +00:00
commit 6fdc377216
16 changed files with 287 additions and 61 deletions

View file

@ -0,0 +1,27 @@
cc_library_shared {
name: "libaudiohack",
cflags: [
"-Wno-unused-parameter",
],
srcs: [
"FM_AudioRoute_ctl.cpp",
],
defaults: ["eureka_defaults"],
shared_libs: [
"liblog",
"libutils",
"audioflinger-aidl-cpp",
"audiopolicy-aidl-cpp",
"audiopolicy-types-aidl-cpp",
"libaudiofoundation",
"libaudioutils",
"libaudioclient",
"libutils",
"libaudiopolicy",
"libaudiomanager",
],
header_libs: [
"libaudioclient_headers",
"jni_headers",
],
}

View file

@ -1,10 +1,12 @@
cc_binary {
name: "vendor.eureka.hardware.fmradio-service",
srcs: [
"FMRadio.cpp",
"FMSupport.cpp",
"FMDevControl.cpp",
"service.cpp",
],
defaults: ["eureka_defaults"],
static_libs: ["libfm_slsi-impl"],
shared_libs: [
"libbase",
"libbinder_ndk",

View file

@ -0,0 +1,100 @@
// 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 "FMDevControl.h"
#include <fm_slsi-impl.h>
#include <cassert>
#include <fcntl.h>
namespace aidl::vendor::eureka::hardware::fmradio {
static int fd = -1;
::ndk::ScopedAStatus FMDevControl::open(void) {
fd = fm_radio_slsi::open_device();
assert(fd > 0);
fm_radio_slsi::bootctrl(fd);
return ::ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus FMDevControl::getValue(GetType type, int *_aidl_return) {
assert(fd > 0);
switch (type) {
case GetType::GET_TYPE_FM_FREQ:
int64_t freq;
fm_radio_slsi::get_frequency(fd, &freq);
*_aidl_return = freq;
break;
case GetType::GET_TYPE_FM_UPPER_LIMIT:
*_aidl_return = fm_radio_slsi::get_upperband_limit(fd);
break;
case GetType::GET_TYPE_FM_LOWER_LIMIT:
*_aidl_return = fm_radio_slsi::get_lowerband_limit(fd);
break;
case GetType::GET_TYPE_FM_RMSSI:
*_aidl_return = fm_radio_slsi::get_rmssi(fd);
break;
case GetType::GET_TYPE_FM_BEFORE_CHANNEL:
*_aidl_return = fm_radio_slsi::before_channel(fd);
break;
case GetType::GET_TYPE_FM_NEXT_CHANNEL:
*_aidl_return = fm_radio_slsi::next_channel(fd);
break;
default:
break;
};
return ::ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus FMDevControl::setValue(SetType type, int value) {
assert(fd > 0);
switch (type) {
case SetType::SET_TYPE_FM_FREQ:
fm_radio_slsi::set_frequency(fd, value);
break;
case SetType::SET_TYPE_FM_MUTE:
fm_radio_slsi::set_mute(fd, value);
break;
case SetType::SET_TYPE_FM_VOLUME:
fm_radio_slsi::set_volume(fd, value);
break;
case SetType::SET_TYPE_FM_THREAD:
fm_radio_slsi::fm_thread_set(fd, value);
break;
case SetType::SET_TYPE_FM_RMSSI:
fm_radio_slsi::set_rssi(fd, value);
break;
case SetType::SET_TYPE_FM_SEARCH_CANCEL:
fm_radio_slsi::stop_search(fd);
break;
default:
break;
};
return ::ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus FMDevControl::getFreqsList(std::vector<int> *_aidl_return){
auto vec = fm_radio_slsi::get_freqs(fd);
for (auto i : vec)
_aidl_return->push_back(i);
return ::ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus FMDevControl::close() {
if (fd > 0) ::close(fd);
fd = -1;
return ::ndk::ScopedAStatus::ok();
}
} // namespace aidl::vendor::eureka::hardware::fmradio

View file

@ -0,0 +1,31 @@
// 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/BnFMDevControl.h>
namespace aidl::vendor::eureka::hardware::fmradio {
struct FMDevControl : public BnFMDevControl {
public:
FMDevControl() = default;
// Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow.
::ndk::ScopedAStatus open(void) override;
::ndk::ScopedAStatus getValue(GetType type, int *_aidl_return) override;
::ndk::ScopedAStatus setValue(SetType type, int value) override;
::ndk::ScopedAStatus getFreqsList(std::vector<int> *_aidl_return) override;
::ndk::ScopedAStatus close(void) override;
};
} // namespace aidl::vendor::eureka::hardware::fmradio

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "FMRadio.h"
#include "FMSupport.h"
#include <fstream>
#include <iostream>
#include <sstream>
@ -30,12 +30,12 @@ constexpr const char *FM_FREQ_CTL =
constexpr const char *FM_FREQ_SEEK =
"/sys/devices/virtual/s610_radio/s610_radio/radio_freq_seek";
::ndk::ScopedAStatus FMRadio::setManualFreq(float freq) {
::ndk::ScopedAStatus FMSupport::setManualFreq(float freq) {
FileIO::writeline(FM_FREQ_CTL, freq * 1000);
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus FMRadio::adjustFreqByStep(Direction dir) {
::ndk::ScopedAStatus FMSupport::adjustFreqByStep(Direction dir) {
std::string value = "";
if (dir == Direction::UP) {
value = "1 " + std::to_string(mChannelSpacing * 10);
@ -45,21 +45,21 @@ constexpr const char *FM_FREQ_SEEK =
FileIO::writeline(FM_FREQ_SEEK, value);
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus FMRadio::isAvailable(bool *_aidl_return) {
::ndk::ScopedAStatus FMSupport::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) {
::ndk::ScopedAStatus FMSupport::setChannelSpacing(Space space) {
mChannelSpacing = static_cast<int>(space);
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus FMRadio::getFreqFromSysfs(int32_t *_aidl_return) {
::ndk::ScopedAStatus FMSupport::getFreqFromSysfs(int32_t *_aidl_return) {
*_aidl_return = FileIO::readline(FM_FREQ_CTL);
return ndk::ScopedAStatus::ok();
}
::ndk::ScopedAStatus FMRadio::getChannelSpacing(Space *_aidl_return) {
::ndk::ScopedAStatus FMSupport::getChannelSpacing(Space *_aidl_return) {
switch (mChannelSpacing) {
case 1:
*_aidl_return = Space::CHANNEL_SPACING_10HZ;

View file

@ -14,13 +14,13 @@
#pragma once
#include <aidl/vendor/eureka/hardware/fmradio/BnFMRadio.h>
#include <aidl/vendor/eureka/hardware/fmradio/BnFMSysfsSupport.h>
namespace aidl::vendor::eureka::hardware::fmradio {
struct FMRadio : public BnFMRadio {
struct FMSupport : public BnFMSysfsSupport {
public:
FMRadio() = default;
FMSupport() = default;
// Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow.
::ndk::ScopedAStatus setManualFreq(float freq) override;
::ndk::ScopedAStatus adjustFreqByStep(Direction dir) override;

View file

@ -5,26 +5,7 @@ cc_library_static {
],
srcs: [
"FM_Device_ctl.cpp",
"FM_AudioRoute_ctl.cpp",
],
export_include_dirs: ["public"],
defaults: ["eureka_defaults"],
shared_libs: [
"libhidlbase",
"liblog",
"libutils",
"audioflinger-aidl-cpp",
"audiopolicy-aidl-cpp",
"audiopolicy-types-aidl-cpp",
"libaudiofoundation",
"libaudioutils",
"libaudioclient",
"libutils",
"libaudiopolicy",
"libaudiomanager",
],
header_libs: [
"libaudioclient_headers",
"jni_headers",
],
}

View file

@ -10,12 +10,7 @@
#include <iostream>
#include "S610_FMRadio.h"
#include "V4L2_4_4_API.h"
#include <algorithm>
#include <jni.h>
#include <memory>
#include <vector>
#include <thread>
namespace fm_radio_slsi {
@ -81,7 +76,7 @@ static int set_control(const int fd, unsigned int id, int64_t val) {
return FM_SUCCESS;
}
int seek_frequency(int fd, unsigned int upward,
static int seek_frequency(int fd, unsigned int upward,
unsigned int wrap_around,
unsigned int spacing) {
struct v4l2_hw_freq_seek seek {};
@ -100,7 +95,7 @@ int seek_frequency(int fd, unsigned int upward,
return FM_SUCCESS;
}
int channel_search(const int fd, unsigned int upward,
static int channel_search(const int fd, unsigned int upward,
unsigned int wrap_around,
unsigned int spacing, int64_t *channel) {
int ret;
@ -120,7 +115,16 @@ int channel_search(const int fd, unsigned int upward,
return ret;
}
int next_channel(const int fd) {
int64_t ret;
channel_search(fd, 1, 0, FM_CHANNEL_SPACING_100KHZ, &ret);
return ret;
}
int before_channel(const int fd) {
int64_t ret;
channel_search(fd, 0, 0, FM_CHANNEL_SPACING_100KHZ, &ret);
return ret;
}
int set_mute(const int fd, bool mute) {
int ret = set_control(fd, V4L2_CID_AUDIO_MUTE, !mute);
if (ret < 0) {
@ -137,7 +141,7 @@ int set_volume(int fd, int volume /* 1 ~ 15 */) {
return FM_SUCCESS;
}
std::unique_ptr<int64_t[]> get_freqs(const int fd) {
std::vector<int64_t> get_freqs(const int fd) {
set_mute(fd, true);
auto map = std::vector<int64_t>();
@ -151,13 +155,8 @@ std::unique_ptr<int64_t[]> get_freqs(const int fd) {
map.push_back(found);
}
auto ptr = std::make_unique<int64_t[]>(map.size());
for (unsigned long i = 0; i < map.size(); i++) {
ptr[i] = map[i];
}
set_mute(fd, false);
return std::move(ptr);
return map;
}
static int fm_poll(int fd, struct pollfd *poll_fd) {

View file

@ -1,19 +1,17 @@
#pragma once
#include <memory>
#include <vector>
namespace fm_radio_slsi {
int open_device(void);
int get_frequency(const int fd, int64_t *channel);
int set_frequency(const int fd, int64_t channel);
int seek_frequency(int fd, unsigned int upward, unsigned int wrap_around,
unsigned int spacing);
int channel_search(const int fd, unsigned int upward, unsigned int wrap_around,
unsigned int spacing, int64_t *channel);
int next_channel(const int fd);
int before_channel(const int fd);
int set_mute(const int fd, bool mute);
int set_volume(int fd, int volume);
std::unique_ptr<int64_t[]> get_freqs(const int fd);
std::vector<int64_t> get_freqs(const int fd);
void fm_thread_set(const int fd, const bool enable);
unsigned int get_upperband_limit(int fd);
unsigned int get_lowerband_limit(int fd);

View file

@ -12,22 +12,29 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <android-base/logging.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <android-base/logging.h>
#include "FMRadio.h"
#include "FMSupport.h"
#include "FMDevControl.h"
using ::aidl::vendor::eureka::hardware::fmradio::FMRadio;
using ::aidl::vendor::eureka::hardware::fmradio::FMDevControl;
using ::aidl::vendor::eureka::hardware::fmradio::FMSupport;
template <class C> static void registerAsService(std::shared_ptr<C> service) {
const std::string instance = std::string() + C::descriptor + "/default";
binder_status_t status =
AServiceManager_addService(service->asBinder().get(), instance.c_str());
CHECK(status == STATUS_OK);
LOG(INFO) << "Register done for " << C::descriptor;
}
int main() {
ABinderProcess_setThreadPoolMaxThreadCount(0);
std::shared_ptr<FMRadio> fm_service = ndk::SharedRefBase::make<FMRadio>();
registerAsService(ndk::SharedRefBase::make<FMSupport>());
registerAsService(ndk::SharedRefBase::make<FMDevControl>());
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
}

View file

@ -1,6 +1,7 @@
<manifest version="1.0" type="framework">
<hal format="aidl">
<name>vendor.eureka.hardware.fmradio</name>
<fqname>IFMRadio/default</fqname>
<fqname>IFMSysfsSupport/default</fqname>
<fqname>IFMDevControl/default</fqname>
</hal>
</manifest>

View file

@ -0,0 +1,25 @@
// Copyright (C) 2022 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;
@Backing(type="int")
enum GetType {
GET_TYPE_FM_FREQ,
GET_TYPE_FM_UPPER_LIMIT,
GET_TYPE_FM_LOWER_LIMIT,
GET_TYPE_FM_RMSSI,
GET_TYPE_FM_BEFORE_CHANNEL,
GET_TYPE_FM_NEXT_CHANNEL
}

View file

@ -0,0 +1,30 @@
// Copyright (C) 2022 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;
import vendor.eureka.hardware.fmradio.GetType;
import vendor.eureka.hardware.fmradio.SetType;
interface IFMDevControl {
void open();
int getValue(in GetType type);
void setValue(in SetType type, int value);
int[] getFreqsList();
void close();
}

View file

@ -17,7 +17,7 @@ package vendor.eureka.hardware.fmradio;
import vendor.eureka.hardware.fmradio.Direction;
import vendor.eureka.hardware.fmradio.Space;
interface IFMRadio {
interface IFMSysfsSupport {
void adjustFreqByStep(in Direction dir);
Space getChannelSpacing();

View file

@ -0,0 +1,25 @@
// Copyright (C) 2022 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;
@Backing(type="int")
enum SetType {
SET_TYPE_FM_FREQ,
SET_TYPE_FM_MUTE,
SET_TYPE_FM_VOLUME,
SET_TYPE_FM_THREAD,
SET_TYPE_FM_RMSSI,
SET_TYPE_FM_SEARCH_CANCEL,
}