universal7885: fm-aidl: Implement new settype

Creates a thread that can poll pid value passed by this settype. Can track the client status with this
This commit is contained in:
roynatech2544 2022-10-28 23:34:51 +09:00
commit 06ca6c2ea6
4 changed files with 24 additions and 4 deletions

View file

@ -23,7 +23,7 @@ cc_binary {
"libbinder_ndk",
"liblog",
"libfileio",
"vendor.eureka.hardware.fmradio-V2-ndk",
"vendor.eureka.hardware.fmradio-V3-ndk",
"vendor.eureka.hardware.audio_route-V1-ndk",
],
header_libs: ["libaudioclient_headers"],

View file

@ -20,8 +20,10 @@
#include <cassert>
#include <cerrno>
#include <chrono>
#include <fcntl.h>
#include <signal.h>
#include "CommonMacro.h"
@ -94,9 +96,10 @@ namespace aidl::vendor::eureka::hardware::fmradio {
}
::ndk::ScopedAStatus FMDevControl::setValue(SetType type, int value) {
using audio_route::IAudioRoute;
RETURN_IF_FAILED_LOCK;
assert(fd > 0);
std::shared_ptr<audio_route::IAudioRoute> svc;
switch (type) {
case SetType::SET_TYPE_FM_FREQ:
fm_radio_slsi::set_frequency(fd, value);
@ -119,7 +122,7 @@ namespace aidl::vendor::eureka::hardware::fmradio {
fm_radio_slsi::stop_search(fd);
break;
case SetType::SET_TYPE_FM_SPEAKER_ROUTE:
svc = audio_route::IAudioRoute::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService("vendor.eureka.hardware.audio_route.IAudioRoute/default")));
std::shared_ptr<IAudioRoute> svc = IAudioRoute::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService("vendor.eureka.hardware.audio_route.IAudioRoute/default")));
svc->setParam(value ? "routing=2": "routing=8");
break;
case SetType::SET_TYPE_FM_SEARCH_START:
@ -130,6 +133,22 @@ namespace aidl::vendor::eureka::hardware::fmradio {
});
search_thread.detach();
break;
case SetType::SET_TYPE_FM_APP_PID:
client_observe_thread = std::thread([=] {
std::shared_ptr<IAudioRoute> svc;
pid_t pid = value;
while (true) {
if (kill(pid, 0) < 0 && errno == ESRCH) break;
std::this_thread::sleep_for(std::chrono::seconds(2));
}
fm_radio_slsi::fm_thread_set(fd, 0);
svc = IAudioRoute::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService("vendor.eureka.hardware.audio_route.IAudioRoute/default")));
svc->setParam("l_fmradio_mode=off");
close();
}
client_observe_thread.detach();
default:
break;
};

View file

@ -38,7 +38,7 @@ struct FMDevControl : public BnFMDevControl {
int fd;
unsigned int index;
std::timed_mutex lock;
std::thread search_thread;
std::thread search_thread, client_observe_thread;
std::vector<int> freqs_list;
middlestate_t *kMiddleState;
};

View file

@ -97,6 +97,7 @@ constexpr const char *FM_FREQ_SEEK = FM_SYSFS_BASE "/radio_freq_seek";
case SetType::SET_TYPE_FM_RMSSI:
case SetType::SET_TYPE_FM_SEARCH_CANCEL:
case SetType::SET_TYPE_FM_SPEAKER_ROUTE:
case SetType::SET_TYPE_FM_APP_PID:
NOT_SUPPORTED;
case SetType::SET_TYPE_FM_SEARCH_START:
lock.unlock();