Add option to kill adb on close
Killing adb on close by default would be incorrect, since it would break any other usage of adb in parallel. It could be easily done manually by calling "adb kill-server" once scrcpy terminates, but add an option --kill-adb-on-close for convenience. Fixes #205 <https://github.com/Genymobile/scrcpy/issues/205> Fixes #2580 <https://github.com/Genymobile/scrcpy/issues/2580> Fixes #4049 <https://github.com/Genymobile/scrcpy/issues/4049>
This commit is contained in:
parent
b16d4d1835
commit
a3cdf1a6b8
9 changed files with 31 additions and 0 deletions
|
@ -20,6 +20,7 @@ _scrcpy() {
|
|||
--force-adb-forward
|
||||
--forward-all-clicks
|
||||
-h --help
|
||||
--kill-adb-on-close
|
||||
-K --hid-keyboard
|
||||
--legacy-paste
|
||||
--list-displays
|
||||
|
|
|
@ -27,6 +27,7 @@ arguments=(
|
|||
'--force-adb-forward[Do not attempt to use \"adb reverse\" to connect to the device]'
|
||||
'--forward-all-clicks[Forward clicks to device]'
|
||||
{-h,--help}'[Print the help]'
|
||||
'--kill-adb-on-close[Kill adb when scrcpy terminates]'
|
||||
{-K,--hid-keyboard}'[Simulate a physical keyboard by using HID over AOAv2]'
|
||||
'--legacy-paste[Inject computer clipboard text as a sequence of key events on Ctrl+v]'
|
||||
'--list-displays[List displays available on the device]'
|
||||
|
|
|
@ -129,6 +129,10 @@ By default, right-click triggers BACK (or POWER on) and middle-click triggers HO
|
|||
.B \-h, \-\-help
|
||||
Print this help.
|
||||
|
||||
.TP
|
||||
.B \-\-kill\-adb\-on\-close
|
||||
Kill adb when scrcpy terminates.
|
||||
|
||||
.TP
|
||||
.B \-K, \-\-hid\-keyboard
|
||||
Simulate a physical keyboard by using HID over AOAv2.
|
||||
|
|
|
@ -77,6 +77,7 @@ enum {
|
|||
OPT_NO_AUDIO_PLAYBACK,
|
||||
OPT_NO_VIDEO_PLAYBACK,
|
||||
OPT_AUDIO_SOURCE,
|
||||
OPT_KILL_ADB_ON_CLOSE,
|
||||
};
|
||||
|
||||
struct sc_option {
|
||||
|
@ -280,6 +281,11 @@ static const struct sc_option options[] = {
|
|||
.longopt = "help",
|
||||
.text = "Print this help.",
|
||||
},
|
||||
{
|
||||
.longopt_id = OPT_KILL_ADB_ON_CLOSE,
|
||||
.longopt = "kill-adb-on-close",
|
||||
.text = "Kill adb when scrcpy terminates.",
|
||||
},
|
||||
{
|
||||
.shortopt = 'K',
|
||||
.longopt = "hid-keyboard",
|
||||
|
@ -1944,6 +1950,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case OPT_KILL_ADB_ON_CLOSE:
|
||||
opts->kill_adb_on_close = true;
|
||||
break;
|
||||
default:
|
||||
// getopt prints the error message on stderr
|
||||
return false;
|
||||
|
|
|
@ -80,4 +80,5 @@ const struct scrcpy_options scrcpy_options_default = {
|
|||
.require_audio = false,
|
||||
.list_encoders = false,
|
||||
.list_displays = false,
|
||||
.kill_adb_on_close = false,
|
||||
};
|
||||
|
|
|
@ -180,6 +180,7 @@ struct scrcpy_options {
|
|||
bool require_audio;
|
||||
bool list_encoders;
|
||||
bool list_displays;
|
||||
bool kill_adb_on_close;
|
||||
};
|
||||
|
||||
extern const struct scrcpy_options scrcpy_options_default;
|
||||
|
|
|
@ -364,6 +364,7 @@ scrcpy(struct scrcpy_options *options) {
|
|||
.power_on = options->power_on,
|
||||
.list_encoders = options->list_encoders,
|
||||
.list_displays = options->list_displays,
|
||||
.kill_adb_on_close = options->kill_adb_on_close,
|
||||
};
|
||||
|
||||
static const struct sc_server_callbacks cbs = {
|
||||
|
|
|
@ -794,6 +794,15 @@ sc_server_configure_tcpip_unknown_address(struct sc_server *server,
|
|||
return sc_server_connect_to_tcpip(server, ip_port);
|
||||
}
|
||||
|
||||
static void
|
||||
sc_server_kill_adb_if_requested(struct sc_server *server) {
|
||||
if (server->params.kill_adb_on_close) {
|
||||
LOGI("Killing adb server...");
|
||||
unsigned flags = SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR;
|
||||
sc_adb_kill_server(&server->intr, flags);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
run_server(void *data) {
|
||||
struct sc_server *server = data;
|
||||
|
@ -993,9 +1002,12 @@ run_server(void *data) {
|
|||
|
||||
sc_process_close(pid);
|
||||
|
||||
sc_server_kill_adb_if_requested(server);
|
||||
|
||||
return 0;
|
||||
|
||||
error_connection_failed:
|
||||
sc_server_kill_adb_if_requested(server);
|
||||
server->cbs->on_connection_failed(server, server->cbs_userdata);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ struct sc_server_params {
|
|||
bool power_on;
|
||||
bool list_encoders;
|
||||
bool list_displays;
|
||||
bool kill_adb_on_close;
|
||||
};
|
||||
|
||||
struct sc_server {
|
||||
|
|
Loading…
Reference in a new issue