mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 14:49:29 +00:00
Dynamically allocated ADB devices
* This fixes connection to farm servers with many more than 16 devices
This commit is contained in:
parent
85edba20e7
commit
96238bbe0a
3 changed files with 17 additions and 4 deletions
|
@ -519,9 +519,7 @@ bool
|
||||||
sc_adb_select_device(struct sc_intr *intr,
|
sc_adb_select_device(struct sc_intr *intr,
|
||||||
const struct sc_adb_device_selector *selector,
|
const struct sc_adb_device_selector *selector,
|
||||||
unsigned flags, struct sc_adb_device *out_device) {
|
unsigned flags, struct sc_adb_device *out_device) {
|
||||||
struct sc_adb_device devices[16];
|
ssize_t count = sc_adb_list_devices(intr, flags, NULL, 4096);
|
||||||
ssize_t count =
|
|
||||||
sc_adb_list_devices(intr, flags, devices, ARRAY_LEN(devices));
|
|
||||||
if (count == -1) {
|
if (count == -1) {
|
||||||
LOGE("Could not list ADB devices");
|
LOGE("Could not list ADB devices");
|
||||||
return false;
|
return false;
|
||||||
|
@ -532,6 +530,14 @@ sc_adb_select_device(struct sc_intr *intr,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct sc_adb_device *devices = malloc(sizeof(struct sc_adb_device) * count);
|
||||||
|
ssize_t parseCount = sc_adb_list_devices(intr, flags, devices, count);
|
||||||
|
if (parseCount != count) {
|
||||||
|
LOGE("Missmatch in second parsing");
|
||||||
|
free(devices);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
size_t sel_idx; // index of the single matching device if sel_count == 1
|
size_t sel_idx; // index of the single matching device if sel_count == 1
|
||||||
size_t sel_count =
|
size_t sel_count =
|
||||||
sc_adb_devices_select(devices, count, selector, &sel_idx);
|
sc_adb_devices_select(devices, count, selector, &sel_idx);
|
||||||
|
@ -559,6 +565,7 @@ sc_adb_select_device(struct sc_intr *intr,
|
||||||
|
|
||||||
sc_adb_devices_log(SC_LOG_LEVEL_ERROR, devices, count);
|
sc_adb_devices_log(SC_LOG_LEVEL_ERROR, devices, count);
|
||||||
sc_adb_devices_destroy_all(devices, count);
|
sc_adb_devices_destroy_all(devices, count);
|
||||||
|
free(devices);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,6 +595,7 @@ sc_adb_select_device(struct sc_intr *intr,
|
||||||
LOGE("Select a device via -s (--serial), -d (--select-usb) or -e "
|
LOGE("Select a device via -s (--serial), -d (--select-usb) or -e "
|
||||||
"(--select-tcpip)");
|
"(--select-tcpip)");
|
||||||
sc_adb_devices_destroy_all(devices, count);
|
sc_adb_devices_destroy_all(devices, count);
|
||||||
|
free(devices);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,6 +605,7 @@ sc_adb_select_device(struct sc_intr *intr,
|
||||||
bool ok = sc_adb_device_check_state(device, devices, count);
|
bool ok = sc_adb_device_check_state(device, devices, count);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
sc_adb_devices_destroy_all(devices, count);
|
sc_adb_devices_destroy_all(devices, count);
|
||||||
|
free(devices);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -606,6 +615,7 @@ sc_adb_select_device(struct sc_intr *intr,
|
||||||
// Move devics into out_device (do not destroy device)
|
// Move devics into out_device (do not destroy device)
|
||||||
sc_adb_device_move(out_device, device);
|
sc_adb_device_move(out_device, device);
|
||||||
sc_adb_devices_destroy_all(devices, count);
|
sc_adb_devices_destroy_all(devices, count);
|
||||||
|
free(devices);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,7 @@ ssize_t
|
||||||
sc_adb_parse_devices(char *str, struct sc_adb_device *devices,
|
sc_adb_parse_devices(char *str, struct sc_adb_device *devices,
|
||||||
size_t devices_len) {
|
size_t devices_len) {
|
||||||
size_t dev_count = 0;
|
size_t dev_count = 0;
|
||||||
|
struct sc_adb_device scratch_device;
|
||||||
|
|
||||||
#define HEADER "List of devices attached"
|
#define HEADER "List of devices attached"
|
||||||
#define HEADER_LEN (sizeof(HEADER) - 1)
|
#define HEADER_LEN (sizeof(HEADER) - 1)
|
||||||
|
@ -144,7 +145,7 @@ sc_adb_parse_devices(char *str, struct sc_adb_device *devices,
|
||||||
size_t line_len = sc_str_remove_trailing_cr(line, len);
|
size_t line_len = sc_str_remove_trailing_cr(line, len);
|
||||||
line[line_len] = '\0';
|
line[line_len] = '\0';
|
||||||
|
|
||||||
bool ok = sc_adb_parse_device(line, &devices[dev_count]);
|
bool ok = sc_adb_parse_device(line, devices ? &devices[dev_count] : &scratch_device);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
* Parse the available devices from the output of `adb devices`
|
* Parse the available devices from the output of `adb devices`
|
||||||
*
|
*
|
||||||
* The parameter must be a NUL-terminated string.
|
* The parameter must be a NUL-terminated string.
|
||||||
|
* If a devices is a nullptr it will parse and report the caller
|
||||||
|
* the amount of devices in ADB.
|
||||||
*
|
*
|
||||||
* Warning: this function modifies the buffer for optimization purposes.
|
* Warning: this function modifies the buffer for optimization purposes.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue