Skip to content

Instantly share code, notes, and snippets.

@JosefLitos
Last active August 31, 2021 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosefLitos/0d47a07161d2e84ae728d2fe29ae8c77 to your computer and use it in GitHub Desktop.
Save JosefLitos/0d47a07161d2e84ae728d2fe29ae8c77 to your computer and use it in GitHub Desktop.
Simple bash script using adb and fzf for uninstalling apps from Android phones, disabling them, enabling and installing the system default apps back.
#!/usr/bin/env bash
# sam = System APK Manager
if [ -z "$(adb devices | sed 's/^List.*$//')" ]; then
printf "No devices are connected, please attach a usb cable or use 'adb connect'.\n"
exit 0
fi
# Display a menu for disabling applications as long as there is a selection
disable() {
packages=$(adb shell pm list packages -e | sed 's/package://' | fzf -m --prompt='disable: ')
for package in $packages; do
adb shell pm disable-user --user 0 $package
done
}
# Selectively enables previously disabled applications
enable() {
packages=$(adb shell pm list packages -d | sed 's/package://' | fzf -m --prompt='enable: ')
for package in $packages; do
adb shell pm enable --user 0 $package
done
}
# Selectively uninstall every disabled app onboard
uninstall() {
packages=$(adb shell pm list packages -d | sed 's/package://' | fzf -m --prompt='uninstall: ')
for package in $packages; do
printf "Uninstall '%s'? [Yes/no/(k)eep data and cache]: " $package
read -r -n 1 decision
[ $decision ] && printf '\n'
printf '\e[2A\n\e[KPackage %s uninstallation: ' $package
case $decision in
y | Y | "") adb uninstall --user 0 $package ;;
k | K) adb shell cmd package uninstall -k $package ;;
esac
done
}
# Installs selected system apps that were uninstalled
installUninstalled() {
sysapps=($(adb shell pm list packages -s -u))
for sysinstalled in $(adb shell pm list packages -s); do
declare -i c=0
while [ "${sysapps[$c]}" != $sysinstalled ]; do c+=1; done
sysapps[$c]=
done
packages=$(echo "${sysapps[@]}" | sed 's/package://g;s/^ \+//;s/ \+/\n/g' | fzf -m --prompt='install: ')
for package in $packages; do
adb shell pm install-existing --user 0 $package
done
}
help() {
printf 'SAM - System APK Manager
This program uses ADB to manage system applications on your Android phone.
d:\tdisable; provide app disabler
e:\tenable; provide disabled-app enabler
u:\tuninstall; provide disabled-app uninstaller
i:\tinstall; provide uninstalled-default-app installer
h:\thelp; display this help
q:\tquit; exit the program\n'
}
help
printf "Choose action: "
while read -r -n 1 option; do
printf '\e[1A\n\e[K'
case $option in
d | disable) disable ;;
e | enable) enable ;;
u | uninstall) uninstall ;;
i | install) installUninstalled ;;
h | help) help ;;
q | quit) exit 0 ;;
esac
printf "Choose action: "
done
exit 0
@JosefLitos
Copy link
Author

JosefLitos commented Aug 4, 2021

Using this, you can get rid of google quite easily, simply keep searching for google string and keep disabling it until there is no more left.
then uninstall those disabled apps from the user.

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