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. PR #5270 <https://github.com/Genymobile/scrcpy/pull/5270>
This commit is contained in:
parent
222916eebe
commit
1f5be743b4
@ -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
|
||||||
|
@ -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;
|
||||||
|
@ -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"
|
||||||
@ -252,7 +253,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);
|
||||||
}
|
}
|
||||||
@ -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->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);
|
||||||
@ -365,6 +368,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;
|
||||||
|
@ -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);
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
@ -32,6 +32,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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user