├── docs ├── screenshot1.png ├── screenshot2.png ├── screenshot3.png ├── screenshot4.png └── screenshot5.png ├── README.md ├── adb-block-cli └── adb-block /docs/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/parkerlreed/adb-block/HEAD/docs/screenshot1.png -------------------------------------------------------------------------------- /docs/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/parkerlreed/adb-block/HEAD/docs/screenshot2.png -------------------------------------------------------------------------------- /docs/screenshot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/parkerlreed/adb-block/HEAD/docs/screenshot3.png -------------------------------------------------------------------------------- /docs/screenshot4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/parkerlreed/adb-block/HEAD/docs/screenshot4.png -------------------------------------------------------------------------------- /docs/screenshot5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/parkerlreed/adb-block/HEAD/docs/screenshot5.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # adb-block 2 | Script to block packages on Android even without root 3 | 4 | There is now an initial CLI port. ~~NOTE: Do no use the GUI and CLI versions interchangeably. The .blocked_packages file is formatted differently due to the utilities used. There will be errors if you say block in GUI and unblock in CLI or block in CLI and unblock in GUI.~~ Forgot I made it save to different files. 5 | 6 | Thanks to /u/UnchainedMundane for the cleaned up code. 7 | 8 | ![Main dialog](/docs/screenshot1.png?raw=true "Screenshot 1") 9 | ![Block list](/docs/screenshot2.png?raw=true "Screenshot 2") 10 | ![Block list output](/docs/screenshot4.png?raw=true "Screenshot 4") 11 | ![Unblock list](/docs/screenshot3.png?raw=true "Screenshot 3") 12 | ![Unblock list output](/docs/screenshot5.png?raw=true "Screenshot 5") 13 | 14 | -------------------------------------------------------------------------------- /adb-block-cli: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | get_packages() { adb shell pm list packages -e | sort -t";" -k2 | sed 's/package://g' | sed s/\\r\$// | sed 's/.*/& &/' | sed 's/$/ off/g'; } 3 | os_version() { adb shell getprop ro.build.version.release | sed s/\\r\$//; } 4 | select_packages_block() { dialog --checklist Packages 24 80 20 $(get_packages) 2>.packages; sed -e 's/\s\+/\n/g' -i .packages; sed -i -e '$a\' -i .packages; } 5 | select_packages_unblock() { dialog --checklist Packages 24 80 20 $(cat .blocked_packages_cli) 2>.delpack; sed -e 's/\s\+/\n/g' -i .delpack; sed -i -e '$a\' -i .delpack; } 6 | check_file() { touch .blocked_packages_cli; } 7 | status_dialog_blocked() { dialog --msgbox "$(cat .status)" 24 80; } 8 | status_dialog_unblocked() { dialog --msgbox "$(cat .status)" 24 80; } 9 | unsupported() { if [[ $(os_version) > 5 ]]; then dialog --title 'Message' --msgbox 'Cannot unblock on newer OS versions' 5 60; exit; fi; } 10 | disable_packages() { 11 | # can be done with xargs if you don't like this way 12 | for package in $@; do 13 | if [[ $(os_version) -lt 5 ]]; then 14 | adb shell pm block "$package" 15 | printf "$package $package off \n" >> .blocked_packages_cli 16 | else 17 | adb shell pm uninstall -k --user 0 "$package" 18 | printf "$package $package off \n" >> .blocked_packages_cli 19 | fi 20 | done 21 | } 22 | enable_packages() { 23 | # can be done with xargs if you don't like this way 24 | while IFS= read -r package; do 25 | if [[ $(os_version) -lt 5 ]]; then 26 | adb shell pm unblock "$package" 27 | sed '/'$package'/d' -i .blocked_packages_cli 28 | else 29 | adb shell cmd package install-existing "$package" 30 | sed '/'$package'/d' -i .blocked_packages_cli 31 | fi 32 | done 33 | } 34 | block() { 35 | check_file 36 | select_packages_block 37 | disable_packages $(cat .packages) > .status 38 | status_dialog_blocked; 39 | } 40 | unblock() { 41 | #unsupported 42 | check_file 43 | select_packages_unblock 44 | cat .delpack | enable_packages > .status 45 | status_dialog_unblocked; 46 | } 47 | dialog --menu "Would you like to block or unblock?" 24 80 24 "Block" "Block a package" "Unblock" "Unblock a package" 2>.answer 48 | if [[ $(cat .answer) == "Block" ]]; 49 | then 50 | block 51 | else 52 | unblock 53 | fi 54 | -------------------------------------------------------------------------------- /adb-block: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | get_packages() { adb shell pm list packages -e | sort -t";" -k2 | sed 's/package:/FALSE\n/g' | sed s/\\r\$//; } 3 | os_version() { adb shell getprop ro.build.version.release | sed s/\\r\$//; } 4 | select_packages_block() { yad --list --checklist --column "Block" --column "Package" --separator "" --print-column=2 --width=600 --height=400; } 5 | select_packages_unblock() { yad --list --checklist --column "Unblock" --column "Package" --separator "" --print-column=2 --width=600 --height=400; } 6 | check_file() { touch .blocked_packages; } 7 | sanitize_file() { sed '/^$/d' -i .blocked_packages; } 8 | status_dialog_blocked() { yad --title "Blocked packages" --text-info --width=600 --height=400 --button=gtk-ok:0; } 9 | status_dialog_unblocked() { yad --title "Unblocked packages" --text-info --width=600 --height=400 --button=gtk-ok:0; } 10 | unsupported() { if [[ $(os_version) > 5 ]]; then yad --title "adb-block" --button=Ok:1 --text "Unblocking is unsupported on newer OS versions"; exit; fi; } 11 | disable_packages() { 12 | # can be done with xargs if you don't like this way 13 | for package in $@; do 14 | if [[ $(os_version) -lt 5 ]]; then 15 | adb shell pm block "$package" 16 | printf "FALSE\n$package\n" >> .blocked_packages 17 | else 18 | adb shell pm uninstall -k --user 0 "$package" 19 | printf "FALSE\n$package\n" >> .blocked_packages 20 | fi 21 | done 22 | } 23 | enable_packages() { 24 | # can be done with xargs if you don't like this way 25 | while IFS= read -r package; do 26 | if [[ $(os_version) -lt 5 ]]; then 27 | adb shell pm unblock "$package" 28 | sed -n '/'$package'/{n;x;d;};x;1d;p;${x;p;}' -i .blocked_packages 29 | else 30 | adb shell cmd package install-existing "$package" 31 | sed -n '/'$package'/{n;x;d;};x;1d;p;${x;p;}' -i .blocked_packages 32 | fi 33 | done 34 | } 35 | block() { 36 | check_file 37 | sanitize_file 38 | disable_packages $(get_packages | select_packages_block) > .status 39 | cat .status | status_dialog_blocked 40 | sanitize_file; 41 | } 42 | unblock() { 43 | #unsupported 44 | check_file 45 | sanitize_file 46 | cat .blocked_packages | select_packages_unblock | enable_packages > .status 47 | cat .status | status_dialog_unblocked 48 | check_file 49 | sanitize_file; 50 | } 51 | yad --image "dialog-question" \ 52 | --title "adb-block" \ 53 | --button=Block:1 \ 54 | --button=Unblock:2 \ 55 | --text "Would you like to block or unblock?" 56 | ret=$? 57 | if [[ $ret == 1 ]]; then 58 | block 59 | elif [[ $ret == 2 ]]; then 60 | unblock 61 | elif [[ $ret == 0 ]]; then 62 | exit 63 | fi 64 | --------------------------------------------------------------------------------