qahw: test: Handle power suspend scenario
Test app is entering to suspend state while playback
is running in power suspend scenario.Avoid this by
acquiring wakelock in write_to_hal api.
Change-Id: Id7632de2786d839daba0384b167c61b580ad37b5
diff --git a/qahw_api/test/qahw_multi_record_test.c b/qahw_api/test/qahw_multi_record_test.c
index c9f8b03..8044f77 100644
--- a/qahw_api/test/qahw_multi_record_test.c
+++ b/qahw_api/test/qahw_multi_record_test.c
@@ -89,6 +89,40 @@
static pthread_mutex_t sourcetrack_lock;
struct qahw_sound_focus_param sound_focus_data;
+static bool request_wake_lock(bool wakelock_acquired, bool enable)
+{
+ int system_ret;
+
+ if (enable) {
+ if (!wakelock_acquired) {
+ system_ret = system("echo audio_services > /sys/power/wake_lock");
+ if (system_ret < 0) {
+ fprintf(stderr, "%s.Failed to acquire audio_service lock\n", __func__);
+ fprintf(log_file, "%s.Failed to acquire audio_service lock\n", __func__);
+ } else {
+ wakelock_acquired = true;
+ fprintf(log_file, "%s.Success to acquire audio_service lock\n", __func__);
+ }
+ } else
+ fprintf(log_file, "%s.Lock is already acquired\n", __func__);
+ }
+
+ if (!enable) {
+ if (wakelock_acquired) {
+ system_ret = system("echo audio_services > /sys/power/wake_unlock");
+ if (system_ret < 0) {
+ fprintf(stderr, "%s.Failed to release audio_service lock\n", __func__);
+ fprintf(log_file, "%s.Failed to release audio_service lock\n", __func__);
+ } else {
+ wakelock_acquired = false;
+ fprintf(log_file, "%s.Success to release audio_service lock\n", __func__);
+ }
+ } else
+ fprintf(log_file, "%s.No Lock is acquired to release\n", __func__);
+ }
+ return wakelock_acquired;
+}
+
void stop_signal_handler(int signal __unused)
{
stop_record = true;
@@ -547,6 +581,7 @@
bool interactive_mode = false, source_tracking = false;
struct listnode param_list;
char log_filename[256] = "stdout";
+ bool wakelock_acquired = false;
log_file = stdout;
list_init(¶m_list);
@@ -624,6 +659,7 @@
}
}
+ wakelock_acquired = request_wake_lock(wakelock_acquired, true);
qahw_mod_handle = qahw_load_module(mod_name);
if(qahw_mod_handle == NULL) {
fprintf(log_file, " qahw_load_module failed");
@@ -862,5 +898,6 @@
fprintf(stdout, "\n Done with hal record test \n");
fclose(log_file);
}
+ wakelock_acquired = request_wake_lock(wakelock_acquired, false);
return 0;
}
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index 1f65368..e0a744d 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -237,6 +237,40 @@
"music_offload_wma_encode_option2=%d;" \
"music_offload_wma_format_tag=%d;"
+static bool request_wake_lock(bool wakelock_acquired, bool enable)
+{
+ int system_ret;
+
+ if (enable) {
+ if (!wakelock_acquired) {
+ system_ret = system("echo audio_services > /sys/power/wake_lock");
+ if (system_ret < 0) {
+ fprintf(stderr, "%s.Failed to acquire audio_service lock\n", __func__);
+ fprintf(log_file, "%s.Failed to acquire audio_service lock\n", __func__);
+ } else {
+ wakelock_acquired = true;
+ fprintf(log_file, "%s.Success to acquire audio_service lock\n", __func__);
+ }
+ } else
+ fprintf(log_file, "%s.Lock is already acquired\n", __func__);
+ }
+
+ if (!enable) {
+ if (wakelock_acquired) {
+ system_ret = system("echo audio_services > /sys/power/wake_unlock");
+ if (system_ret < 0) {
+ fprintf(stderr, "%s.Failed to release audio_service lock\n", __func__);
+ fprintf(log_file, "%s.Failed to release audio_service lock\n", __func__);
+ } else {
+ wakelock_acquired = false;
+ fprintf(log_file, "%s.Success to release audio_service lock\n", __func__);
+ }
+ } else
+ fprintf(log_file, "%s.No Lock is acquired to release\n", __func__);
+ }
+ return wakelock_acquired;
+}
+
void stop_signal_handler(int signal __unused)
{
stop_playback = true;
@@ -1574,6 +1608,7 @@
int j = 0;
kpi_mode = false;
event_trigger = false;
+ bool wakelock_acquired = false;
log_file = stdout;
proxy_params.acp.file_name = "/data/pcm_dump.wav";
@@ -1739,6 +1774,7 @@
}
}
+ wakelock_acquired = request_wake_lock(wakelock_acquired, true);
num_of_streams = i+1;
fprintf(log_file, "Starting audio hal tests for streams : %d\n", num_of_streams);
@@ -1913,6 +1949,7 @@
if ((log_file != stdout) && (log_file != nullptr))
fclose(log_file);
+ wakelock_acquired = request_wake_lock(wakelock_acquired, false);
fprintf(log_file, "\nBYE BYE\n");
return 0;
}