universal7885: fm-aidl: Run clang-format

This commit is contained in:
roynatech2544 2022-11-09 19:03:21 +09:00
commit 7d23777f39
8 changed files with 203 additions and 188 deletions

View file

@ -16,16 +16,16 @@
#include "FMDevControl.h" #include "FMDevControl.h"
#include <fm_slsi-impl.h>
#include <LogFormat.h> #include <LogFormat.h>
#include <fm_slsi-impl.h>
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <log/log.h> #include <log/log.h>
#include <algorithm>
#include <cassert> #include <cassert>
#include <cerrno> #include <cerrno>
#include <chrono> #include <chrono>
#include <algorithm>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
@ -63,7 +63,8 @@ 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:
if (index > 0) index -= 1; if (index > 0)
index -= 1;
if (kMiddleState != nullptr) { if (kMiddleState != nullptr) {
index = kMiddleState->first; index = kMiddleState->first;
delete kMiddleState; delete kMiddleState;
@ -73,7 +74,8 @@ namespace aidl::vendor::eureka::hardware::fmradio {
*_aidl_return = freqs_list[index]; *_aidl_return = freqs_list[index];
break; break;
case GetType::GET_TYPE_FM_NEXT_CHANNEL: case GetType::GET_TYPE_FM_NEXT_CHANNEL:
if (index < freqs_list.size() - 1) index += 1; if (index < freqs_list.size() - 1)
index += 1;
if (kMiddleState != nullptr) { if (kMiddleState != nullptr) {
index = kMiddleState->second; index = kMiddleState->second;
delete kMiddleState; delete kMiddleState;
@ -113,7 +115,8 @@ namespace aidl::vendor::eureka::hardware::fmradio {
switch (type) { switch (type) {
case SetType::SET_TYPE_FM_FREQ: case SetType::SET_TYPE_FM_FREQ:
fm_radio_slsi::set_frequency(fd, value); fm_radio_slsi::set_frequency(fd, value);
if (std::find(freqs_list.begin(), freqs_list.end(), value) == freqs_list.end()) if (std::find(freqs_list.begin(), freqs_list.end(), value) ==
freqs_list.end())
kMiddleState = saveMiddleState(value, freqs_list); kMiddleState = saveMiddleState(value, freqs_list);
break; break;
case SetType::SET_TYPE_FM_MUTE: case SetType::SET_TYPE_FM_MUTE:
@ -132,7 +135,9 @@ namespace aidl::vendor::eureka::hardware::fmradio {
fm_radio_slsi::stop_search(fd); fm_radio_slsi::stop_search(fd);
break; break;
case SetType::SET_TYPE_FM_SPEAKER_ROUTE: { case SetType::SET_TYPE_FM_SPEAKER_ROUTE: {
auto svc = IAudioRoute::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService("vendor.eureka.hardware.audio_route.IAudioRoute/default"))); auto svc =
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;
} }
@ -150,7 +155,8 @@ namespace aidl::vendor::eureka::hardware::fmradio {
LOG_D("FM_APP_PID: received value %d", pid); LOG_D("FM_APP_PID: received value %d", pid);
while (true) { while (true) {
if (kill(pid, 0) < 0 && errno == ESRCH) break; if (kill(pid, 0) < 0 && errno == ESRCH)
break;
std::this_thread::sleep_for(std::chrono::seconds(2)); std::this_thread::sleep_for(std::chrono::seconds(2));
} }
LOG_W("FM_APP_PID: Starting client death receiver"); LOG_W("FM_APP_PID: Starting client death receiver");
@ -162,11 +168,13 @@ namespace aidl::vendor::eureka::hardware::fmradio {
default: default:
break; break;
}; };
if (type != SetType::SET_TYPE_FM_SEARCH_START) 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;
*_aidl_return = freqs_list; *_aidl_return = freqs_list;
lock.unlock(); lock.unlock();
@ -174,7 +182,8 @@ namespace aidl::vendor::eureka::hardware::fmradio {
} }
::ndk::ScopedAStatus FMDevControl::close() { ::ndk::ScopedAStatus FMDevControl::close() {
if (fd > 0) ::close(fd); if (fd > 0)
::close(fd);
fd = -1; fd = -1;
return ::ndk::ScopedAStatus::ok(); return ::ndk::ScopedAStatus::ok();
} }

View file

@ -25,15 +25,14 @@ namespace aidl::vendor::eureka::hardware::fmradio {
struct FMDevControl : public BnFMDevControl { struct FMDevControl : public BnFMDevControl {
public: public:
FMDevControl(void) { FMDevControl(void) { index = 0; }
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;
::ndk::ScopedAStatus setValue(SetType type, int value) override; ::ndk::ScopedAStatus setValue(SetType type, int value) override;
::ndk::ScopedAStatus getFreqsList(std::vector<int> *_aidl_return) override; ::ndk::ScopedAStatus getFreqsList(std::vector<int> *_aidl_return) override;
::ndk::ScopedAStatus close(void) override; ::ndk::ScopedAStatus close(void) override;
private: private:
int fd; int fd;
unsigned int index; unsigned int index;

View file

@ -45,7 +45,8 @@ constexpr const char *FM_FREQ_SEEK = FM_SYSFS_BASE "/radio_freq_seek";
case GetType::GET_TYPE_FM_RMSSI: case GetType::GET_TYPE_FM_RMSSI:
NOT_SUPPORTED; NOT_SUPPORTED;
case GetType::GET_TYPE_FM_BEFORE_CHANNEL: case GetType::GET_TYPE_FM_BEFORE_CHANNEL:
if (index > 0) index -= 1; if (index > 0)
index -= 1;
if (kMiddleState != nullptr) { if (kMiddleState != nullptr) {
index = kMiddleState->first; index = kMiddleState->first;
delete kMiddleState; delete kMiddleState;
@ -55,7 +56,8 @@ constexpr const char *FM_FREQ_SEEK = FM_SYSFS_BASE "/radio_freq_seek";
*_aidl_return = freqs_list[index]; *_aidl_return = freqs_list[index];
break; break;
case GetType::GET_TYPE_FM_NEXT_CHANNEL: case GetType::GET_TYPE_FM_NEXT_CHANNEL:
if (index < freqs_list.size() - 1) index += 1; if (index < freqs_list.size() - 1)
index += 1;
if (kMiddleState != nullptr) { if (kMiddleState != nullptr) {
index = kMiddleState->second; index = kMiddleState->second;
delete kMiddleState; delete kMiddleState;
@ -88,7 +90,8 @@ constexpr const char *FM_FREQ_SEEK = FM_SYSFS_BASE "/radio_freq_seek";
switch (type) { switch (type) {
case SetType::SET_TYPE_FM_FREQ: case SetType::SET_TYPE_FM_FREQ:
FileIO::writeline(FM_FREQ_CTL, value); FileIO::writeline(FM_FREQ_CTL, value);
if (std::find(freqs_list.begin(), freqs_list.end(), value) == freqs_list.end()) if (std::find(freqs_list.begin(), freqs_list.end(), value) ==
freqs_list.end())
kMiddleState = saveMiddleState(value, freqs_list); kMiddleState = saveMiddleState(value, freqs_list);
break; break;
case SetType::SET_TYPE_FM_MUTE: case SetType::SET_TYPE_FM_MUTE:
@ -104,9 +107,12 @@ constexpr const char *FM_FREQ_SEEK = FM_SYSFS_BASE "/radio_freq_seek";
search_thread = new std::thread([this] { search_thread = new std::thread([this] {
const std::lock_guard<std::timed_mutex> guard(lock); const std::lock_guard<std::timed_mutex> guard(lock);
for (int i = 0; i < TRACK_SIZE; i++) { for (int i = 0; i < TRACK_SIZE; i++) {
FileIO::writeline(FM_FREQ_SEEK, "1 " + std::to_string(SYSFS_SPACING * 10)); FileIO::writeline(FM_FREQ_SEEK,
"1 " + std::to_string(SYSFS_SPACING * 10));
int freq = FileIO::readline(FM_FREQ_CTL); int freq = FileIO::readline(FM_FREQ_CTL);
if (std::find(freqs_list.begin(), freqs_list.end(), freq) != freqs_list.end()) continue; if (std::find(freqs_list.begin(), freqs_list.end(), freq) !=
freqs_list.end())
continue;
freqs_list.push_back(freq); freqs_list.push_back(freq);
} }
std::sort(freqs_list.begin(), freqs_list.end(), std::less<int>()); std::sort(freqs_list.begin(), freqs_list.end(), std::less<int>());
@ -115,7 +121,8 @@ constexpr const char *FM_FREQ_SEEK = FM_SYSFS_BASE "/radio_freq_seek";
default: default:
break; break;
}; };
if (type != SetType::SET_TYPE_FM_SEARCH_START) lock.unlock(); if (type != SetType::SET_TYPE_FM_SEARCH_START)
lock.unlock();
return ::ndk::ScopedAStatus::ok(); return ::ndk::ScopedAStatus::ok();
} }

View file

@ -16,23 +16,22 @@
#include <aidl/vendor/eureka/hardware/fmradio/BnFMDevControl.h> #include <aidl/vendor/eureka/hardware/fmradio/BnFMDevControl.h>
#include "MiddleState.h"
#include <mutex> #include <mutex>
#include <thread> #include <thread>
#include "MiddleState.h"
namespace aidl::vendor::eureka::hardware::fmradio { namespace aidl::vendor::eureka::hardware::fmradio {
struct FMSupport : public BnFMDevControl { struct FMSupport : public BnFMDevControl {
public: public:
FMSupport(void) { FMSupport(void) { index = 0; };
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;
::ndk::ScopedAStatus setValue(SetType type, int value) override; ::ndk::ScopedAStatus setValue(SetType type, int value) override;
::ndk::ScopedAStatus getFreqsList(std::vector<int> *_aidl_return) override; ::ndk::ScopedAStatus getFreqsList(std::vector<int> *_aidl_return) override;
::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::thread *search_thread;

View file

@ -1,13 +1,13 @@
#include "MiddleState.h" #include "MiddleState.h"
middlestate_t *saveMiddleState(const int value, const std::vector<int> &vec) middlestate_t *saveMiddleState(const int value, const std::vector<int> &vec) {
{
unsigned int i; unsigned int i;
// Bounds checking, we need at least 2 elements on the vector. // Bounds checking, we need at least 2 elements on the vector.
// If it doesn't meet the requirements, return nullptr to keep it // If it doesn't meet the requirements, return nullptr to keep it
// as-is. // as-is.
if (vec.size() <= 1) return nullptr; if (vec.size() <= 1)
return nullptr;
for (i = 0; i < vec.size() - 1; i++) { for (i = 0; i < vec.size() - 1; i++) {
const int first = vec[i] - value; const int first = vec[i] - value;

View file

@ -16,13 +16,14 @@
#include <android/binder_manager.h> #include <android/binder_manager.h>
#include <android/binder_process.h> #include <android/binder_process.h>
#include "FMSupport.h"
#include "FMDevControl.h" #include "FMDevControl.h"
#include "FMSupport.h"
using ::aidl::vendor::eureka::hardware::fmradio::FMDevControl; using ::aidl::vendor::eureka::hardware::fmradio::FMDevControl;
using ::aidl::vendor::eureka::hardware::fmradio::FMSupport; using ::aidl::vendor::eureka::hardware::fmradio::FMSupport;
template <class C> static void registerAsService(std::shared_ptr<C> service, const char *inst) { template <class C>
static void registerAsService(std::shared_ptr<C> service, const char *inst) {
const std::string instance = std::string() + C::descriptor + "/" + inst; const std::string instance = std::string() + C::descriptor + "/" + inst;
binder_status_t status = binder_status_t status =
AServiceManager_addService(service->asBinder().get(), instance.c_str()); AServiceManager_addService(service->asBinder().get(), instance.c_str());