Do not fallback keyboard mode if AOA fails

Initially, if AOA initialization failed, default injection method was
used, in order to use the same command/shortcut when the device is
connected via USB or via TCP/IP, without changing the arguments.

Now that there are 3 keyboard modes, it seems unexpected to switch to
another specific mode if AOA fails (and it is inconsistent). If the user
explicitly requests AOA, then use AOA or fail.

Refs #2632 comment <https://github.com/Genymobile/scrcpy/pull/2632#issuecomment-945190859>
PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
This commit is contained in:
Romain Vimont 2024-02-28 22:46:48 +01:00
parent 1c5ad0e813
commit 5f12132c47
1 changed files with 5 additions and 29 deletions

View File

@ -570,7 +570,7 @@ scrcpy(struct scrcpy_options *options) {
if (!ok) { if (!ok) {
LOGE("Failed to initialize USB"); LOGE("Failed to initialize USB");
sc_acksync_destroy(&s->acksync); sc_acksync_destroy(&s->acksync);
goto aoa_hid_end; goto end;
} }
assert(serial); assert(serial);
@ -578,7 +578,7 @@ scrcpy(struct scrcpy_options *options) {
ok = sc_usb_select_device(&s->usb, serial, &usb_device); ok = sc_usb_select_device(&s->usb, serial, &usb_device);
if (!ok) { if (!ok) {
sc_usb_destroy(&s->usb); sc_usb_destroy(&s->usb);
goto aoa_hid_end; goto end;
} }
LOGI("USB device: %s (%04" PRIx16 ":%04" PRIx16 ") %s %s", LOGI("USB device: %s (%04" PRIx16 ":%04" PRIx16 ") %s %s",
@ -591,7 +591,7 @@ scrcpy(struct scrcpy_options *options) {
LOGE("Failed to connect to USB device %s", serial); LOGE("Failed to connect to USB device %s", serial);
sc_usb_destroy(&s->usb); sc_usb_destroy(&s->usb);
sc_acksync_destroy(&s->acksync); sc_acksync_destroy(&s->acksync);
goto aoa_hid_end; goto end;
} }
ok = sc_aoa_init(&s->aoa, &s->usb, &s->acksync); ok = sc_aoa_init(&s->aoa, &s->usb, &s->acksync);
@ -600,7 +600,7 @@ scrcpy(struct scrcpy_options *options) {
sc_usb_disconnect(&s->usb); sc_usb_disconnect(&s->usb);
sc_usb_destroy(&s->usb); sc_usb_destroy(&s->usb);
sc_acksync_destroy(&s->acksync); sc_acksync_destroy(&s->acksync);
goto aoa_hid_end; goto end;
} }
if (use_keyboard_aoa) { if (use_keyboard_aoa) {
@ -628,41 +628,18 @@ scrcpy(struct scrcpy_options *options) {
sc_usb_disconnect(&s->usb); sc_usb_disconnect(&s->usb);
sc_usb_destroy(&s->usb); sc_usb_destroy(&s->usb);
sc_aoa_destroy(&s->aoa); sc_aoa_destroy(&s->aoa);
goto aoa_hid_end; goto end;
} }
acksync = &s->acksync; acksync = &s->acksync;
aoa_hid_initialized = true; aoa_hid_initialized = true;
aoa_hid_end:
if (!aoa_hid_initialized) {
if (keyboard_aoa_initialized) {
sc_keyboard_aoa_destroy(&s->keyboard_aoa);
keyboard_aoa_initialized = false;
}
if (mouse_aoa_initialized) {
sc_mouse_aoa_destroy(&s->mouse_aoa);
mouse_aoa_initialized = false;
}
}
if (use_keyboard_aoa && !keyboard_aoa_initialized) {
LOGE("Fallback to --keyboard=sdk (--keyboard=aoa ignored)");
options->keyboard_input_mode = SC_KEYBOARD_INPUT_MODE_SDK;
}
if (use_mouse_aoa && !mouse_aoa_initialized) {
LOGE("Fallback to --keyboard=sdk (--keyboard=aoa ignored)");
options->mouse_input_mode = SC_MOUSE_INPUT_MODE_SDK;
}
} }
#else #else
assert(options->keyboard_input_mode != SC_KEYBOARD_INPUT_MODE_AOA); assert(options->keyboard_input_mode != SC_KEYBOARD_INPUT_MODE_AOA);
assert(options->mouse_input_mode != SC_MOUSE_INPUT_MODE_AOA); assert(options->mouse_input_mode != SC_MOUSE_INPUT_MODE_AOA);
#endif #endif
// keyboard_input_mode may have been reset if AOA mode failed
if (options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_SDK) { if (options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_SDK) {
sc_keyboard_sdk_init(&s->keyboard_sdk, &s->controller, sc_keyboard_sdk_init(&s->keyboard_sdk, &s->controller,
options->key_inject_mode, options->key_inject_mode,
@ -680,7 +657,6 @@ aoa_hid_end:
kp = &s->keyboard_uhid.key_processor; kp = &s->keyboard_uhid.key_processor;
} }
// mouse_input_mode may have been reset if AOA mode failed
if (options->mouse_input_mode == SC_MOUSE_INPUT_MODE_SDK) { if (options->mouse_input_mode == SC_MOUSE_INPUT_MODE_SDK) {
sc_mouse_sdk_init(&s->mouse_sdk, &s->controller); sc_mouse_sdk_init(&s->mouse_sdk, &s->controller);
mp = &s->mouse_sdk.mouse_processor; mp = &s->mouse_sdk.mouse_processor;