From 5c7c9065198bae7fcc8f9bf146c503e52a478278 Mon Sep 17 00:00:00 2001 From: roynatech2544 Date: Tue, 1 Nov 2022 12:13:31 +0900 Subject: [PATCH] universal7885: fm-aidl: Fixups - libfileio: Move back to liblog. - FMDevCtrl: Add some loggings - FM-app: Call open() before set(apppid) --- .../src/com/eurekateam/fmradio/MainActivity.kt | 2 +- .../aidl-support/fm/default/FMDevControl.cpp | 18 +++++++++++++++--- .../apps/aidl-support/libfileio/Android.bp | 2 +- .../apps/aidl-support/libfileio/FileIO.cpp | 16 +++++++++------- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/universal7885-common/apps/FMRadio/src/com/eurekateam/fmradio/MainActivity.kt b/universal7885-common/apps/FMRadio/src/com/eurekateam/fmradio/MainActivity.kt index 8ced06a..cb3c53e 100644 --- a/universal7885-common/apps/FMRadio/src/com/eurekateam/fmradio/MainActivity.kt +++ b/universal7885-common/apps/FMRadio/src/com/eurekateam/fmradio/MainActivity.kt @@ -57,8 +57,8 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_navigation) DynamicColors.applyToActivitiesIfAvailable(application) - mFMInterface.mDevCtl.setValue(SetType.SET_TYPE_FM_APP_PID, Process.myPid()) mFMInterface.mDevCtl.open() + mFMInterface.mDevCtl.setValue(SetType.SET_TYPE_FM_APP_PID, Process.myPid()) mAudioManager = getSystemService(AUDIO_SERVICE) as AudioManager /** diff --git a/universal7885-common/apps/aidl-support/fm/default/FMDevControl.cpp b/universal7885-common/apps/aidl-support/fm/default/FMDevControl.cpp index fb3733b..daa0c75 100644 --- a/universal7885-common/apps/aidl-support/fm/default/FMDevControl.cpp +++ b/universal7885-common/apps/aidl-support/fm/default/FMDevControl.cpp @@ -12,11 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +#define LOG_TAG "FMHAL-DevControl" + #include "FMDevControl.h" #include +#include #include +#include #include #include @@ -39,6 +43,7 @@ namespace aidl::vendor::eureka::hardware::fmradio { } ::ndk::ScopedAStatus FMDevControl::getValue(GetType type, int *_aidl_return) { + ALOGD(make_str("%s: type %d", __func__, type)); if (type != GetType::GET_TYPE_FM_MUTEX_LOCKED) { RETURN_IF_FAILED_LOCK; } @@ -92,12 +97,16 @@ namespace aidl::vendor::eureka::hardware::fmradio { if (type != GetType::GET_TYPE_FM_MUTEX_LOCKED) { lock.unlock(); } + ALOGD(make_str("%s: returning %d", __func__, *_aidl_return)); + return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus FMDevControl::setValue(SetType type, int value) { using audio_route::IAudioRoute; + ALOGD(make_str("%s: type %d, value %d", __func__, type, value)); + RETURN_IF_FAILED_LOCK; assert(fd > 0); switch (type) { @@ -122,7 +131,7 @@ namespace aidl::vendor::eureka::hardware::fmradio { fm_radio_slsi::stop_search(fd); break; case SetType::SET_TYPE_FM_SPEAKER_ROUTE: - std::shared_ptr 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"); break; case SetType::SET_TYPE_FM_SEARCH_START: @@ -135,16 +144,19 @@ namespace aidl::vendor::eureka::hardware::fmradio { break; case SetType::SET_TYPE_FM_APP_PID: client_observe_thread = std::thread([=] { - std::shared_ptr svc; pid_t pid = value; + ALOGD(make_str("%s: FM_APP_PID: recieved value %d", __func__, pid)); + while (true) { if (kill(pid, 0) < 0 && errno == ESRCH) break; std::this_thread::sleep_for(std::chrono::seconds(2)); } + ALOGW(make_str("%s: FM_APP_PID: Starting client death receiver", __func__)); + fm_radio_slsi::fm_thread_set(fd, 0); - 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("l_fmradio_mode=off"); close(); } diff --git a/universal7885-common/apps/aidl-support/libfileio/Android.bp b/universal7885-common/apps/aidl-support/libfileio/Android.bp index a86a4d9..5a2be10 100644 --- a/universal7885-common/apps/aidl-support/libfileio/Android.bp +++ b/universal7885-common/apps/aidl-support/libfileio/Android.bp @@ -4,7 +4,7 @@ cc_library_shared { cppflags: ["-fexceptions"], local_include_dirs: ["include"], export_include_dirs: ["include"], - shared_libs: ["libbase"], + shared_libs: ["liblog"], header_libs: ["logformat"], } diff --git a/universal7885-common/apps/aidl-support/libfileio/FileIO.cpp b/universal7885-common/apps/aidl-support/libfileio/FileIO.cpp index ee23950..c40a081 100644 --- a/universal7885-common/apps/aidl-support/libfileio/FileIO.cpp +++ b/universal7885-common/apps/aidl-support/libfileio/FileIO.cpp @@ -1,4 +1,6 @@ -#include +#define LOG_TAG "libFileIO" + +#include #include #include @@ -13,20 +15,20 @@ int readline(const char *path) { std::ifstream file; std::string value; file.open(path); - LOG(DEBUG) << make_str("%s: Opening %s", __func__, path); + ALOGD(make_str("%s: Opening %s", __func__, path)); if (file.is_open()) { getline(file, value); file.close(); } else { - LOG(ERROR) << make_str("%s: Failed to open %s", __func__, path); + ALOGE(make_str("%s: Failed to open %s", __func__, path)); return EXIT_ERR; } try { return stoi(value); } catch (std::invalid_argument const &ex) { - LOG(ERROR) << make_str("%s: stoi(): invalid argument: for %s", __func__, value.c_str()); + ALOGE(make_str("%s: stoi(): invalid argument: for %s", __func__, value.c_str())); } catch (std::out_of_range const &ex) { - LOG(ERROR) << make_str("%s: stoi(): out of range: for %s", __func__, value.c_str()); + ALOGE(make_str("%s: stoi(): out of range: for %s", __func__, value.c_str())); } return EXIT_ERR; } @@ -34,13 +36,13 @@ int readline(const char *path) { void writeline(const char *path, const std::string& data) { std::ofstream file; file.open(path); - LOG(DEBUG) << make_str("%s: Opening %s, will write '%s'", __func__, path, data.c_str()); + ALOGD(make_str("%s: Opening %s, will write '%s'", __func__, path, data.c_str())); if (file.is_open()) { file << data; file.close(); return; } - LOG(ERROR) << make_str("%s: Failed to open %s", __func__, path); + ALOGE(make_str("%s: Failed to open %s", __func__, path)); } void writeline(const char *path, const int data) {