Skip to content

Instantly share code, notes, and snippets.

@steverichey
Forked from mauron85/keep-adb-running.sh
Last active November 28, 2018 15:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steverichey/df147bc118d34dadb2f1dfedb82e864b to your computer and use it in GitHub Desktop.
Save steverichey/df147bc118d34dadb2f1dfedb82e864b to your computer and use it in GitHub Desktop.
Workaround adb disconnecting issue on macOS Sierra
#!/bin/bash
cat << EOF
###########################################################
# Workaround adb disconnecting issue on macOS Sierra
#
# More info:
# https://code.google.com/p/android/issues/detail?id=219085
# credits to: hans...@meetme.com, vs...@google.com
###########################################################
EOF
function each_device() {
DEVICES=( $(adb devices | tail -n +2 | cut -sf 1) )
for DEVICE in ${DEVICES[@]}
do
adb -s ${DEVICE} $@
done
}
function monitor_adb () {
adb start-server
echo "[$(date)] adb started"
while [ "$(each_device shell echo 1)" ]; do sleep 5; done
echo "[$(date)] adb is broken, restarting"
adb kill-server
adb start-server || adb start-server
each_device reverse
}
while [ true ]; do time monitor_adb ; done
@steverichey
Copy link
Author

This revision works when more than one device is connected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment