-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebloater.sh
More file actions
executable file
·159 lines (117 loc) · 3.9 KB
/
Copy pathdebloater.sh
File metadata and controls
executable file
·159 lines (117 loc) · 3.9 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
clear
echo "================================================================================"
echo "============================ Welcome to Android Debloater ======================"
echo "================================================================================"
echo ""
# Initialize variables and package files
BLOATWARE_FILE=bloatware_list/android_google.txt
DEVICE_PACKAGE_FILE=packages.pkg
UNINSTALL_PACKAGE_FILE=uninstall.pkg
# Helper to preety print headers
function print_header() {
now=$(date +"%I:%M:%S")
echo -e "${BOLD}[$now] $1 ${RESET}"
}
# Helper to preety print messages
function print_message() {
# Prints 12 spaces to match indentation of the header
# Aligns the content to header
echo " $1"
}
# Helper to check if a line is present in the given list of lines
function exists_in_list() {
echo "$1" | grep -F -q -x "$2"
}
# Utility to find bloatware packages currently installed in the device
function check_bloatware_packages() {
DEVICE_PACKAGES=$1
BLOATWARE_PACKAGES=$(<$2)
OUTPUT_FILE=$3
while read -r line
do
if exists_in_list "$BLOATWARE_PACKAGES" "$line"; then
echo $line >> $OUTPUT_FILE
fi
done < $DEVICE_PACKAGES
}
# Utility to perform uninstallation of packages
function uninstall-packages() {
UNINSTALL_PACKAGES=$1
while read -r package <&3
do
print_header "Processing package: $package"
# Trying to uninstall package system-wide
adb shell pm uninstall $package > /dev/null
if [ $? -eq 0 ]; then
print_message "Successfully uninstalled"
else
# Trying to uninstall package for current user
adb shell pm uninstall --user 0 $package > /dev/null
if [ $? -eq 0 ]; then
print_message "Successfully uninstalled for current user"
else
# Uninstalling failed, try to disable package
adb shell pm clear $package > /dev/null
adb shell pm disable-user $package > /dev/null
if [ $? -eq 0 ]; then
print_message "Successfully disabled for current user"
else
print_message "Failed to process package"
fi
fi
fi
echo ""
done 3< $UNINSTALL_PACKAGES
}
# Option for the user to determine bloatware list to use
echo "Select bloatware list to use depending on the OS:"
echo "[1] Stock Android with Google Bloatware"
echo "[2] Xiaomi MIUI/HyperOs"
echo "[3] Samsung OneUI"
echo -n ": "
read option
# Configure correct bloatware list to use based on user selection
if [ "$option" -eq 1 ]; then
BLOATWARE_FILE=bloatware_list/android_google.txt
elif [ "$option" -eq 2 ]; then
BLOATWARE_FILE=bloatware_list/xiaomi.txt
elif [ "$option" -eq 3 ]; then
BLOATWARE_FILE=bloatware_list/samsung.txt
else
echo "Invalid selection"
exit
fi
echo ""
print_header "Using bloatware file: $BLOATWARE_FILE"
echo ""
# Check if we have any connected devices
print_header "Getting Device list..."
DEVICE_ID=$(adb shell getprop ro.serialno)
if [ $? -eq 0 ]; then
print_message "Found: $DEVICE_ID"
else
exit
fi
echo ""
# Fetch list of enabled packages from current device
print_header "Gathering list of installed packages..."
adb shell pm list packages -e > $DEVICE_PACKAGE_FILE
sed -i 's/package://' $DEVICE_PACKAGE_FILE
echo ""
# Find bloatware packages installed in the current device
print_header "Preparing list of packages to uninstall..."
check_bloatware_packages $DEVICE_PACKAGE_FILE $BLOATWARE_FILE $UNINSTALL_PACKAGE_FILE
echo ""
# Unintsall detected bloatware packages
print_header "Uninstalling packages..."
echo ""
uninstall-packages $UNINSTALL_PACKAGE_FILE
print_header "Done"
echo ""
# Perform cleanup and exit
print_header "Performing Cleanup..."
rm -f $DEVICE_PACKAGE_FILE
rm -f $UNINSTALL_PACKAGE_FILE
# Stop adb server
adb kill-server