mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 12:35:33 -04:00
universal7885: fm-aidl: Move to V2 version
- Also sort out common sysfs path - Also fix Android.bp formatting
This commit is contained in:
parent
3fa34f4db9
commit
1c59e28be9
5 changed files with 66 additions and 37 deletions
|
|
@ -2,7 +2,8 @@ cc_defaults {
|
||||||
name: "fm_aidl_defaults",
|
name: "fm_aidl_defaults",
|
||||||
cflags: [
|
cflags: [
|
||||||
"-DTRACK_SIZE=30",
|
"-DTRACK_SIZE=30",
|
||||||
"-DSYSFS_SPACING=3",],
|
"-DSYSFS_SPACING=3",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_binary {
|
cc_binary {
|
||||||
|
|
@ -22,7 +23,7 @@ cc_binary {
|
||||||
"libbinder_ndk",
|
"libbinder_ndk",
|
||||||
"liblog",
|
"liblog",
|
||||||
"libfileio",
|
"libfileio",
|
||||||
"vendor.eureka.hardware.fmradio-V1-ndk",
|
"vendor.eureka.hardware.fmradio-V2-ndk",
|
||||||
"vendor.eureka.hardware.audio_route-V1-ndk",
|
"vendor.eureka.hardware.audio_route-V1-ndk",
|
||||||
],
|
],
|
||||||
header_libs: ["libaudioclient_headers"],
|
header_libs: ["libaudioclient_headers"],
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,7 @@ namespace aidl::vendor::eureka::hardware::fmradio {
|
||||||
assert(fd > 0);
|
assert(fd > 0);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case GetType::GET_TYPE_FM_FREQ:
|
case GetType::GET_TYPE_FM_FREQ:
|
||||||
int64_t freq;
|
fm_radio_slsi::get_frequency(fd, _aidl_return);
|
||||||
fm_radio_slsi::get_frequency(fd, &freq);
|
|
||||||
*_aidl_return = freq;
|
|
||||||
break;
|
break;
|
||||||
case GetType::GET_TYPE_FM_UPPER_LIMIT:
|
case GetType::GET_TYPE_FM_UPPER_LIMIT:
|
||||||
*_aidl_return = fm_radio_slsi::get_upperband_limit(fd);
|
*_aidl_return = fm_radio_slsi::get_upperband_limit(fd);
|
||||||
|
|
@ -55,13 +53,25 @@ namespace aidl::vendor::eureka::hardware::fmradio {
|
||||||
*_aidl_return = fm_radio_slsi::get_rmssi(fd);
|
*_aidl_return = fm_radio_slsi::get_rmssi(fd);
|
||||||
break;
|
break;
|
||||||
case GetType::GET_TYPE_FM_BEFORE_CHANNEL:
|
case GetType::GET_TYPE_FM_BEFORE_CHANNEL:
|
||||||
*_aidl_return = fm_radio_slsi::before_channel(fd);
|
if (index > 0) index -= 1;
|
||||||
|
fm_radio_slsi::set_frequency(fd, freqs_list[index]);
|
||||||
|
*_aidl_return = freqs_list[index];
|
||||||
break;
|
break;
|
||||||
case GetType::GET_TYPE_FM_NEXT_CHANNEL:
|
case GetType::GET_TYPE_FM_NEXT_CHANNEL:
|
||||||
*_aidl_return = fm_radio_slsi::next_channel(fd);
|
if (index < freqs_list.size() - 1) index += 1;
|
||||||
|
fm_radio_slsi::set_frequency(fd, freqs_list[index]);
|
||||||
|
*_aidl_return = freqs_list[index];
|
||||||
break;
|
break;
|
||||||
case GetType::GET_TYPE_FM_SYSFS_IF:
|
case GetType::GET_TYPE_FM_SYSFS_IF:
|
||||||
NOT_SUPPORTED;
|
NOT_SUPPORTED;
|
||||||
|
case GetType::GET_TYPE_FM_MUTEX_LOCKED:
|
||||||
|
if (lock.try_lock()){
|
||||||
|
*_aidl_return = false;
|
||||||
|
lock.unlock();
|
||||||
|
} else {
|
||||||
|
*_aidl_return = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
@ -96,19 +106,22 @@ namespace aidl::vendor::eureka::hardware::fmradio {
|
||||||
svc = audio_route::IAudioRoute::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService("vendor.eureka.hardware.audio_route.IAudioRoute/default")));
|
svc = audio_route::IAudioRoute::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService("vendor.eureka.hardware.audio_route.IAudioRoute/default")));
|
||||||
svc->setParam(value ? "routing=2": "routing=8");
|
svc->setParam(value ? "routing=2": "routing=8");
|
||||||
break;
|
break;
|
||||||
|
case SetType::SET_TYPE_FM_SEARCH_START:
|
||||||
|
search_thread = std::thread([this] {
|
||||||
|
freqs_list = fm_radio_slsi::get_freqs(fd);
|
||||||
|
lock.unlock();
|
||||||
|
});
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
lock.unlock();
|
if (type != SetType::SET_TYPE_FM_SEARCH_START) lock.unlock();
|
||||||
return ::ndk::ScopedAStatus::ok();
|
return ::ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
::ndk::ScopedAStatus FMDevControl::getFreqsList(std::vector<int> *_aidl_return){
|
::ndk::ScopedAStatus FMDevControl::getFreqsList(std::vector<int> *_aidl_return){
|
||||||
RETURN_IF_FAILED_LOCK;
|
RETURN_IF_FAILED_LOCK;
|
||||||
auto vec = fm_radio_slsi::get_freqs(fd);
|
*_aidl_return = freqs_list;
|
||||||
for (auto i : vec)
|
|
||||||
_aidl_return->push_back(i);
|
|
||||||
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
return ::ndk::ScopedAStatus::ok();
|
return ::ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,15 @@
|
||||||
#include <aidl/vendor/eureka/hardware/fmradio/BnFMDevControl.h>
|
#include <aidl/vendor/eureka/hardware/fmradio/BnFMDevControl.h>
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
namespace aidl::vendor::eureka::hardware::fmradio {
|
namespace aidl::vendor::eureka::hardware::fmradio {
|
||||||
|
|
||||||
struct FMDevControl : public BnFMDevControl {
|
struct FMDevControl : public BnFMDevControl {
|
||||||
public:
|
public:
|
||||||
FMDevControl() = default;
|
FMDevControl(void) {
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
// Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow.
|
// Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow.
|
||||||
::ndk::ScopedAStatus open(void) override;
|
::ndk::ScopedAStatus open(void) override;
|
||||||
::ndk::ScopedAStatus getValue(GetType type, int *_aidl_return) override;
|
::ndk::ScopedAStatus getValue(GetType type, int *_aidl_return) override;
|
||||||
|
|
@ -31,6 +34,9 @@ struct FMDevControl : public BnFMDevControl {
|
||||||
::ndk::ScopedAStatus close(void) override;
|
::ndk::ScopedAStatus close(void) override;
|
||||||
private:
|
private:
|
||||||
int fd;
|
int fd;
|
||||||
|
unsigned int index;
|
||||||
std::timed_mutex lock;
|
std::timed_mutex lock;
|
||||||
|
std::thread search_thread;
|
||||||
|
std::vector<int> freqs_list;
|
||||||
};
|
};
|
||||||
} // namespace aidl::vendor::eureka::hardware::fmradio
|
} // namespace aidl::vendor::eureka::hardware::fmradio
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include "FMSupport.h"
|
#include "FMSupport.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
@ -26,10 +26,9 @@
|
||||||
|
|
||||||
namespace aidl::vendor::eureka::hardware::fmradio {
|
namespace aidl::vendor::eureka::hardware::fmradio {
|
||||||
|
|
||||||
constexpr const char *FM_FREQ_CTL =
|
#define FM_SYSFS_BASE "/sys/devices/virtual/s610_radio/s610_radio"
|
||||||
"/sys/devices/virtual/s610_radio/s610_radio/radio_freq_ctrl";
|
constexpr const char *FM_FREQ_CTL = FM_SYSFS_BASE "/radio_freq_ctrl";
|
||||||
constexpr const char *FM_FREQ_SEEK =
|
constexpr const char *FM_FREQ_SEEK = FM_SYSFS_BASE "/radio_freq_seek";
|
||||||
"/sys/devices/virtual/s610_radio/s610_radio/radio_freq_seek";
|
|
||||||
|
|
||||||
::ndk::ScopedAStatus FMSupport::open(void) { NOT_SUPPORTED; }
|
::ndk::ScopedAStatus FMSupport::open(void) { NOT_SUPPORTED; }
|
||||||
|
|
||||||
|
|
@ -52,7 +51,15 @@ constexpr const char *FM_FREQ_SEEK =
|
||||||
*_aidl_return = FileIO::readline(FM_FREQ_CTL);
|
*_aidl_return = FileIO::readline(FM_FREQ_CTL);
|
||||||
break;
|
break;
|
||||||
case GetType::GET_TYPE_FM_SYSFS_IF:
|
case GetType::GET_TYPE_FM_SYSFS_IF:
|
||||||
*_aidl_return = access("/sys/devices/virtual/s610_radio/s610_radio/", F_OK);
|
*_aidl_return = access(FM_SYSFS_BASE, F_OK);
|
||||||
|
break;
|
||||||
|
case GetType::GET_TYPE_FM_MUTEX_LOCKED:
|
||||||
|
if (lock.try_lock()) {
|
||||||
|
*_aidl_return = false;
|
||||||
|
lock.unlock();
|
||||||
|
} else {
|
||||||
|
*_aidl_return = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -73,31 +80,27 @@ constexpr const char *FM_FREQ_SEEK =
|
||||||
case SetType::SET_TYPE_FM_SEARCH_CANCEL:
|
case SetType::SET_TYPE_FM_SEARCH_CANCEL:
|
||||||
case SetType::SET_TYPE_FM_SPEAKER_ROUTE:
|
case SetType::SET_TYPE_FM_SPEAKER_ROUTE:
|
||||||
NOT_SUPPORTED;
|
NOT_SUPPORTED;
|
||||||
|
case SetType::SET_TYPE_FM_SEARCH_START:
|
||||||
|
search_thread = std::thread([this] {
|
||||||
|
for (int i = 0; i < TRACK_SIZE; i++) {
|
||||||
|
FileIO::writeline(FM_FREQ_SEEK, "1 " + std::to_string(SYSFS_SPACING * 10));
|
||||||
|
int freq = FileIO::readline(FM_FREQ_CTL);
|
||||||
|
if (std::find(freqs_list.begin(), freqs_list.end(), freq) != freqs_list.end()) continue;
|
||||||
|
freqs_list.push_back(freq);
|
||||||
|
}
|
||||||
|
lock.unlock();
|
||||||
|
});
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
lock.unlock();
|
if (type != SetType::SET_TYPE_FM_SEARCH_START) lock.unlock();
|
||||||
return ::ndk::ScopedAStatus::ok();
|
return ::ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool vector_contains(const std::vector<int> vec,
|
|
||||||
const int search) {
|
|
||||||
for (auto i : vec) {
|
|
||||||
if (i == search)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
::ndk::ScopedAStatus FMSupport::getFreqsList(std::vector<int> *_aidl_return) {
|
::ndk::ScopedAStatus FMSupport::getFreqsList(std::vector<int> *_aidl_return) {
|
||||||
RETURN_IF_FAILED_LOCK;
|
RETURN_IF_FAILED_LOCK;
|
||||||
for (int i = 0; i < TRACK_SIZE; i++) {
|
*_aidl_return = freqs_list;
|
||||||
FileIO::writeline(FM_FREQ_SEEK, "1 " + std::to_string(SYSFS_SPACING * 10));
|
|
||||||
int freq = FileIO::readline(FM_FREQ_CTL);
|
|
||||||
if (vector_contains(*_aidl_return, freq))
|
|
||||||
continue;
|
|
||||||
_aidl_return->push_back(freq);
|
|
||||||
}
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
return ::ndk::ScopedAStatus::ok();
|
return ::ndk::ScopedAStatus::ok();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,15 @@
|
||||||
#include <aidl/vendor/eureka/hardware/fmradio/BnFMDevControl.h>
|
#include <aidl/vendor/eureka/hardware/fmradio/BnFMDevControl.h>
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
namespace aidl::vendor::eureka::hardware::fmradio {
|
namespace aidl::vendor::eureka::hardware::fmradio {
|
||||||
|
|
||||||
struct FMSupport : public BnFMDevControl {
|
struct FMSupport : public BnFMDevControl {
|
||||||
public:
|
public:
|
||||||
FMSupport() = default;
|
FMSupport(void) {
|
||||||
|
index = 0;
|
||||||
|
};
|
||||||
// Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow.
|
// Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow.
|
||||||
::ndk::ScopedAStatus open(void) override;
|
::ndk::ScopedAStatus open(void) override;
|
||||||
::ndk::ScopedAStatus getValue(GetType type, int *_aidl_return) override;
|
::ndk::ScopedAStatus getValue(GetType type, int *_aidl_return) override;
|
||||||
|
|
@ -31,5 +34,8 @@ public:
|
||||||
::ndk::ScopedAStatus close(void) override;
|
::ndk::ScopedAStatus close(void) override;
|
||||||
private:
|
private:
|
||||||
std::timed_mutex lock;
|
std::timed_mutex lock;
|
||||||
|
std::thread search_thread;
|
||||||
|
std::vector<int> freqs_list;
|
||||||
|
int index;
|
||||||
};
|
};
|
||||||
} // namespace aidl::vendor::eureka::hardware::fmradio
|
} // namespace aidl::vendor::eureka::hardware::fmradio
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue