-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebloater.bat
More file actions
executable file
·162 lines (119 loc) · 3.75 KB
/
debloater.bat
File metadata and controls
executable file
·162 lines (119 loc) · 3.75 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
160
161
162
@echo off
setlocal enabledelayedexpansion
cls
echo ========================================================================================
echo ============================= Welcome to Android Debloater =============================
echo ========================================================================================
echo.
:: Initialize variables and package files
SET BLOATWARE_FILE=bloatware_list/android_google.txt
SET DEVICE_PACKAGE_FILE=packages.pkg
SET UNINSTALL_PACKAGE_FILE=uninstall.pkg
:: 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
set /p option= ": "
echo.
:: Configure correct bloatware list to use based on user selection
IF "%option%" EQU "1" GOTO :Android
IF "%option%" EQU "2" GOTO :Xiaomi
IF "%option%" EQU "3" GOTO :Samsung
:: Fall-through for invalid selection
echo Invalid selection
echo.
exit /b 1
:Android
SET BLOATWARE_FILE=bloatware_list/android_google.txt
GOTO :CONTINUE
:Xiaomi
SET BLOATWARE_FILE=bloatware_list/xiaomi.txt
GOTO :CONTINUE
:Samsung
SET BLOATWARE_FILE=bloatware_list/samsung.txt
GOTO :CONTINUE
:CONTINUE
call :PrintHeader "Using bloatware file: %BLOATWARE_FILE%"
echo.
:: Check if we have any connected devices
call :PrintHeader "Getting Device list..."
set "DEVICE_ID="
for /f "delims=" %%i in ('adb shell getprop ro.serialno') do (
set "DEVICE_ID=%%i"
)
IF DEFINED DEVICE_ID (
call :PrintMessage "Found: %DEVICE_ID%"
) ELSE (
echo.
exit /b 0
)
echo.
:: Fetch list of enabled packages from current device
call :PrintHeader "Gathering list of installed packages..."
adb shell pm list packages -e > %DEVICE_PACKAGE_FILE%
echo.
:: Find bloatware packages installed in the current device
call :PrintHeader "Preparing list of packages to uninstall..."
call :CheckBloatwarePackages %DEVICE_PACKAGE_FILE%, %BLOATWARE_FILE%, %UNINSTALL_PACKAGE_FILE%
echo.
:: Unintsall detected bloatware packages
call :PrintHeader "Uninstalling packages..."
echo.
call :UninstallPackages %UNINSTALL_PACKAGE_FILE%
call :PrintHeader "Done"
echo.
:: Perform cleanup and exit
call :PrintHeader "Performing Cleanup..."
del %DEVICE_PACKAGE_FILE%
del %UNINSTALL_PACKAGE_FILE%
echo.
:: Stop adb server
adb kill-server
GOTO :EOF
:: Helper to preety print headers
:PrintHeader
set "NOW=%time%"
set "TIME=%NOW:~0,8%"
echo [%TIME%] %~1
exit /b 0
:: Helper to preety print headers
:PrintMessage
:: Prints 12 spaces to match indentation of the header
:: Aligns the content to header
echo %~1
exit /b 0
:: Utility to find bloatware packages currently installed in the device
:CheckBloatwarePackages
set DEVICE_PACKAGES=%~1
set BLOATWARE_PACKAGES=%~2
set OUTPUT_FILE=%~3
FOR /f "tokens=*" %%A in (%BLOATWARE_PACKAGES%) do (
find "%%A" %DEVICE_PACKAGES% > nul && ( echo %%A >> %OUTPUT_FILE% )
)
exit /b 0
:: Utility to perform uninstallation of packages
:UninstallPackages
SET UNINSTALL_PACKAGES=%~1
FOR /f "tokens=*" %%A in (%UNINSTALL_PACKAGES%) do (
call :PrintHeader "Processing package: %%A"
:: Trying to uninstall package system-wide
adb shell pm uninstall %%A 1>nul 2>nul && (
call :PrintMessage "Successfully uninstalled"
) || (
:: Trying to uninstall package for current user
adb shell pm uninstall --user 0 %%A 1>nul 2>nul && (
call :PrintMessage "Successfully uninstalled for current user"
) || (
:: Uninstalling failed, try to disable package
adb shell pm clear %%A 1>nul 2>nul
adb shell pm disable-user %%A 1>nul 2>nul && (
call :PrintMessage "Successfully disabled for current user"
) || (
call :PrintMessage "Failed to process package"
)
)
)
echo.
)
exit /b 0