-
Notifications
You must be signed in to change notification settings - Fork 1
/
XiaomiADB.sh
239 lines (203 loc) Β· 6.99 KB
/
XiaomiADB.sh
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
LOG_FILE="/tmp/xiaomiadb.log"
print_banner() {
local banner=(
"******************************************"
"* Xiaomi-ADB *"
"* Xiaomi Device Customizer with ADB *"
"* v1.1.0 *"
"* ---------------------------- *"
"* by @ImKKingshuk *"
"* Github- https://github.com/ImKKingshuk *"
"******************************************"
)
local width=$(tput cols)
for line in "${banner[@]}"; do
printf "%*s\n" $(((${#line} + width) / 2)) "$line"
done
echo
}
log_info() {
echo "[INFO] $1" | tee -a "$LOG_FILE"
}
log_error() {
echo "[ERROR] $1" | tee -a "$LOG_FILE" >&2
}
check_root() {
if [ "$(id -u)" -ne 0 ]; then
log_error "This script must be run as root."
exit 1
fi
}
backup_file() {
local file="$1"
if [ -f "$file" ]; then
cp "$file" "${file}.bak"
log_info "Backup created for $file"
fi
}
modify_xml_property() {
local xml_file="$1"
local property="$2"
local value="$3"
local line_no
line_no=$(grep -n "$property" "$xml_file" | awk -F: '{print $1}')
if [ "$line_no" ]; then
log_info "Found $property at line $line_no"
sed -i "/$property/s/false/$value/" "$xml_file"
else
log_info "$property not found, inserting..."
sed -i "3a \ \ \ \ <boolean name=\"$property\" value=\"$value\" />" "$xml_file"
fi
grep "$property" "$xml_file" | tee -a "$LOG_FILE"
}
restart_service() {
local service_name="$1"
pkill -9 "$service_name" && log_info "$service_name service restarted"
}
disable_ads() {
local xml_file="/data/data/com.miui.securitycenter/shared_prefs/remote_provider_preferences.xml"
log_info "Disabling ads in the Security App..."
backup_file "$xml_file"
modify_xml_property "$xml_file" "ads_enabled" "false"
}
enable_all_permissions() {
log_info "Enabling all permissions for all apps..."
pm grant com.miui.securitycenter android.permission.READ_LOGS
pm grant com.miui.securitycenter android.permission.ACCESS_FINE_LOCATION
pm grant com.miui.securitycenter android.permission.ACCESS_COARSE_LOCATION
pm grant com.miui.securitycenter android.permission.READ_CONTACTS
pm grant com.miui.securitycenter android.permission.WRITE_CONTACTS
pm grant com.miui.securitycenter android.permission.CALL_PHONE
pm grant com.miui.securitycenter android.permission.READ_PHONE_STATE
pm grant com.miui.securitycenter android.permission.READ_CALL_LOG
pm grant com.miui.securitycenter android.permission.WRITE_CALL_LOG
pm grant com.miui.securitycenter android.permission.SEND_SMS
pm grant com.miui.securitycenter android.permission.RECEIVE_SMS
log_info "All permissions enabled for com.miui.securitycenter"
}
bypass_battery_optimization() {
log_info "Bypassing battery optimization for selected apps..."
powercfg=$(dumpsys deviceidle | grep "whitelist=" | sed 's/whitelist=//')
app_list="com.miui.securitycenter com.android.settings"
for app in $app_list; do
if [[ $powercfg != *"$app"* ]]; then
dumpsys deviceidle whitelist +$app
log_info "Bypassed battery optimization for $app"
else
log_info "$app is already bypassing battery optimization"
fi
done
}
unlock_dev_options() {
log_info "Unlocking hidden developer options..."
settings put global development_settings_enabled 1
settings put global adb_enabled 1
settings put global verity_mode 0
log_info "Developer options unlocked"
}
disable_miui_optimization() {
log_info "Disabling MIUI/HyperOS optimization..."
settings put global miui_optimization 0
log_info "MIUI/HyperOS optimization disabled"
}
enable_third_party_themes() {
log_info "Enabling third-party themes..."
settings put secure theme_authorization 1
log_info "Third-party themes enabled"
}
print_banner
check_root
echo "Select an option:"
echo "1. Enable USB debugging"
echo "2. Enable Fastboot"
echo "3. Enable Installation via USB"
echo "4. Disable install intercept"
echo "5. Disable Ads in Security App"
echo "6. Enable All Permissions for Security App"
echo "7. Bypass Battery Optimization for Selected Apps"
echo "8. Unlock Hidden Developer Options"
echo "9. Disable MIUI Optimization"
echo "10. Enable Third-Party Themes"
echo "11. Apply all modifications"
echo "12. Exit"
read -rp "Enter your choice: " choice
XML_FILE="/data/data/com.miui.securitycenter/shared_prefs/remote_provider_preferences.xml"
case $choice in
1)
log_info "Enabling USB debugging (Security settings)..."
RESULT=$(getprop persist.security.adbinput)
if [[ $RESULT != "1" ]]; then
setprop persist.security.adbinput 1 && log_info "USB debugging (Security settings) enabled"
else
log_info "USB debugging (Security settings) is already enabled"
fi
;;
2)
log_info "Enabling Fastboot..."
RESULT=$(getprop persist.fastboot.enable)
if [[ $RESULT != "1" ]]; then
setprop persist.fastboot.enable 1 && log_info "Fastboot enabled"
else
log_info "Fastboot is already enabled"
fi
;;
3)
log_info "Modifying $XML_FILE for USB installation..."
backup_file "$XML_FILE"
modify_xml_property "$XML_FILE" "security_adb_install_enable" "true"
;;
4)
log_info "Modifying $XML_FILE to disable install intercept..."
backup_file "$XML_FILE"
modify_xml_property "$XML_FILE" "permcenter_install_intercept_enabled" "false"
;;
5)
disable_ads
;;
6)
enable_all_permissions
;;
7)
bypass_battery_optimization
;;
8)
unlock_dev_options
;;
9)
disable_miui_optimization
;;
10)
enable_third_party_themes
;;
11)
log_info "Applying all modifications..."
RESULT=$(getprop persist.security.adbinput)
if [[ $RESULT != "1" ]]; then
setprop persist.security.adbinput 1 && log_info "USB debugging (Security settings) enabled"
fi
RESULT=$(getprop persist.fastboot.enable)
if [[ $RESULT != "1" ]]; then
setprop persist.fastboot.enable 1 && log_info "Fastboot enabled"
fi
backup_file "$XML_FILE"
modify_xml_property "$XML_FILE" "security_adb_install_enable" "true"
modify_xml_property "$XML_FILE" "permcenter_install_intercept_enabled" "false"
disable_ads
enable_all_permissions
bypass_battery_optimization
unlock_dev_options
disable_miui_optimization
enable_third_party_themes
restart_service "com.miui.securitycenter.remote"
;;
12)
log_info "Exiting..."
exit 0
;;
*)
log_error "Invalid choice. Exiting..."
exit 1
;;
esac
log_info "Done!"