Skip to content

Instantly share code, notes, and snippets.

@Esl1h
Last active September 9, 2025 13:27
Show Gist options
  • Select an option

  • Save Esl1h/dd9c1b82bee79e52a27fc346519ee85d to your computer and use it in GitHub Desktop.

Select an option

Save Esl1h/dd9c1b82bee79e52a27fc346519ee85d to your computer and use it in GitHub Desktop.
By a list, trying remove or disable all installed packages on Android device
#!/bin/bash
# Used to turn ann old smartphone into a DAP (Digital Audio Player)
# https://esli.blog.br/transformando-antigo-smartphone-em-dap
set +e
export ANDROID_SERIAL=ZF523242ZG # 'adb devices' command to find your device
LIST=packages-remove.txt
echo "Loading package list..."
# Load all lines into an array (avoids stdin issues)
readarray -t packages < "$LIST"
echo "Total of ${#packages[@]} packages loaded"
processed=0
success=0
failed=0
for pkg in "${packages[@]}"; do
# Limpa a linha
pkg=$(echo "$pkg" | tr -d '\r\n' | xargs)
[[ -z "$pkg" || "$pkg" =~ ^[[:space:]]*# ]] && continue
((processed++))
echo "[$processed/${#packages[@]}] $pkg"
# Check if it exists
if adb shell pm list packages 2>/dev/null | grep -q "package:$pkg$"; then
echo " -> Found"
# Try to remove
if adb shell pm uninstall --user 0 "$pkg" >/dev/null 2>&1; then
echo " -> ✓ Removed"
((success++))
else
# Try to disable
if adb shell pm disable-user --user 0 "$pkg" >/dev/null 2>&1; then
echo " -> ✓ Disabled"
((success++))
else
echo " -> ✗ Failed"
((failed++))
fi
fi
else
echo " -> Not found"
((failed++))
fi
done
echo ""
echo "Processed: $processed | Successes: $success | Failures: $failed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment