Make AOA keyboard/mouse open error fatal

Now that the AOA open/close are asynchronous, an open error did not make
scrcpy exit anymore.

Add a mechanism to exit if the AOA device could not be opened
asynchronously.
This commit is contained in:
Romain Vimont 2024-09-06 23:08:08 +02:00
parent 44e29989ee
commit 6f1d79ba17
7 changed files with 20 additions and 4 deletions

View File

@ -19,6 +19,7 @@ enum {
SC_EVENT_SCREEN_INIT_SIZE, SC_EVENT_SCREEN_INIT_SIZE,
SC_EVENT_TIME_LIMIT_REACHED, SC_EVENT_TIME_LIMIT_REACHED,
SC_EVENT_CONTROLLER_ERROR, SC_EVENT_CONTROLLER_ERROR,
SC_EVENT_AOA_OPEN_ERROR,
}; };
bool bool

View File

@ -168,6 +168,9 @@ event_loop(struct scrcpy *s) {
case SC_EVENT_RECORDER_ERROR: case SC_EVENT_RECORDER_ERROR:
LOGE("Recorder error"); LOGE("Recorder error");
return SCRCPY_EXIT_FAILURE; return SCRCPY_EXIT_FAILURE;
case SC_EVENT_AOA_OPEN_ERROR:
LOGE("AOA open error");
return SCRCPY_EXIT_FAILURE;
case SC_EVENT_TIME_LIMIT_REACHED: case SC_EVENT_TIME_LIMIT_REACHED:
LOGI("Time limit reached"); LOGI("Time limit reached");
return SCRCPY_EXIT_SUCCESS; return SCRCPY_EXIT_SUCCESS;

View File

@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include "aoa_hid.h" #include "aoa_hid.h"
#include "events.h"
#include "util/log.h" #include "util/log.h"
#include "util/str.h" #include "util/str.h"
#include "util/vector.h" #include "util/vector.h"
@ -248,7 +249,8 @@ sc_aoa_push_input_with_ack_to_wait(struct sc_aoa *aoa,
} }
bool 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) { if (sc_get_log_level() <= SC_LOG_LEVEL_VERBOSE) {
sc_hid_open_log(hid_open); sc_hid_open_log(hid_open);
} }
@ -267,6 +269,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->type = SC_AOA_EVENT_TYPE_OPEN;
aoa_event->open.hid = *hid_open; aoa_event->open.hid = *hid_open;
aoa_event->open.exit_on_error = exit_on_open_error;
if (was_empty) { if (was_empty) {
sc_cond_signal(&aoa->event_cond); sc_cond_signal(&aoa->event_cond);
@ -361,6 +364,10 @@ sc_aoa_process_event(struct sc_aoa *aoa, struct sc_aoa_event *event,
} }
} else { } else {
LOGW("Could not open AOA device: %" PRIu16, hid_open->hid_id); 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; break;

View File

@ -24,6 +24,7 @@ struct sc_aoa_event {
union { union {
struct { struct {
struct sc_hid_open hid; struct sc_hid_open hid;
bool exit_on_error;
} open; } open;
struct { struct {
struct sc_hid_close hid; 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 // report_desc must be a pointer to static memory, accessed at any time from
// another thread // another thread
bool 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);
bool bool
sc_aoa_push_close(struct sc_aoa *aoa, const struct sc_hid_close *hid_close); sc_aoa_push_close(struct sc_aoa *aoa, const struct sc_hid_close *hid_close);

View File

@ -69,7 +69,7 @@ sc_keyboard_aoa_init(struct sc_keyboard_aoa *kb, struct sc_aoa *aoa) {
struct sc_hid_open hid_open; struct sc_hid_open hid_open;
sc_hid_keyboard_generate_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) { if (!ok) {
LOGW("Could not push AOA HID open (keyboard)"); LOGW("Could not push AOA HID open (keyboard)");
return false; return false;

View File

@ -55,7 +55,7 @@ sc_mouse_aoa_init(struct sc_mouse_aoa *mouse, struct sc_aoa *aoa) {
struct sc_hid_open hid_open; struct sc_hid_open hid_open;
sc_hid_mouse_generate_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) { if (!ok) {
LOGW("Could not push AOA HID open (mouse)"); LOGW("Could not push AOA HID open (mouse)");
return false; return false;

View File

@ -35,6 +35,9 @@ event_loop(struct scrcpy_otg *s) {
case SC_EVENT_USB_DEVICE_DISCONNECTED: case SC_EVENT_USB_DEVICE_DISCONNECTED:
LOGW("Device disconnected"); LOGW("Device disconnected");
return SCRCPY_EXIT_DISCONNECTED; return SCRCPY_EXIT_DISCONNECTED;
case SC_EVENT_AOA_OPEN_ERROR:
LOGE("AOA open error");
return SCRCPY_EXIT_FAILURE;
case SDL_QUIT: case SDL_QUIT:
LOGD("User requested to quit"); LOGD("User requested to quit");
return SCRCPY_EXIT_SUCCESS; return SCRCPY_EXIT_SUCCESS;