Last active
February 28, 2024 19:17
-
-
Save benbaxter/269549fdb97d58f848b6b32aed4d7e78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is for ATV only | |
alias adb-dev-options='adb shell am start -n com.android.tv.settings/.system.development.DevelopmentActivity' | |
# For mobile use: | |
#alias adb-dev-options='adb shell am start -n com.android.settings/.DevelopmentSettings' | |
# Animations | |
alias animations-off='adb shell settings put global animator_duration_scale 0' | |
alias animations-slow='adb shell settings put global animator_duration_scale 10' | |
alias animations-normal='adb shell settings put global animator_duration_scale 1' | |
alias animations-fast='adb shell settings put global animator_duration_scale 0.5' | |
alias animations-speed='adb shell settings put global animator_duration_scale ' | |
# Key presses | |
alias adb-home='adb shell input keyevent 3' | |
alias adb-back='adb shell input keyevent 4' | |
alias adb-up='adb shell input keyevent 19' | |
alias adb-down='adb shell input keyevent 20' | |
alias adb-left='adb shell input keyevent 21' | |
alias adb-right='adb shell input keyevent 22' | |
alias adb-enter='adb shell input keyevent 66' | |
alias adb-text='adb shell input text ' | |
function adb-del() { | |
for i in `seq 1 $1`; | |
adb shell input keyevent 67 | |
} | |
# Changes the font size to 1.5x and then back to 1.0. This triggers two configuration changes in succession. | |
alias adb-config-change-font='adb shell content insert --uri content://settings/system --bind name:s:font_scale --bind value:f:1.5;adb shell content insert --uri content://settings/system --bind name:s:font_scale --bind value:f:1.0' | |
# Prints the screen denisty. A table of density values mapped to density qualifiers can be found here: | |
# https://developer.android.com/training/multiscreen/screendensities#TaskProvideAltBmp | |
alias adb-screen-density='adb shell getprop ro.sf.lcd_density' | |
alias adb-wake='adb shell input keyevent 224' | |
alias adb-assistant='adb shell input keyevent 231' | |
alias adb-wifi-enable='adb shell svc wifi enable' | |
alias adb-wifi-disable='adb shell svc wifi disable' | |
function screenshot() { | |
DATE=`date +%Y-%m-%d_%H:%M:%S` | |
FILENAME=$DATE.png | |
FOLDER="$HOME/screenshots" # or choose a different folder location | |
[ ! -d "$FOLDER" ] && mkdir "$FOLDER" | |
adb shell screencap -p /sdcard/screen.png | |
adb pull /sdcard/screen.png $FOLDER/$FILENAME | |
adb shell rm /sdcard/screen.png | |
} | |
function adb-pull-trace() { | |
DATE=`date +%Y-%m-%d_%H:%M:%S` | |
FILENAME=trace-$DATE.png | |
FOLDER="$HOME/traces" # or choose a different folder location | |
[ ! -d "$FOLDER" ] && mkdir "$FOLDER" | |
adb pull /data/misc/perfetto-traces/trace $FOLDER/$FILENAME | |
adb shell rm /data/misc/perfetto-traces/trace | |
} | |
# Set device | |
function adb-emulator() { | |
export ANDROID_SERIAL=emulator-5554 | |
export ANDROID_SERIAL_LABEL="Emulator" | |
echo "Setting device to $ANDROID_SERIAL_LABEL: $ANDROID_SERIAL" | |
} | |
function adb-adt3() { | |
export ANDROID_SERIAL=PUSA00000XXX # update with device serial number | |
export ANDROID_SERIAL_LABEL="ADT-3" | |
echo "Setting device to $ANDROID_SERIAL_LABEL: $ANDROID_SERIAL" | |
} | |
function adb-shield() { | |
export ANDROID_SERIAL=XXXXXXXXXXXXX # update with device serial number | |
export ANDROID_SERIAL_LABEL="Shield" | |
echo "Setting device to $ANDROID_SERIAL_LABEL: $ANDROID_SERIAL" | |
} | |
function adb-log-level() { | |
if [ "$1" = "h" -o "$1" = help ]; then | |
echo "Set the logging level for a particular tag." | |
echo "example usage:" | |
echo " adb-log MyTag VERBOSE" | |
return 0 | |
fi | |
if [ "$1" = "" ]; then | |
echo "A logging tag must be specified" | |
echo "example usage:" | |
echo " adb-log MyTag VERBOSE" | |
return 1 | |
fi | |
# Convert short hand to actual logging levels | |
shopt -s nocasematch | |
#For zsh, use setopt instead | |
case "$2" in | |
"v" ) LOG_LEVEL="VERBOSE";; | |
"d" ) LOG_LEVEL="DEBUG";; | |
"i" ) LOG_LEVEL="INFO";; | |
"w" ) LOG_LEVEL="WARN";; | |
"e" ) LOG_LEVEL="ERROR";; | |
"a" ) LOG_LEVEL="ASSERT";; | |
*) LOG_LEVEL="$2";; | |
esac | |
if [ "$LOG_LEVEL" = "r" -o "$LOG_LEVEL" = "R" ]; then | |
adb shell setprop log.tag."$1" "\"\"" | |
echo "Logging is removed for tag: $1" | |
adb shell getprop | grep log.tag."$1" | |
return 0 | |
fi | |
if [[ "$LOG_LEVEL" != "VERBOSE" | |
&& "$LOG_LEVEL" != "DEBUG" | |
&& "$LOG_LEVEL" != "INFO" | |
&& "$LOG_LEVEL" != "WARN" | |
&& "$LOG_LEVEL" != "ERROR" | |
&& "$LOG_LEVEL" != "ASSERT" ]]; then | |
echo "Log level must be one of VERBOSE, DEBUG, INFO, WARN, ERROR, or ASSERT" | |
echo "See https://developer.android.com/reference/android/util/Log#constants_1 for more details" | |
echo "You can also use v, d, i, w, e, or a" | |
echo "example usage:" | |
echo " adb-log MyTag VERBOSE" | |
return 1 | |
fi | |
adb shell setprop log.tag."$1" "$LOG_LEVEL" | |
echo "Tag is set to log" | |
adb shell getprop | grep log.tag."$1" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To make the animation run slower, run: | |
$> animations-slow | |
# To return back to normal speed, run: | |
$> animations-normal | |
# To set to a custom speed, run: | |
$> animations-speed 5 | |
# This sets the duration to 5x. | |
# You can always verify the value in Developer Options if you do not know what the value of the duration is. | |
# When more than one device is connected and run `adb shell`: | |
$> adb shell | |
error: more than one device/emulator | |
# Then run one of the device functions to set the device and remove the need for the -s flag | |
$> adb-emulator | |
Setting device to Emulator: emulator-5554 | |
$> adb shell | |
generic_x86:/ # | |
# This is the same as running `adb -s emulator-5554 shell` but persists the -s flag for the terminal session. | |
$> adb-text hello | |
# Sends the string "hello" over text input. | |
$> adb-text <username>; adb-enter | |
# Great for typing username/passwords. | |
$> adb-text hello%sworld | |
# Send the string "hello world", note that %s is used for spaces. | |
$> adb-del | |
# Sends the delete key event. Useful when needed to hit backspace to retype something. | |
$> adb-del 5 | |
# Sends the event 5 times. Useful when needed to clear a larger chunk of text. | |
# Enable logging for a specific tag | |
# See https://developer.android.com/reference/android/util/Log.html#isLoggable(java.lang.String,%20int) for more details | |
$> adb-log MyTag VERBOSE | |
Tag is set to log | |
[log.tag.MyTag]: [VERBOSE] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment