Android™ Debug Bridge (adb)
The Swiss Army Knife for Android
Installation
emerge --ask dev-util/android-sdk-update-manager dev-util/android-tools
dnf install adb
apt install adb fastboot
1) Download the Android SDK Platform Tools ZIP file for Linux.
2) Extract the ZIP to an easily-accessible location (like the Desktop for example).
3) Open a Terminal window.
4) Enter the following command: cd /path/to/extracted/folder/
5) This will change the directory to where you extracted the ADB files.
6) So for example: cd /Users/Doug/Desktop/platform-tools/
7. Connect your device to your Linux machine with your USB cable.
Change the connection mode to “file transfer (MTP)” mode.
This is not always necessary for every device, but it’s recommended so you don’t run into any issues.
8) Once the Terminal is in the same folder your ADB tools are in, you can execute the following command to launch the ADB daemon: ./adb devices
9) Back on your smartphone or tablet device, you’ll see a prompt asking you to allow USB debugging. Go ahead and grant it.
1) Download: https://dl.google.com/android/repository/platform-tools-latest-windows.zip
2) Extract the contents of this ZIP file into an easily accessible folder (such as C:\platform-tools)
3) Open Windows explorer and browse to where you extracted the contents of this ZIP file
4) Then open up a Command Prompt from the same directory as this ADB binary. This can be done by holding
Shift and Right-clicking within the folder then click the “Open command window here” option.
5) Connect your smartphone or tablet to your computer with a USB cable.
Change the USB mode to “file transfer (MTP)” mode. Some OEMs may or may not require this,
but it’s best to just leave it in this mode for general compatibility.
6) In the Command Prompt window, enter the following command to launch the ADB daemon: adb devices
7) On your phone’s screen, you should see a prompt to allow or deny USB Debugging access. Naturally,
you will want to grant USB Debugging access when prompted (and tap the always allow check box if you never want to see that prompt again).
8) Finally, re-enter the command from step
you should now see your device’s serial number in the command prompt (or the PowerShell window).
Bash: Aliases For ADB
#!/bin/bash
cat <<! >> ~/.bashrc
function startintent() {
adb devices \
|tail -n +2 \
|cut -sf 1 \
|xargs -I X adb -s X shell am start $(1)
function apkinstall() {
adb devices \
|tail -n +2 \
|cut -sf 1 \
|xargs -I X \
adb -s X install -r $(1)
}
function rmapp() {
adb devices \
|tail -n +2 \
|cut -sf 1 \
|xargs -I X adb -s X uninstall $(1)
}
function clearapp() {
adb devices \
|tail -n +2 \
|cut -sf 1 \
|xargs -I X adb -s X shell cmd package clear $(1)
}
Backup all apk files and avoid permission denied applications
#!/usr/bin/env bash
set -u
# ──────────────────────────────────────────────
# Color handling (auto-disable if not TTY)
# ──────────────────────────────────────────────
if [[ -t 1 ]]; then
GRN=$'\e[0;32m'
RED=$'\e[0;31m'
RST=$'\e[0m'
else
GRN=''
RED=''
RST=''
fi
OK="[${GRN}*${RST}]"
ERR="[${RED}!${RST}]"
DONE="[${GRN}✓${RST}]"
INFO="[i]"
# Print helper (never use echo for escapes)
log() { printf '%s %s\n' "$OK" "$*"; }
err() { printf '%s %s\n' "$ERR" "$*"; }
done_(){ printf '%s %s\n' "$DONE" "$*"; }
info() { printf '%s %s\n' "$INFO" "$*"; }
# ──────────────────────────────────────────────
# Setup
# ──────────────────────────────────────────────
OUT="${1:-apks_backup}"
mkdir -p "$OUT"
FAILLOG="$OUT/_failures.log"
: > "$FAILLOG"
# Choose one:
PKGS_CMD=(cmd package list packages) # all packages
# PKGS_CMD=(cmd package list packages -3) # user-installed only
mapfile -t PKGS < <("${PKGS_CMD[@]}" 2>/dev/null | sed 's/^package://')
log "Found ${#PKGS[@]} packages"
log "Logging failures to: $FAILLOG"
# ──────────────────────────────────────────────
# Main loop
# ──────────────────────────────────────────────
for pkg in "${PKGS[@]}"; do
mapfile -t PATHS < <(cmd package path "$pkg" 2>/dev/null | sed 's/^package://')
[[ ${#PATHS[@]} -gt 0 ]] || continue
appdir="$OUT/$pkg"
mkdir -p "$appdir"
log "$pkg -> ${#PATHS[@]} apk(s)"
for p in "${PATHS[@]}"; do
if ! "test -r '$p'" >/dev/null 2>&1; then
err "SKIP (not readable): $pkg :: $p"
printf '%s\n' "SKIP (not readable): $pkg :: $p" >> "$FAILLOG"
continue
fi
if ! adb pull "$p" "$appdir/" >/dev/null 2>&1; then
err "FAIL (pull): $pkg :: $p"
printf '%s\n' "FAIL (pull): $pkg :: $p" >> "$FAILLOG"
continue
fi
done
done
done_ "Done. Output: $OUT/"
info "Any failures were logged in: $FAILLOG"
Find phone number on device
am start com.samsung.android.app.telephonyui/com.samsung.android.app.telephonyui.netsettings.ui.simcardmanager.SimCardMgrActivity
uiautomator dump /data/local/tmp/ui.xml && grep -o 'text="+[0-9]*"' /data/local/tmp/ui.xml | sed 's/text="//;s/"//'
Backup all apk files and avoid permission denied applications (smartwatch version)
#!/usr/bin/env bash
set -u
# ──────────────────────────────────────────────
# Color handling (auto-disable if not TTY)
# ──────────────────────────────────────────────
if [[ -t 1 ]]; then
GRN=$'\e[0;32m'
RED=$'\e[0;31m'
RST=$'\e[0m'
else
GRN=''
RED=''
RST=''
fi
OK="[${GRN}*${RST}]"
ERR="[${RED}!${RST}]"
DONE="[${GRN}✓${RST}]"
INFO="[i]"
# Print helper (never use echo for escapes)
log() { printf '%s %s\n' "$OK" "$*"; }
err() { printf '%s %s\n' "$ERR" "$*"; }
done_() { printf '%s %s\n' "$DONE" "$*"; }
info() { printf '%s %s\n' "$INFO" "$*"; }
# ──────────────────────────────────────────────
# Device selection
# Usage:
# ./pull_apks.sh [OUTDIR] [SERIAL]
# ADB_SERIAL=192.168.1.100:45605 ./pull_apks.sh
# ──────────────────────────────────────────────
OUT="${1:-apks_backup}"
ADB_SERIAL="${ADB_SERIAL:-${2:-}}"
ADB=(adb)
if [[ -n "$ADB_SERIAL" ]]; then
ADB+=( -s "$ADB_SERIAL" )
fi
# If multiple devices and no serial, fail early (avoid "Found 0 packages")
if [[ -z "$ADB_SERIAL" ]]; then
# Count "device" and "offline" lines that look like actual transports
dev_count="$("${ADB[@]}" devices 2>/dev/null | awk 'NR>1 && $1!="" {c++} END{print c+0}')"
if (( dev_count > 1 )); then
err "Multiple ADB transports detected. Specify a serial:"
"${ADB[@]}" devices -l 2>/dev/null | sed 's/^/ /'
err "Run: $0 $OUT 192.168.1.100:45605"
exit 2
fi
fi
# Warn if selected device is offline/unauthorized
if [[ -n "$ADB_SERIAL" ]]; then
state="$("${ADB[@]}" devices 2>/dev/null | awk -v s="$ADB_SERIAL" '$1==s {print $2; exit}')"
if [[ "$state" == "offline" ]]; then
err "Device $ADB_SERIAL is OFFLINE. Try:"
err " adb disconnect $ADB_SERIAL; adb kill-server; adb start-server; adb connect $ADB_SERIAL"
exit 3
elif [[ "$state" == "unauthorized" ]]; then
err "Device $ADB_SERIAL is UNAUTHORIZED. Accept the RSA prompt on the device."
exit 4
fi
fi
# ──────────────────────────────────────────────
# Setup
# ──────────────────────────────────────────────
mkdir -p "$OUT"
FAILLOG="$OUT/_failures.log"
: > "$FAILLOG"
# Choose one (pm is usually more compatible than cmd):
PKGS_CMD=("${ADB[@]}" shell pm list packages) # all packages
# PKGS_CMD=("${ADB[@]}" shell pm list packages -3) # user-installed only
mapfile -t PKGS < <("${PKGS_CMD[@]}" 2>/dev/null | sed 's/^package://')
log "Found ${#PKGS[@]} packages"
log "Logging failures to: $FAILLOG"
# ──────────────────────────────────────────────
# Main loop
# ──────────────────────────────────────────────
for pkg in "${PKGS[@]}"; do
mapfile -t PATHS < <("${ADB[@]}" shell pm path "$pkg" 2>/dev/null | sed 's/^package://')
[[ ${#PATHS[@]} -gt 0 ]] || continue
appdir="$OUT/$pkg"
mkdir -p "$appdir"
log "$pkg -> ${#PATHS[@]} apk(s)"
for p in "${PATHS[@]}"; do
if ! "${ADB[@]}" shell "test -r '$p'" >/dev/null 2>&1; then
err "SKIP (not readable): $pkg :: $p"
printf '%s\n' "SKIP (not readable): $pkg :: $p" >> "$FAILLOG"
continue
fi
if ! "${ADB[@]}" pull "$p" "$appdir/" >/dev/null 2>&1; then
err "FAIL (pull): $pkg :: $p"
printf '%s\n' "FAIL (pull): $pkg :: $p" >> "$FAILLOG"
continue
fi
done
done
done_ "Done. Output: $OUT/"
info "Any failures were logged in: $FAILLOG"
Shutdown rather then reboot
reboot -p ShutDown
Dump battery level in perecentage
dumpsys battery | awk -F': ' '/level/{print $2"%"}'
Disable sim warning for service provider
cmd package disable-user --user 0 com.samsung.android.cidmanager
Execute the help command -h on all options in cmd list for find valid commands in shell
cmd -l | xargs -n 1 -P $(( $(nproc) + 1 )) sh -c 'cmd "$0" -h' 2>/dev/null
Execute the help command -h on all options in cmd list for find valid commands in shell without printing help for each setting
bash "for c in \$(cmd -l); do OUT=\$(cmd \$c -h 2>&1); if echo \"\$OUT\" | grep -qEi \"No shell command|Unknown|not found|Failure|Error|Failed transaction\"; then printf \"[\033[0;31m*\033[0m] %s failed\n\" \"\$c\"; else printf \"[\033[0;32m*\033[0m] %s works\n\" \"\$c\"; fi; done"
Dump all cmd commands with -h option ready to use
cmd -l | xargs -P$(nproc) -I{} echo "cmd {} -h" 2>/dev/null
Follow and monitor the battery charging in realtime
adb logcat -c
adb logcat -s AODBatteryManager | awk -F' ' '/mRemainingChargeTime/ {
split($15, arr, "=")
gsub(",", "", arr[2])
minutes = int(arr[2] / 60000)
seconds = int((arr[2] % 60000) / 1000)
if (!found) {
print "Estimated time until fully charged: " minutes " min " seconds " seconds"
found=1
exit
}
}'
Capture all touches and create the commands in realtime
- Shared on this gist: Adb useful commands list
getevent -l | awk '
/EV_ABS/ {
event[$3] = strtonum("0x" $NF)
}
/EV_SYN/ {
if (event["ABS_MT_POSITION_X"] && event["ABS_MT_POSITION_Y"]) {
printf "input touchscreen swipe %d %d %d %d 1000\n",
event["ABS_MT_POSITION_X"], event["ABS_MT_POSITION_Y"],
event["ABS_MT_POSITION_X"], event["ABS_MT_POSITION_Y"]
}
}
Sniff network traffic to stdout
su -c tcpdump -nn -i any -U -s0 -w - 'not port 5555' | wireshark -k -i
Dump all cmd commands with -h option ready to use
- Launch this when you working in in the native shell
cmd -l | xargs -n 1 -P $(( $(nproc) + 1 )) sh -c 'echo "cmd $0" -h' 2>/dev/null
Execute -h on all options in cmd list for find valid commands in shell
- Launch this when you working in in the native shell
cmd -l | xargs -n 1 -P $(( $(nproc) + 1 )) sh -c 'cmd "$0" -h' 2>/dev/null
Efficient Retrieval of ADB Shell Command Help Information
cmd -l | while read -r service; do
(
cmd_output=$(cmd "$service" -h 2>&1)
if echo "$cmd_output" | grep -q "Unknown command"; then
cmd "$service" --help 2>/dev/null
else
echo "$cmd_output"
fi
) &
[ $(jobs | wc -l) -ge $(( $(nproc) + 1 )) ] && wait -n
done
wait
cmd -l | grep -v "\." | xargs -P $(( $(nproc) + 1 )) -n 1 sh -c '
(
out=$(cmd "$1" -h 2>&1)
if echo "$out" | grep -q "Unknown command"; then
cmd "$1" --help 2>/dev/null
else
echo "$out"
fi
) &
PID=$!
( sleep 2; kill $PID 2>/dev/null ) &
WATCHDOG=$!
wait $PID 2>/dev/null
kill $WATCHDOG 2>/dev/null
' _
- This command will launch –help IF
-his not working
#!/system/bin/sh
### Script works as: If `-h` is unknown, try `--help`
### If "-h" worked, print its output and skip `--help` for the same command
handle_command() {
cmd_output=$(cmd "$1" -h 2>&1)
if echo "$cmd_output" | grep -q "Unknown command"; then
cmd "$1" --help 2>/dev/null
else
echo "$cmd_output"
fi
}
export -f handle_command
cmd -l | parallel -j $(( $(nproc) + 1 )) handle_command
Enhancing Command-Line Productivity and Debugging - Random Colorized Output
- Launch this when you working in in the native shell
cmd -l | xargs -n 1 -P $(( $(nproc) + 1 )) sh -c '
color=$((RANDOM%254+1))
printf "\033[38;5;${color}m"
printf "%-80s\n" | tr " " "-"
printf "cmd $0 -h\033[0m\n"
cmd "$0" -h | awk -v color="$color" "
BEGIN {
line=sprintf(\"%-80s\", \"\")
gsub(/ /, \"-\", line)
print \"\033[38;5;\" color \"m\" line \"\033[0m\"
}
{
print \"\033[38;5;\" color \"m\" \$0 \"\033[0m\"
}
"
'
Print device uptime in days
TZ=UTC date -d@$(cut -d\ -f1 /proc/uptime) +'%j %T' |awk '{print $1-1"d",$2}'
Device sensors by name
su -c "grep -r . /sys/class/sensors/*/name"
Print how many times device has booted since last factory reset
settings list global|awk -F= '/^boot_count/ {print $2}'
Connect to adb over wifi by copy/paste
#!/bin/bash
# Author: wuseman
port="5555"
interface=$(ip addr | awk '/state UP/ {print $2}' | sed 's/.$//'; )
ip=$(ifconfig ${interface} \
|egrep -o '(\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.){3}\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>' 2> /dev/null \
|head -n 1)
adb tcpip ${port};sleep 0.5
adb connect $ip:${port}; sleep 1.0
adb devices; adb shell
Listing Currently Running Applications
pm list packages | sed -e "s/package://" | while read x; do
cmd package resolve-activity --brief $x | tail -n 1 | grep -v "No activity found"
done
Add a Contact, fill info and press save on device
am start -a android.intent.action.INSERT \
-t vnd.android.cursor.dir/contact \
-e name 'wuseman' \
-e phone '+467777701' \
-e email 'wuseman@android-shell.se' \
-e postal 'Street 10, New York'
- For press save contact via shell from above command
input keyevent 4
input keyevent 4
Launch accessbility window
su -c 'am start com.samsung.accessibility/com.samsung.accessibility.core.winset.activity.SubSettings'
Initiates a Wi-Fi scan on the Android device
cmd -w wifi start-scan
sleep 7
cmd -w wifi list-scan-results
Dumping Information of Current Application in Use (Android 12/13)
dumpsys activity|grep -i mCurrentFocus|awk 'NR==1{print $3}'|cut -d'}' -f1
Print Warranty Status (Samsung)
warranty=$(getprop ro.boot.warranty_bit)
if [[ $warranty -ne 0 ]]; then
echo "Warranty is voided and device has been rooted"
else
echo "Warranty is valid and device is not rooted"
fi
Indicating Device Completion
content insert --uri content://settings/global --bind name:s:device_provisioned --bind value:i:1
content insert --uri content://settings/secure --bind name:s:user_setup_complete --bind value:i:1
am broadcast -a android.intent.action.SETTING --es setting:global device_provisioned --ez value 1
am broadcast -a android.intent.action.SETTING --es setting:secure user_setup_complete --ez value 1
am broadcast -a android.intent.action.SETTING --es setting:global --esa value '[{"name":"device_provisioned","value":"1"}]'
am broadcast -a android.intent.action.SETTING --es setting:secure --esa value '[{"name":"user_setup_complete","value":"1"}]'
Dumping All Launchable Activities for a Preferred Application
dumpsys package com.android.settings | awk '/Activity/ && /com.android.settings\// {print "am start -n \x27" $2 "\x27"}'
Dumping All Secret Launchable Activities for System Settings
dumpsys package com.android.settings | awk -F' ' '/Activity/ && /com.android.settings\// {print $2}' | rg -i "develop|dev"
Dumping All Secret Launchable Activities for System Settings
dumpsys package \^J |grep -Eo "^[[:space:]]+[0-9a-f]+[[:space:]]+.*/[^[:space:]]+" \^J |grep -oE "[^[:space:]]+$"|uniq|grep ".dev.*settings"
Dump Unique Package Names from 'dumpsys package' History
dumpsys package \
|grep -Eo "^[[:space:]]+[0-9a-f]+[[:space:]]+.*/[^[:space:]]+" \
|grep -oE "[^[:space:]]+$"|uniq
Dumping Launchable Activities for All Installed Applications on the Device
"cmd package list packages" \
| cut -d':' -f2 \
| xargs -P $(( $(nproc) + 1 )) -n 1 -I {} sh -c '
"dumpsys package {}" \
| awk "/Activity/ && /\// {print \$2}" \
| while read -r activity; do
printf "am start -n '\''%s'\''\n" "$activity"
done
'
packages=$(cmd package list packages | awk -F':' '{ print $2 }' | sort)
do_work() {
package=$1
# Dump package info, extract the raw activity strings cleanly
"dumpsys package $package" \
| grep -io "com.*activity" \
| sed "s/^/am start -n '/;s/$/'/g"
}
export -f do_work
# --ungroup skips internal caching buffers, -j+1 pipes dynamically across all cores + 1
echo "$packages" | parallel --ungroup -j+1 do_work
packages=$(cmd package list packages | awk -F':' '{ print $2 }' | sort)
do_work() {
package=$1
"dumpsys package $package" \
| grep -io "com.*activity" \
| sed "s/^/am start -n '/;s/$/'/g"
}
export -f do_work
echo "$packages" | xargs -I {} -P $(( $(nproc) + 1 )) -n 1 bash -c 'do_work "$@"' _ {}
Dumping Samsung Telephony UI Receivers
app="com.samsung.android.app.telephonyui"
dumpsys package \
| grep -Eo "^[[:space:]]+[0-9a-f]+[[:space:]]+${app}/[^[:space:]]+" \
| grep -oE "[^[:space:]]+Receiver"
Dump IMEI
service call iphonesubinfo 1 \
|cut -d "'" -f2 \
|grep -Eo '[0-9]'\
|xargs| sed 's/\ //g'
service call iphonesubinfo 3 i32 1 \
|grep -oE '[0-9a-f]{8} ' \
|while read hex; do echo -ne "\u${hex:4:4}\u${hex:0:4}";
done;
echo
echo "[device.imei]: [$(service call iphonesubinfo 1 \
| awk -F "'" '{print $2}' \
| sed '1 d' \
| tr -d '\n' \
| tr -d '.' \
| tr -d ' ')]"
service call iphonesubinfo 1 |awk -F"'" 'NR>1 { gsub(/\./,"",$2); imei=imei $2 } END {print imei}'
service call iphonesubinfo 1|cut -c 52-66|tr -d '.[:space:]'"
service call iphonesubinfo 3 i32 2 \
|grep -oE '[0-9a-f]{8} ' \
|while read hex; do
echo -ne "\u${hex:4:4}\u${hex:0:4}";
done; echo
service call iphonesubinfo 1 s16 com.android.shell | cut -d "'" -f2| grep -Eo '[0-9]'| xargs| sed 's/\ //g'
Read screen via uiautomator and print IMEI for all active esim/sim cards on device
(
input keyevent KEYCODE_CALL
sleep 1.5
input text '*#06#'
uiautomator dump /data/local/tmp/uidump.xml >/dev/null
cat /data/local/tmp/uidump.xml
) \
| tr '><' '\n' \
| awk '
/text="IMEI/ {
print_next = 1
next
}
print_next && /text="[0-9]/ {
if (match($0, /[0-9]{15}/)) {
print "IMEI" ++c ": " substr($0, RSTART, RLENGTH)
}
print_next = 0
}
'
Add value oem_unlock_disallowed to allowed
content insert --uri content://settings/global --bind name:s:oem_unlock_disallowed --bind value:s:0
Delete value oem_unlock_disallowed to allowed
content delete --uri content://settings/global --where "name='oem_unlock_disallowed'"
Launch adb debugging wireless mode
am start com.android.settings/.Settings$DevelopmentSettingsActivity
Search through entire device for oemdisallow
find / \( -path "./proc" -o -path "./sys" \) -prune -o -type f -name "*oem*disallow*" -exec sh -c 'for f; do strings "$f" | sed "s|^|$f: |"; done' _ {} + 2>/dev/null
Dump screen state
screenState="$(dumpsys input_method \
|grep -i "mSystemReady=true mInteractive=" \
|awk -F= '{print $3}')"
if [[ $screenState = "true" ]]; then
echo "Screen is on";
else
echo "Screen is off";
fi
Chroot into termux env from android shell
export PREFIX='/data/data/com.termux/files/usr'
export HOME='/data/data/com.termux/files/home'
export LD_LIBRARY_PATH='/data/data/com.termux/files/usr/lib'
export PATH="/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/usr/bin/applets:$PATH"
export LANG='en_US.UTF-8'
export SHELL='/data/data/com.termux/files/usr/bin/bash'
cd "$HOME"
exec "$SHELL" -l
Follow activities by dumpsys the apps that launch the activites
previous_activity=""
while true; do
current_activity=$(dumpsys activity | grep -i mCurrentFocus | awk 'NR==1{print $3}' | cut -d'}' -f1)
if [ "$current_activity" != "$previous_activity" ]; then
echo "$current_activity"
previous_activity="$current_activity"
fi
sleep 1 # Adjust the sleep interval as needed
done
Find Activities for Currently Running Applications - Follow activities - Updated: 2024-02-19
adb logcat | awk '
/act=android.intent.action.MAIN/ && /cmp=/ {
match($0, /act=[^ ]+/);
act=substr($0, RSTART+4, RLENGTH-4);
match($0, /cmp=[^ ]+/);
cmp=substr($0, RSTART+4, RLENGTH-4);
# Exclude lines where cmp ends with "}"
if (cmp ~ /\}$/) next;
key = act " -n " cmp;
if (!seen[key]++) {
printf "am start -a '\''";
# Apply color to action
printf "\033[38;5;202m" act "\033[0m";
printf "'\'' -n '\''";
# Apply color to component
printf "\033[38;5;46m" cmp "\033[0m";
print "'\''";
}
}'
Find Broadcast Receiver for Currently Running Applications (follow services)
adb logcat | awk -F'[ =]' '/cmp=[^ ]+BroadcastReceiver[^ ]*/ {
for (i = 1; i <= NF; i++) {
if ($i == "act") {
act = $(i + 1)
}
if ($i == "cmp") {
cmp = $(i + 1)
}
}
printf "am broadcast -a \033[1;33m'%s'\033[0m -n \033[1;36m'%s'\033[0m\n", act, cmp
}'
Find Services for Currently Running Applications (follow services)
adb logcat | awk -F'[ =]' '/act=[^ ]+/ && /cmp=[^ ]+Service[^ ]*/ {
for (i = 1; i <= NF; i++) {
if ($i == "act") {
act = $(i + 1)
}
if ($i == "cmp") {
cmp = $(i + 1)
} }
printf "am startservice -a \033[1;34m'\''%s'\''\033[0m -n \033[1;32m'\''%s'\''\033[0m\n", act, cmp
}'
Follow and filter lines that indicate an intent is being broadcast
This script extracts the action (act), category (cat), flags (flg), and package (pkg) from the intent and constructs an am broadcast command.
-
This script will process adb logcat output, looking for lines that indicate an intent is being broadcast. It extracts the action (act), category ( cat), flags (flg), and package (pkg) from the intent and constructs an am broadcast command.
-
The command is color-coded for easier reading: action in blue, category in yellow, flags in green, and package in purple.
-
The script assumes that the intent will always have an action and a package. If additional parameters like category and flags are present, they are included in the command.
adb logcat | awk '
/act=/ && /[bB]roadcast/ {
act=""; cat=""; flg=""; pkg=""; cmp="";
# Extrahera värden med säker regex-matchning
if (match($0, /act=[^ ]+/)) { act = substr($0, RSTART+4, RLENGTH-4) }
if (match($0, /cat=\[[^\]]+\]/)) { cat = substr($0, RSTART+5, RLENGTH-6) }
if (match($0, /flg=[^ ]+/)) { flg = substr($0, RSTART+4, RLENGTH-4) }
if (match($0, /pkg=[^ ]+/)) { pkg = substr($0, RSTART+4, RLENGTH-4) }
if (match($0, /cmp=[^ ]+/)) { cmp = substr($0, RSTART+4, RLENGTH-4) }
# Rensa eventuella avslutande parenteser/tecken från strängarna
gsub(/[sub()}]/, "", act); gsub(/[)}]/, "", pkg); gsub(/[)}]/, "", cmp);
# Vi triggar så länge vi åtminstone har en Action (act)
if (act != "") {
printf "am broadcast -a \033[1;34m'\''%s'\''\033[0m ", act;
if (cat != "") { printf "-c \033[1;33m'\''%s'\''\033[0m ", cat }
if (flg != "") { printf "-f \033[1;32m%s\033[0m ", flg }
# Om explicit paket saknas men komponent finns, använd -n istället för -p
if (pkg != "") {
printf "-p \033[1;35m'\''%s'\''\033[0m\n", pkg
} else if (cmp != "") {
printf "-n \033[1;36m'\''%s'\''\033[0m\n", cmp
} else {
printf "\n"
}
}
}'
Filter OTA and FOTA Update Logs with logcat and grep
adb logcat | grep -E '(ota|fota)\.zip'
Stream device screen via FFmpeg
adb exec-out screenrecord --output-format=h264 - |ffmpeg -i - -f mpegts -codec:v mpeg1video -b:v 1000k -s 1280x720 -r 30 -bf 0 http://localhost:8080/stream
Stream device screen via Mplayer
adb exec-out screenrecord --output-format=h264 - |mplayer -framedrop -fps 60 -cache 1024 -
Record device screen to a file
adb exec-out screenrecord --output-format=h264 /sdcard/screen.mp4
Search for AT commands with ripgrep
sourcePath="/path/to/android/files"
mkdir -p ~/search_index
rg --stats --no-column --colors 'match:fg:141' --colors 'match:bg:234' '(AT[+%$]([A-Z]+|\d+)|PACMD|lock(_?|Settings)ettings|weaver.*matched)' $sourcePath | while read line; do
echo "$line"
if [[ "$line" =~ PACMD ]]; then
echo "$line" >> ~/search_index/pacmd.log
fi
if [[ "$line" =~ AT[+%$] ]]; then
echo "$line" >> ~/search_index/at-commands.log
fi
if [[ "$line" =~ weaver ]]; then
echo "$line" >> ~/search_index/weaver-commands.log
fi
done
Receiver used for testing emergency cell broadcasts
am broadcast -a com.android.internal.telephony.gsm.TEST_TRIGGER_CELL_BROADCAST --es pdu_string 0000110011010D0A5BAE57CE770C531790E85C716CBF3044573065B9306757309707767A751F30025F37304463FA308C306B5099304830664E0B30553044FF086C178C615E81FF090000000000000000000000000000
am broadcast -a com.android.internal.telephony.gsm.TEST_TRIGGER_CELL_BROADCAST --es pdu_string 0000110011010D0A5BAE57CE770C531790E85C716CBF3044573065B9306757309707767A751F30025F37304463FA308C306B5099304830664E0B30553044FF086C178C615E81FF090000000000000000000000000000 --ei phone_id 0
Setting up Device Provisioning and Completing Setup
content insert --uri content://settings/global --bind name:s:device_provisioned --bind value:i:1
content insert --uri content://settings/secure --bind name:s:user_setup_complete --bind value:i:1
am broadcast -a android.intent.action.SETTING --es setting:global device_provisioned --ez value 1
am broadcast -a android.intent.action.SETTING --es setting:secure user_setup_complete --ez value 1
am broadcast -a android.intent.action.SETTING --es setting:global --esa value '[{"name":"device_provisioned","value":"1"}]'
am broadcast -a android.intent.action.SETTING --es setting:secure --esa value '[{"name":"user_setup_complete","value":"1"}]'
Copy default sounds to /sdcard
'su -c cp -r /system/media/audio /sdcard/wuseman/sounds/'
Move ring and notification sounds to default path
mount -o rw,remount /
mkdir /system/media/audio/ringtones/SoundTheme/wuseman
cp /sdcard/wuseman/ringtones/* /system/media/audio/ringtones/SoundTheme/wuseman
Create symlink of our custom ringtones and notification path to default media path
'su -c mount -o rw,remount /'
'su -c ln -s /sdcard/wuseman/sounds/wuseman/ /system/media/audio/ringtones/SoundTheme/wuseman'
'su -c mount -o ro,remount /'
reboot
Set ringtone from /sdcard/
'content write --uri content://settings/system/ringtone_cache < /sdcard/wuseman/sounds/wuseman/molle_jobba_jobba.ogg'
Set ringtone to foo.ogg over adb from PC
'content write --uri content://settings/system/ringtone_cache' < host.ogg
UDEV Rules Mostly Brands
SUBSYSTEM=="usb", ATTR{idVendor}=="0502", MODE="0666", GROUP="plugdev" #Acer
SUBSYSTEM=="usb", ATTR{idVendor}=="0b05", MODE="0666", GROUP="plugdev" #ASUS
SUBSYSTEM=="usb", ATTR{idVendor}=="413c", MODE="0666", GROUP="plugdev" #Dell
SUBSYSTEM=="usb", ATTR{idVendor}=="0489", MODE="0666", GROUP="plugdev" #Foxconn
SUBSYSTEM=="usb", ATTR{idVendor}=="04c5", MODE="0666", GROUP="plugdev" #Fujitsu
SUBSYSTEM=="usb", ATTR{idVendor}=="04c5", MODE="0666", GROUP="plugdev" #Fujitsu Toshiba
SUBSYSTEM=="usb", ATTR{idVendor}=="091e", MODE="0666", GROUP="plugdev" #Garmin-Asus
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev" #Google
SUBSYSTEM=="usb", ATTR{idVendor}=="201E", MODE="0666", GROUP="plugdev" #Haier
SUBSYSTEM=="usb", ATTR{idVendor}=="109b", MODE="0666", GROUP="plugdev" #Hisense
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev" #HTC
SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", MODE="0666", GROUP="plugdev" #Huawei
SUBSYSTEM=="usb", ATTR{idVendor}=="24e3", MODE="0666", GROUP="plugdev" #K-Touch
SUBSYSTEM=="usb", ATTR{idVendor}=="2116", MODE="0666", GROUP="plugdev" #KT Tech
SUBSYSTEM=="usb", ATTR{idVendor}=="0482", MODE="0666", GROUP="plugdev" #Kyocera
SUBSYSTEM=="usb", ATTR{idVendor}=="17ef", MODE="0666", GROUP="plugdev" #Lenovo
SUBSYSTEM=="usb", ATTR{idVendor}=="1004", MODE="0666", GROUP="plugdev" #LG
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0666", GROUP="plugdev" #Motorola
SUBSYSTEM=="usb", ATTR{idVendor}=="0e8d", MODE="0666", GROUP="plugdev" #MTK
SUBSYSTEM=="usb", ATTR{idVendor}=="0409", MODE="0666", GROUP="plugdev" #NEC
SUBSYSTEM=="usb", ATTR{idVendor}=="2080", MODE="0666", GROUP="plugdev" #Nook
SUBSYSTEM=="usb", ATTR{idVendor}=="0955", MODE="0666", GROUP="plugdev" #Nvidia
SUBSYSTEM=="usb", ATTR{idVendor}=="2257", MODE="0666", GROUP="plugdev" #OTGV
SUBSYSTEM=="usb", ATTR{idVendor}=="10a9", MODE="0666", GROUP="plugdev" #Pantech
SUBSYSTEM=="usb", ATTR{idVendor}=="1d4d", MODE="0666", GROUP="plugdev" #Pegatron
SUBSYSTEM=="usb", ATTR{idVendor}=="0471", MODE="0666", GROUP="plugdev" #Philips
SUBSYSTEM=="usb", ATTR{idVendor}=="04da", MODE="0666", GROUP="plugdev" #PMC-Sierra
SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666", GROUP="plugdev" #Qualcomm
SUBSYSTEM=="usb", ATTR{idVendor}=="1f53", MODE="0666", GROUP="plugdev" #SK Telesys
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666", GROUP="plugdev" #Samsung
SUBSYSTEM=="usb", ATTR{idVendor}=="04dd", MODE="0666", GROUP="plugdev" #Sharp
SUBSYSTEM=="usb", ATTR{idVendor}=="054c", MODE="0666", GROUP="plugdev" #Sony
SUBSYSTEM=="usb", ATTR{idVendor}=="0fce", MODE="0666", GROUP="plugdev" #Sony Ericsson
SUBSYSTEM=="usb", ATTR{idVendor}=="2340", MODE="0666", GROUP="plugdev" #Teleepoch
SUBSYSTEM=="usb", ATTR{idVendor}=="0930", MODE="0666", GROUP="plugdev" #Toshiba
SUBSYSTEM=="usb", ATTR{idVendor}=="19d2", MODE="0666", GROUP="plugdev" #ZTE