Kill adb daemon in OTG mode on Windows

On Windows, it is not possible to open a USB device from several
process, so HID events may only work if no adb daemon is running.

PR #3011 <https://github.com/Genymobile/scrcpy/pull/3011>
This commit is contained in:
Romain Vimont 2022-02-10 08:42:15 +01:00
parent 3bb24b3926
commit 25296ae167
3 changed files with 21 additions and 0 deletions

View file

@ -204,6 +204,14 @@ sc_adb_start_server(struct sc_intr *intr, unsigned flags) {
return process_check_success_intr(intr, pid, "adb start-server", flags); return process_check_success_intr(intr, pid, "adb start-server", flags);
} }
bool
sc_adb_kill_server(struct sc_intr *intr, unsigned flags) {
const char *const argv[] = SC_ADB_COMMAND("kill-server");
sc_pid pid = sc_adb_execute(argv, flags);
return process_check_success_intr(intr, pid, "adb kill-server", flags);
}
bool bool
sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port, sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
const char *device_socket_name, unsigned flags) { const char *device_socket_name, unsigned flags) {

View file

@ -36,6 +36,9 @@ sc_adb_execute(const char *const argv[], unsigned flags);
bool bool
sc_adb_start_server(struct sc_intr *intr, unsigned flags); sc_adb_start_server(struct sc_intr *intr, unsigned flags);
bool
sc_adb_kill_server(struct sc_intr *intr, unsigned flags);
bool bool
sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port, sc_adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
const char *device_socket_name, unsigned flags); const char *device_socket_name, unsigned flags);

View file

@ -2,6 +2,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "adb/adb.h"
#include "events.h" #include "events.h"
#include "screen_otg.h" #include "screen_otg.h"
#include "util/log.h" #include "util/log.h"
@ -75,6 +76,15 @@ scrcpy_otg(struct scrcpy_options *options) {
bool aoa_started = false; bool aoa_started = false;
bool aoa_initialized = false; bool aoa_initialized = false;
#ifdef _WIN32
// On Windows, only one process could open a USB device
// <https://github.com/Genymobile/scrcpy/issues/2773>
LOGI("Killing adb daemon (if any)...");
unsigned flags = SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR;
// uninterruptible (intr == NULL), but in practice it's very quick
sc_adb_kill_server(NULL, flags);
#endif
static const struct sc_usb_callbacks cbs = { static const struct sc_usb_callbacks cbs = {
.on_disconnected = sc_usb_on_disconnected, .on_disconnected = sc_usb_on_disconnected,
}; };