3 ms·
I do a fair amount of physical unplugging and replugging of Android devices over USB while debugging. I used to get occasional hangs when doing that, so I run s
by cf100clunk 5y ago
I do a fair amount of physical unplugging and replugging of Android devices over USB while debugging. I used to get occasional hangs when doing that, so I run scrcpy thusly in a bash wrapper script on Linux hosts:
#!/bin/bash
# Update: January 2, 2021
#
# script to permit an end user to mirror an android device's GUI
# on a Linux GUI desktop in a window of its own with
# mouse and keyboard interactivity
#
# Prerequisites:
#
# android device with adb debugging enabled
# adb (i.e. android-tools-adb)
# scrcpy (android screen mirror tool)
# USB connection between Android phone and Linux machine
#
# Setup:
#
# Log in as root and do the following:
#
# 1. use visudo to create or edit the file /etc/sudoers.d/adbmount
# with the following entries (use suitable paths to
# the binaries) to authorize the end user for fuser
# and adb use:
#
# %users ALL=(myth) NOPASSWD: /bin/fuser
# %users ALL=(myth) NOPASSWD: /bin/adb
#
# 2. create a new group or add an entry in /etc/group
# for "plugdev" with the end user as member, such as:
#
# plugdev:x:46:mythical
#
# 3. connect the android device to the Linux machine via
# a USB cable and use the lsusb command to get the
# android device's identifying info, such as:
#
# Bus 001 Device 012: ID 18d1:XXXX Google Inc.
#
# 4. create the file /etc/udev/rules.d/51-adbmount.rules
# with the following line, using the id from step 3:
#
# SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="XXXX", MODE="0666", GROUP="plugdev"
#
# 5. run the following command to load the new rules so
# that udev will now allow members of group "plugdev"
# to access the android device:
#
# udevadm control --reload-rules
#
# 6. test this script as the specified end user instead
# of as root
# first kill any hanging adb tcp port 27183:
sudo /bin/fuser -k -n tcp 27183 2>/dev/null
# force any running adb server process to stop:
sudo /bin/adb kill-server 2>/dev/null
# force the adb server to start and scan USB bus:
sudo /bin/adb devices
# start the scrpy app:
/bin/scrcpy