-
Notifications
You must be signed in to change notification settings - Fork 3
/
adb-block-cli
executable file
·53 lines (53 loc) · 1.98 KB
/
adb-block-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
get_packages() { adb shell pm list packages -e | sort -t";" -k2 | sed 's/package://g' | sed s/\\r\$// | sed 's/.*/& &/' | sed 's/$/ off/g'; }
os_version() { adb shell getprop ro.build.version.release | sed s/\\r\$//; }
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; }
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; }
check_file() { touch .blocked_packages_cli; }
status_dialog_blocked() { dialog --msgbox "$(cat .status)" 24 80; }
status_dialog_unblocked() { dialog --msgbox "$(cat .status)" 24 80; }
unsupported() { if [[ $(os_version) > 5 ]]; then dialog --title 'Message' --msgbox 'Cannot unblock on newer OS versions' 5 60; exit; fi; }
disable_packages() {
# can be done with xargs if you don't like this way
for package in $@; do
if [[ $(os_version) -lt 5 ]]; then
adb shell pm block "$package"
printf "$package $package off \n" >> .blocked_packages_cli
else
adb shell pm uninstall -k --user 0 "$package"
printf "$package $package off \n" >> .blocked_packages_cli
fi
done
}
enable_packages() {
# can be done with xargs if you don't like this way
while IFS= read -r package; do
if [[ $(os_version) -lt 5 ]]; then
adb shell pm unblock "$package"
sed '/'$package'/d' -i .blocked_packages_cli
else
adb shell cmd package install-existing "$package"
sed '/'$package'/d' -i .blocked_packages_cli
fi
done
}
block() {
check_file
select_packages_block
disable_packages $(cat .packages) > .status
status_dialog_blocked;
}
unblock() {
#unsupported
check_file
select_packages_unblock
cat .delpack | enable_packages > .status
status_dialog_unblocked;
}
dialog --menu "Would you like to block or unblock?" 24 80 24 "Block" "Block a package" "Unblock" "Unblock a package" 2>.answer
if [[ $(cat .answer) == "Block" ]];
then
block
else
unblock
fi