universal7885: fm-aidl: Fixups

- libfileio: Move back to liblog.
- FMDevCtrl: Add some loggings
- FM-app: Call open() before set(apppid)
This commit is contained in:
roynatech2544 2022-11-01 12:13:31 +09:00
commit 5c7c906519
4 changed files with 26 additions and 12 deletions

View file

@ -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
/**

View file

@ -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 <fm_slsi-impl.h>
#include <LogFormat.h>
#include <android/binder_manager.h>
#include <log/log.h>
#include <cassert>
#include <cerrno>
@ -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<IAudioRoute> 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<IAudioRoute> 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();
}

View file

@ -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"],
}

View file

@ -1,4 +1,6 @@
#include <android-base/logging.h>
#define LOG_TAG "libFileIO"
#include <log/log.h>
#include <fstream>
#include <string>
@ -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) {