Skip to content

Instantly share code, notes, and snippets.

@opus-x
Last active April 22, 2024 21:37
Show Gist options
  • Save opus-x/b68a5fe82751d846422f62e602d8b011 to your computer and use it in GitHub Desktop.
Save opus-x/b68a5fe82751d846422f62e602d8b011 to your computer and use it in GitHub Desktop.
Debloat and speed-up Xiaomi Pad 5 by disabling apps and limiting apps starting in the background (EU model), Tested and working but to be finetuned.
@echo off
rem usb connection
echo =======================================
echo Starting Android Debug Bridge Daemon...
echo =======================================
2>nul adb kill-server
adb start-server
echo | set /p="Checking for a connected device... "
>nul adb get-state
if errorlevel 1 (
echo error
goto :EOF
) else (
echo okay
)
echo | set /p="Verifying device type... "
for /f "tokens=2,3 delims=/" %%i in ('adb shell getprop ^| findstr /i "ro.bootimage.build.fingerprint"') do (
echo %%i %%j | >nul findstr /i "nabu_eea nabu:12"
)
if not errorlevel 0 (
echo error, no Mi Pad 5 [nabu_eea/muiu 12]
goto :EOF
) else (
echo Okay, Mi Pad 5 [nabu_eea/muiu 12]
)
rem com.miui.powerkeeper will not be disabled
set "_SA_DISABLE=com.android.chrome com.android.hotwordenrollment.okgoogle com.android.hotwordenrollment.xgoogle com.android.internal com.android.settings.overlay com.android.systemui.gesture com.android.systemui.navigation com.android.systemui.overlay com.bsp.catchlog com.google.android.apps.googleassistant com.google.android.apps.turbo com.google.android.apps.wellbeing com.google.android.calendar com.google.android.feedback com.google.android.gm com.google.android.googlequicksearchbox com.mi.android.globalFileexplorer com.mi.healthglobal com.miui.analytics com.miui.backup com.miui.bugreport com.miui.cleaner com.miui.cloudbackup com.miui.cloudservice com.miui.daemon com.miui.gallery com.miui.hybrid com.miui.micloudsync com.miui.miservice com.miui.msa.global com.miui.player com.miui.videoplayer com.miui.weather2 com.miui.wmsvc com.xiaomi.account com.xiaomi.mi_connect_service com.xiaomi.miaudiovisual com.xiaomi.micloud.sdk com.xiaomi.miplay_client com.xiaomi.payment com.xiaomi.simactivate.service org.mipay.android.manager com.xiaomi.powerchecker"
rem turn on google services since gmail was disabled
set "_SA_ENABLE=com.google.android.gms"
rem disable permission RECEIVE_BOOT_COMPLETED for system apps
set "_SA_BACKGROUND_OK=com.google.android.gms android.aosp android.miui android.overlay android.qvaoverlay com.android com.bsp.catchlog com.fido.asm com.google com.lbe.security.miui com.mi.emapal com.mi.globallayout com.milink.service com.miui.audioeffect com.miui.audiomonitor com.miui.core com.miui._home com.miui.face com.miui.freeform com.miui.guardprovider com.miui.hybrid com.miui.mishare com.miui.misound com.miui.notes com.miui.notification com.miui.phone com.miui.phrase com.miui.rom com.miui.screenshot com.miui.security com.miui.settings com.miui.system com.miui.systemui com.miui.wmsvc com.modemdebug com.qti com.qualcomm com.tencent com.xiaomi.barrage com.xiaomi.bluetooth com.xiaomi.devauth com.xiaomi.discover com.xiaomi.finddevice com.xiaomi.joyose com.xiaomi.midrop com.xiaomi.misettings com.xiaomi.xmsf miui.systemui.plugin org.codeaurora.ims org.ifaa.aidl.manager vendor.qti"
set "_UA_BACKGROUND_OK=app.greyshirts.firewall au.com.shiftyjelly.pocketcasts biz.codespark.xcalendarapp ch.protonmail.android color.dev.com.whatsremoved com.agooday.fullscreengestures com.airbnb.android com.amazon.windowshop com.android.vending.billing.InAppBillingService.BINN com.anydo com.b_lam.resplash com.bol.shop com.brother.printservice com.brusselsairlines.bmobile com.callpod.android_apps.keeper com.conena.navigation.gesture.control com.daily.journal.diary.lock.mood.tracker.free com.dailymotion.dailymotion com.dashlane com.dhlparcel.nl com.discord com.dp.sysmonitor.app com.drilens.wamr com.ebay.mobile com.fb.fluid com.feresr.walpy com.funda.two com.google.android.apps.authenticator2 com.google.android.apps.chromecast.app com.google.android.apps.meetings com.google.android.apps.photos com.google.android.apps.plus com.google.android.apps.podcasts com.google.android.apps.tachyon com.google.android.apps.tasks com.google.android.apps.work.clouddpc com.google.android.apps.youtube.music com.google.android.keep com.google.android.sambadocumentsprovider com.google.android.videos com.habitnow com.itunestoppodcastplayer.app com.ivianuu.oneplusgestures com.kayak.android com.kbc.mobile.android.phone.kbc com.korovan.kpass com.kunzisoft.keepass.free com.lexa.fakegps com.libin.notification com.microsoft.appmanager com.microsoft.emmx com.microsoft.office.outlook com.microsoft.teams com.microsoft.todos com.mo2o.vueling com.mobile.unseenchat.nolastseen com.ncaferra.podcast com.odilo.bibliotheek com.paypal.android.p2pmobile com.podbean.app.podcast com.podcast.podcasts com.podimo com.reneph.passwordsafe com.ryanair.discovery com.siber.roboform com.skype.raider com.skypicker.main com.softinit.iquitos.mainapp com.splendapps.splendo com.spotify.music com.ss.edgegestures com.stingray.galaxie.android com.stresscodes.wallp.pro com.takeaway.android com.tdev.tswipe com.tempmail com.tenqube.notisave com.teslacoilsw.launcher com.tinoooapp.gravitygestures com.todoist com.tripit com.twitter.android com.ulsoft.tusk com.viaplay.android com.vimeo.android.videoapp com.wanderlog.android com.whatsapp com.windscribe.vpn com.yocto.wenote com.youfone com.zacharee1.systemuituner de.danoeh.antennapod deezer.android.app eu.faircode.email eu.thedarken.sdm eu.toneiv.ubktouch fm.castbox.audiobook.radio.podcast io.enpass.app io.lambus.app io.nextdns.NextDNS juloo.keyboard2 keepass2android.keepass2android kr.co.a7to80.myremind me.hisn.mygesture me.proton.android.calendar natuurhuisje.huurders net.mylifeorganized.mlo net.skyscanner.android.main net.xiaomiui.miuiupdater ninja.sesame.app.edge nl.asnbank.asnbankieren nl.bibliotheek.tijdschriften nl.cz.app nl.greenchoice.android nl.nlziet nl.nos.app nl.nos.jeugdjournaal nl.oneshoe nl.opzet.zcalendar.zrd nl.rabomobiel nl.scoupy.apps.scoupy nl.socialdeal.spontaan nl.streamgroup nl.topicus.geon.parrocomm nl.tpp.mobile.android nl.uitzendinggemist org.jitsi.meet org.pocketworkstation.pckeyboard org.thoughtcrime.securesms org.telegram.messenger org.thunderdog.challegram org.torproject.torservices org.withouthat.acalendarplus rk.android.app.notificationhistory sanity.podcast.freak todolist.scheduleplanner.dailyplanner.todo.reminders tv.bvn.app us.zoom.videomeetings nl.squla.unitab nl.topicus.unicorn.android.gynzykids nl.wrts.mobiel com.aftership com.ups.mobile"
for %%u in (0, 10) do (
rem disable stock apps
echo ============================================
echo Re-enable stock system apps for user %%u...
echo ============================================
for /f "tokens=2 delims=:" %%i in ('adb shell pm list packages --user %%u -s -d') do (>nul adb shell pm enable --user %%u %%i && echo ENABLED: %%i)
if defined _SA_DISABLE if defined _SA_ENABLE (
echo ============================================
echo Disabling stock system apps for user %%u...
echo ============================================
for /f "tokens=2 delims=:" %%i in ('adb shell pm list packages --user %%u -s -e ^| findstr /i "%_SA_DISABLE%"') do (>nul adb shell pm disable-user --user %%u %%i && echo DISABLED: %%i)
for /f "tokens=2 delims=:" %%i in ('adb shell pm list packages --user %%u -s -d ^| findstr /i "%_SA_ENABLE%"') do (>nul adb shell pm enable --user %%u %%i && echo ENABLED: %%i)
)
rem disable gestures and navigation
echo =========================================================
echo Disabling some Android and MIUI overlays for user %%u...
echo =========================================================
adb shell cmd overlay disable --user %%u com.android.internal.systemui.navbar.gestural
adb shell cmd overlay disable --user %%u com.android.internal.systemui.navbar.threebutton
adb shell cmd overlay disable --user %%u com.android.internal.systemui.onehanded.gestural
adb shell cmd overlay disable --user %%u com.android.systemui.gesture.line.overlay
adb shell cmd overlay disable --user %%u com.android.systemui.navigation.bar.overlay
adb shell pm disable-user --user %%u com.android.internal.systemui.navbar.gestural
adb shell pm disable-user --user %%u com.android.internal.systemui.navbar.threebutton
adb shell pm disable-user --user %%u com.android.internal.systemui.onehanded.gestural
adb shell pm disable-user --user %%u com.android.systemui.gesture.line.overlay
adb shell pm disable-user --user %%u com.android.systemui.navigation.bar.overlay
rem adjust some settings
echo ========================================
echo Adjusting some settings for user %%u...
echo ========================================
rem default = 3
adb shell settings put global --user %%u audio_safe_volume_state 0
rem default = 0
adb shell settings put global --user %%u audio_visual_screen_lock_on 0
rem default = null
adb shell settings put global --user %%u ble_scan_always_enabled 0
rem default = device_default
adb shell settings put global --user %%u cached_apps_freezer enabled
adb shell settings put global --user %%u backup_enabled 1
adb shell settings put global --user %%u force_fsg_nav_bar 1
adb shell settings put global --user %%u hide_gesture_line 1
adb shell settings put global --user %%u long_press_home_key null
rem default = 0
adb shell settings put global --user %%u nav_button_pos -1
adb shell settings put global --user %%u one_handed_mode_activated 0
adb shell settings put global --user %%u one_handed_mode_enabled 0
rem default = null, for samsung = 1,1
adb shell settings put global --user %%u restricted_device_performance 0,0
rem default = null
adb shell settings put global --user %%u sem_enhanced_cpu_responsiveness 1
rem default = 0
adb shell settings put global --user %%u speed_mode_enable 1
rem default = 1
adb shell settings put global --user %%u wifi_scan_always_enabled 0
rem default = null
adb shell settings put secure --user %%u adaptive_sleep 1
adb shell settings put secure --user %%u backup_enabled 1
adb shell settings put secure --user %%u double_tap_to_sleep 1
adb shell settings put secure --user %%u double_tap_to_wake 1
adb shell settings put secure --user %%u double_tap_to_wake_up 1
adb shell settings put secure --user %%u hush_gesture_used 0
adb shell settings put secure --user %%u one_handed_mode_activated 0
adb shell settings put secure --user %%u one_handed_mode_enabled 0
adb shell settings put secure --user %%u screensaver_activate_on_dock 0
adb shell settings put secure --user %%u screensaver_activate_on_sleep 0
adb shell settings put secure --user %%u screensaver_enabled 0
rem default = null
adb shell settings put secure --user %%u show_notification_snooze 1
adb shell settings put secure --user %%u silence_gesture 0
adb shell settings put secure --user %%u skip_gesture 0
adb shell settings put secure --user %%u volume_hush_gesture 0
adb shell settings put secure --user %%u unsafe_volume_music_active_ms 1
adb shell settings put secure --user %%u wake_gesture_enabled 0
rem default = null
adb shell settings put system --user %%u intelligent_sleep_mode 1
adb shell settings put system --user %%u lift_to_wake 0
adb shell settings put system --user %%u long_press_home_key null
rem default = null
adb shell settings put system --user %%u multicore_packet_scheduler 1
rem default = null
adb shell settings put system --user %%u nearby_scanning_enabled 0
rem default = null
adb shell settings put system --user %%u nearby_scanning_permission_allowed 0
rem defualt = 0 (-1, 0, 1)
adb shell settings put system --user %%u screen_auto_brightness_adj 0
rem remove some apps
adb shell pm disable-user --user %%u com.xiaomi.payment
adb uninstall --user %%u cn.wps.moffice_eng
adb uninstall --user %%u cn.wps.xiaomi.abroad.lite
rem enable write_secure_settings for users
echo ====================================================================================
echo Revoking user apps requesting WRITE_SECURE_SETTINGS this permission for user %%u...
echo ====================================================================================
for /f "tokens=2 delims=:" %%i in ('adb shell pm list packages --user %%u -3') do (adb shell dumpsys package %%i | >nul findstr /i "android.permission.WRITE_SECURE_SETTINGS" && (adb shell pm revoke --user %%u %%i android.permission.WRITE_SECURE_SETTINGS && echo REVOKED: %%i))
echo ====================================================================================
echo Granting user apps requesting WRITE_SECURE_SETTINGS this permission for user %%u]...
echo ====================================================================================
for /f "tokens=2 delims=:" %%i in ('adb shell pm list packages --user %%u -3') do (adb shell dumpsys package %%i | >nul findstr /i "android.permission.WRITE_SECURE_SETTINGS" && (adb shell pm grant --user %%u %%i android.permission.WRITE_SECURE_SETTINGS && echo GRANTED: %%i))
)
rem disable start for specified apps
echo ===========================================================================
echo Settings default permissions for apps to run in background for all users...
echo ===========================================================================
>nul adb shell appops read-settings
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_ANY_IN_BACKGROUND ignore') do (>nul adb shell appops set --user %%u %%i RUN_ANY_IN_BACKGROUND default && echo DEFAULT: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_IN_BACKGROUND ignore') do (>nul adb shell appops set --user %%u %%i RUN_IN_BACKGROUND default && echo DEFAULT: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_ANY_IN_BACKGROUND allow') do (>nul adb shell appops set --user %%u %%i RUN_ANY_IN_BACKGROUND default && echo DEFAULT: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_IN_BACKGROUND allow') do (>nul adb shell appops set --user %%u %%i RUN_IN_BACKGROUND default && echo DEFAULT: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
if defined _SA_BACKGROUND_OK if defined _UA_BACKGROUND_OK (
echo =============================================================
echo Disable permissions for apps to run in background [step 1]...
echo =============================================================
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_ANY_IN_BACKGROUND allow ^| findstr /i /v "%_SA_BACKGROUND_OK% %_UA_BACKGROUND_OK%"') do (>nul adb shell appops set --user %%u %%i RUN_ANY_IN_BACKGROUND ignore && echo IGNORE: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_ANY_IN_BACKGROUND default ^| findstr /i /v "%_SA_BACKGROUND_OK% %_UA_BACKGROUND_OK%"') do (>nul adb shell appops set --user %%u %%i RUN_ANY_IN_BACKGROUND ignore && echo IGNORE: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
echo =============================================================
echo Disable permissions for apps to run in background [step 2]...
echo =============================================================
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_IN_BACKGROUND allow ^| findstr /i /v "%_SA_BACKGROUND_OK% %_UA_BACKGROUND_OK%"') do (>nul adb shell appops set --user %%u %%i RUN_IN_BACKGROUND ignore && echo IGNORE: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_IN_BACKGROUND default ^| findstr /i /v "%_SA_BACKGROUND_OK% %_UA_BACKGROUND_OK%"') do (>nul adb shell appops set --user %%u %%i RUN_IN_BACKGROUND ignore && echo IGNORE: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
)
if defined _UA_BACKGROUND_OK (
echo ==================================================================
echo Enable whitelisted user apps to run in background for all users...
echo ==================================================================
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_ANY_IN_BACKGROUND ignore ^| findstr /i "%_UA_BACKGROUND_OK% %_SA_BACKGROUND_OK%"') do (>nul adb shell appops set --user %%u %%i RUN_ANY_IN_BACKGROUND allow && echo ALLOW: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_IN_BACKGROUND ignore ^| findstr /i "%_UA_BACKGROUND_OK% %_SA_BACKGROUND_OK%"') do (>nul adb shell appops set --user %%u %%i RUN_IN_BACKGROUND allow && echo ALLOW: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_IN_BACKGROUND default ^| findstr /i "%_UA_BACKGROUND_OK% %_SA_BACKGROUND_OK%"') do (>nul adb shell appops set --user %%u %%i RUN_IN_BACKGROUND allow && echo ALLOW: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
for /f "tokens=1 delims=" %%i in ('adb shell appops query-op RUN_ANY_IN_BACKGROUND default ^| findstr /i "%_UA_BACKGROUND_OK% %_SA_BACKGROUND_OK%"') do (>nul adb shell appops set --user %%u %%i RUN_ANY_IN_BACKGROUND allow && echo ALLOW: %%i)
>nul adb shell appops write-settings
>nul adb shell appops read-settings
)
rem done, rebooting device
echo ========================
echo Done. Restarting device!
echo ========================
adb reboot
@opus-x
Copy link
Author

opus-x commented Dec 20, 2022

Only use when you know how to work with ADB (Android Debug Bridge). No warranty, zero liability.

I'm using Nova Launcher for years on all my devices but you'll miss the gestures. One buy and it lasts forever. For the gestures I use MyGestures (and testing more right know, FNG is great too). The free version is just enough and minimal just like the Mi Launcher.

Extra note: This script turns off WiFi and Bluetooth scanning, the Google App, Google Assistent, Chrome and GMail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment