Display and control your Android device
Make AOA keyboard/mouse open error fatal
Romain Vimont1f5be743b474
diff --git a/app/src/events.h b/app/src/events.hindex 3f15087a..59c55de4 100644--- a/app/src/events.h+++ b/app/src/events.h@@ -19,6 +19,7 @@ enum {SC_EVENT_SCREEN_INIT_SIZE,SC_EVENT_TIME_LIMIT_REACHED,SC_EVENT_CONTROLLER_ERROR,+ SC_EVENT_AOA_OPEN_ERROR,};booldiff --git a/app/src/scrcpy.c b/app/src/scrcpy.cindex 529a3fc2..8e8fe86e 100644--- a/app/src/scrcpy.c+++ b/app/src/scrcpy.c@@ -168,6 +168,9 @@ event_loop(struct scrcpy *s) {case SC_EVENT_RECORDER_ERROR:LOGE("Recorder error");return SCRCPY_EXIT_FAILURE;+ case SC_EVENT_AOA_OPEN_ERROR:+ LOGE("AOA open error");+ return SCRCPY_EXIT_FAILURE;case SC_EVENT_TIME_LIMIT_REACHED:LOGI("Time limit reached");return SCRCPY_EXIT_SUCCESS;diff --git a/app/src/usb/aoa_hid.c b/app/src/usb/aoa_hid.cindex 59c8304b..236a78ed 100644--- a/app/src/usb/aoa_hid.c+++ b/app/src/usb/aoa_hid.c@@ -5,6 +5,7 @@#include <stdio.h>#include "aoa_hid.h"+#include "events.h"#include "util/log.h"#include "util/str.h"#include "util/vector.h"@@ -252,7 +253,8 @@ sc_aoa_push_input_with_ack_to_wait(struct sc_aoa *aoa,}bool-sc_aoa_push_open(struct sc_aoa *aoa, const struct sc_hid_open *hid_open) {+sc_aoa_push_open(struct sc_aoa *aoa, const struct sc_hid_open *hid_open,+ bool exit_on_open_error) {if (sc_get_log_level() <= SC_LOG_LEVEL_VERBOSE) {sc_hid_open_log(hid_open);}@@ -271,6 +273,7 @@ sc_aoa_push_open(struct sc_aoa *aoa, const struct sc_hid_open *hid_open) {aoa_event->type = SC_AOA_EVENT_TYPE_OPEN;aoa_event->open.hid = *hid_open;+ aoa_event->open.exit_on_error = exit_on_open_error;if (was_empty) {sc_cond_signal(&aoa->event_cond);@@ -365,6 +368,10 @@ sc_aoa_process_event(struct sc_aoa *aoa, struct sc_aoa_event *event,}} else {LOGW("Could not open AOA device: %" PRIu16, hid_open->hid_id);+ if (event->open.exit_on_error) {+ // Notify the error to the main thread, which will exit+ sc_push_event(SC_EVENT_AOA_OPEN_ERROR);+ }}break;diff --git a/app/src/usb/aoa_hid.h b/app/src/usb/aoa_hid.hindex 010b3742..00961c28 100644--- a/app/src/usb/aoa_hid.h+++ b/app/src/usb/aoa_hid.h@@ -24,6 +24,7 @@ struct sc_aoa_event {union {struct {struct sc_hid_open hid;+ bool exit_on_error;} open;struct {struct sc_hid_close hid;@@ -73,7 +74,8 @@ sc_aoa_join(struct sc_aoa *aoa);// report_desc must be a pointer to static memory, accessed at any time from// another threadbool-sc_aoa_push_open(struct sc_aoa *aoa, const struct sc_hid_open *hid_open);+sc_aoa_push_open(struct sc_aoa *aoa, const struct sc_hid_open *hid_open,+ bool exit_on_open_error);boolsc_aoa_push_close(struct sc_aoa *aoa, const struct sc_hid_close *hid_close);diff --git a/app/src/usb/keyboard_aoa.c b/app/src/usb/keyboard_aoa.cindex b7834b0f..8f5cb755 100644--- a/app/src/usb/keyboard_aoa.c+++ b/app/src/usb/keyboard_aoa.c@@ -69,7 +69,7 @@ sc_keyboard_aoa_init(struct sc_keyboard_aoa *kb, struct sc_aoa *aoa) {struct sc_hid_open hid_open;sc_hid_keyboard_generate_open(&hid_open);- bool ok = sc_aoa_push_open(aoa, &hid_open);+ bool ok = sc_aoa_push_open(aoa, &hid_open, true);if (!ok) {LOGW("Could not push AOA HID open (keyboard)");return false;diff --git a/app/src/usb/mouse_aoa.c b/app/src/usb/mouse_aoa.cindex 33b777c4..cb566cc0 100644--- a/app/src/usb/mouse_aoa.c+++ b/app/src/usb/mouse_aoa.c@@ -55,7 +55,7 @@ sc_mouse_aoa_init(struct sc_mouse_aoa *mouse, struct sc_aoa *aoa) {struct sc_hid_open hid_open;sc_hid_mouse_generate_open(&hid_open);- bool ok = sc_aoa_push_open(aoa, &hid_open);+ bool ok = sc_aoa_push_open(aoa, &hid_open, true);if (!ok) {LOGW("Could not push AOA HID open (mouse)");return false;diff --git a/app/src/usb/scrcpy_otg.c b/app/src/usb/scrcpy_otg.cindex 715f690a..71d1863f 100644--- a/app/src/usb/scrcpy_otg.c+++ b/app/src/usb/scrcpy_otg.c@@ -32,6 +32,9 @@ event_loop(struct scrcpy_otg *s) {case SC_EVENT_USB_DEVICE_DISCONNECTED:LOGW("Device disconnected");return SCRCPY_EXIT_DISCONNECTED;+ case SC_EVENT_AOA_OPEN_ERROR:+ LOGE("AOA open error");+ return SCRCPY_EXIT_FAILURE;case SDL_QUIT:LOGD("User requested to quit");return SCRCPY_EXIT_SUCCESS;