Skip to content

Instantly share code, notes, and snippets.

@qnimbus
Last active December 16, 2025 14:19
Show Gist options
  • Select an option

  • Save qnimbus/f3682e99b94e8efac179797b207c4fde to your computer and use it in GitHub Desktop.

Select an option

Save qnimbus/f3682e99b94e8efac179797b207c4fde to your computer and use it in GitHub Desktop.
Remove Samsung bloatware
# Samsung S22 debloat
## Install SDK tools
Download Android SDK Platform tools [here](https://developer.android.com/studio/releases/platform-tools)
## ADB Commands
Get list of all apps
```ps
./adb shell pm list packages
```
Get list of system apps
```ps
./adb shell pm list packages -s
```
Get list of samsung apps
```ps
./adb shell pm list packages | Select-String -Pattern "samsung"
```
Disable app for current user
```ps
./adb shell pm disable-user --user 0 <package-name>
```
```ps
# Uninstall app but keep app data and cache
./adb shell pm uninstall -k --user 0 <package-name>
# Or, uninstall app and remove app data as well
./adb shell pm uninstall --user 0 <package-name>
```
```ps
# Get all uninstalled apps for user
./adb shell pm list packages --user 0 -u
```
```ps
# Re-enable app for current user
./adb shell cmd package install-existing --user 0 <package-name>
```
```
# Start adb shell:
./adb shell
# LinkedIn
pm uninstall --user 0 com.linkedin.android
# Facebook
pm uninstall --user 0 com.facebook.services
pm uninstall --user 0 com.facebook.katana
pm uninstall --user 0 com.facebook.system
pm uninstall --user 0 com.facebook.appmanager
# Samsung AR Emoji
pm uninstall --user 0 com.samsung.android.aremoji
pm uninstall --user 0 com.samsung.android.aremojieditor
pm uninstall --user 0 com.sec.android.mimage.avatarstickers
pm uninstall --user 0 samsung.android.emojiupdater
# Samsung Bixby
pm uninstall --user 0 com.samsung.android.bixby.wakeup
pm uninstall --user 0 com.samsung.android.app.spage
pm uninstall --user 0 com.samsung.android.app.routines
pm uninstall --user 0 com.samsung.android.bixby.service
pm uninstall --user 0 com.samsung.android.visionintelligence
pm uninstall --user 0 com.samsung.android.bixby.agent
pm uninstall --user 0 com.samsung.android.bixby.agent.dummy
pm uninstall --user 0 com.samsung.android.bixbyvision.framework
# Google bloatware
pm uninstall --user 0 com.google.android.apps.docs
pm uninstall --user 0 com.google.android.apps.maps
pm uninstall --user 0 com.google.android.apps.tachyon
pm uninstall --user 0 com.google.android.apps.wellbeing
pm uninstall --user 0 com.google.android.feedback
pm uninstall --user 0 com.google.android.gm
pm uninstall --user 0 com.google.android.googlequicksearchbox
pm uninstall --user 0 com.google.android.inputmethod.latin
pm uninstall --user 0 com.google.android.marvin.talkback
pm uninstall --user 0 com.google.android.music
pm uninstall --user 0 com.google.android.tts
pm uninstall --user 0 com.google.android.videos
pm uninstall --user 0 com.google.ar.lens
# Samsung bloatware
pm uninstall --user 0 com.samsung.android.messaging
pm uninstall --user 0 com.samsung.android.drivelink.stub
pm uninstall --user 0 com.sec.android.widgetapp.samsungapps
pm uninstall --user 0 com.sec.android.app.sbrowser
pm uninstall --user 0 com.samsung.android.mateagent
pm uninstall --user 0 com.sec.android.easyMover.Agent
pm uninstall --user 0 com.samsung.android.app.watchmanagerstub
pm uninstall --user 0 com.sec.android.daemonapp
pm uninstall --user 0 com.samsung.android.app.social
pm uninstall --user 0 com.samsung.ecomm.global
pm uninstall --user 0 com.sec.android.app.voicenote
pm uninstall --user 0 com.samsung.android.oneconnect
pm uninstall --user 0 com.samsung.android.voc
pm uninstall --user 0 com.sec.android.splitsound
pm uninstall --user 0 com.mobeam.barcodeService
pm uninstall --user 0 com.samsung.android.scloud
pm uninstall --user 0 com.samsung.android.sdk.handwriting
pm uninstall --user 0 com.samsung.android.sdk.professionalaudio.utility.jammonitor
pm uninstall --user 0 com.samsung.android.universalswitch
pm uninstall --user 0 com.samsung.android.visioncloudagent
pm uninstall --user 0 com.samsung.android.visionintelligence
pm uninstall --user 0 com.samsung.android.widgetapp.yahooedge.finance
pm uninstall --user 0 com.samsung.android.widgetapp.yahooedge.sport
pm uninstall --user 0 com.samsung.app.highlightplayer
pm uninstall --user 0 com.samsung.safetyinformation
pm uninstall --user 0 com.samsung.storyservice
pm uninstall --user 0 com.samsung.android.service.aircommand
pm uninstall --user 0 com.sec.android.app.dexonpc
pm uninstall --user 0 com.samsung.android.ardrawing
pm uninstall --user 0 com.samsung.android.arzone
pm uninstall --user 0 com.samsung.android.svoiceime
pm uninstall --user 0 com.samsung.android.beaconmanager
pm uninstall --user 0 com.samsung.android.email.provider
pm uninstall --user 0 com.wsomacp
# Android bloatware
pm uninstall --user 0 com.android.bips
pm uninstall --user 0 com.android.bookmarkprovider
pm uninstall --user 0 com.android.browser
pm uninstall --user 0 com.android.calendar
pm uninstall --user 0 com.android.cellbroadcastreceiver
pm uninstall --user 0 com.android.cellbroadcastreceiver.overlay.common
pm uninstall --user 0 com.android.chrome
pm uninstall --user 0 com.sec.android.app.chromecustomizations
pm uninstall --user 0 com.android.deskclock
pm uninstall --user 0 com.android.dreams.basic
pm uninstall --user 0 com.android.dreams.phototable
pm uninstall --user 0 com.android.egg
pm uninstall --user 0 com.android.emergency
pm uninstall --user 0 com.android.hotwordenrollment.okgoogle
pm uninstall --user 0 com.android.mms
pm uninstall --user 0 com.android.mms.service
pm uninstall --user 0 com.android.printspooler
pm uninstall --user 0 com.android.statementservice
pm uninstall --user 0 com.android.stk
pm uninstall --user 0 com.android.wallpaper.livepicker
pm uninstall --user 0 com.android.wallpaperbackup
pm uninstall --user 0 com.android.wallpapercropper
pm uninstall --user 0 com.android.providers.downloads.ui
pm uninstall --user 0 com.android.providers.partnerbookmarks
pm uninstall --user 0 com.android.sharedstoragebackup
# Samsung recreational bloatware
pm uninstall --user 0 com.boxer.app
pm uninstall --user 0 com.samsung.android.wellbeing
pm uninstall --user 0 com.samsung.android.da.daagent
pm uninstall --user 0 com.samsung.android.service.livedrawing
# Samsung Pay and Pass
pm uninstall --user 0 com.samsung.android.samsungpassautofill
pm uninstall --user 0 com.samsung.android.authfw
pm uninstall --user 0 com.samsung.android.samsungpass
pm uninstall --user 0 com.samsung.android.spay
pm uninstall --user 0 com.samsung.android.spayfw
# Samsung Gear VR
pm uninstall --user 0 com.samsung.android.hmt.vrsvc
pm uninstall --user 0 com.samsung.android.app.vrsetupwizardstub
pm uninstall --user 0 com.samsung.android.hmt.vrshell
pm uninstall --user 0 com.google.vr.vrcore
# Samsung Kids mode
pm uninstall --user 0 com.samsung.android.kidsinstallerlauncher
pm uninstall --user 0 com.samsung.android.app.camera.sticker.facearavatar.preload
pm uninstall --user 0 com.sec.android.app.kidshome
# Samsung LED cover
pm uninstall --user 0 com.samsung.android.app.ledbackcover
pm uninstall --user 0 com.sec.android.cover.ledcover
# Samsung DEX
pm uninstall --user 0 com.sec.android.desktopmode.uiservice
pm uninstall --user 0 com.samsung.desktopsystemui
pm uninstall --user 0 com.sec.android.app.desktoplauncher
# Samsung other bloatware
pm uninstall --user 0 com.gocro.smartnews.android
pm uninstall --user 0 com.synchronoss.dcs.att.r2g
pm uninstall --user 0 com.wavemarket.waplauncher
pm uninstall --user 0 com.pandora.android
pm uninstall --user 0 com.sec.penup
pm uninstall --user 0 com.samsung.android.service.livedrawing
pm uninstall --user 0 com.linkedin.android
pm uninstall --user 0 com.hunge.app
pm uninstall --user 0 com.greatbigstory.greatbigstory
pm uninstall --user 0 com.android.documentsui
pm uninstall --user 0 com.drivemode
pm uninstall --user 0 com.samsung.android.app.contacts
pm uninstall --user 0 com.samsung.android.calendar
pm uninstall --user 0 com.cnn.mobile.android.phone
pm uninstall --user 0 com.bleacherreport.android.teamstream
pm uninstall --user 0 com.aetherpal.device
pm uninstall --user 0 com.google.android.dialer
pm uninstall --user 0 com.wb.goog.got.conquest
pm uninstall --user 0 com.wb.goog.dcuniverse
pm uninstall --user 0 com.innogames.foeandroid
pm uninstall --user 0 com.playstudios.popslots
pm uninstall --user 0 com.gsn.android.tripeaks
pm uninstall --user 0 com.foxnextgames.m3
pm uninstall --user 0 com.audible.application
pm uninstall --user 0 com.microsoft.skydrive
# Other bloatware
pm uninstall --user 0 de.telekom.tsc
pm uninstall --user 0 com.samsung.android.game.gametools
pm uninstall --user 0 com.samsung.android.game.gamehome
pm uninstall --user 0 com.samsung.android.game.gos
# Samsung Printing Service Components
pm uninstall --user 0 com.android.bips
pm uninstall --user 0 com.google.android.printservice.recommendation
pm uninstall --user 0 com.android.printspooler
```
# debloat.ps1
# Interactive Samsung/Android debloat helper (ADB required)
# - Disable (safer) or Uninstall for user 0 (reversible for preinstalled packages)
# - Restore mode (enable / install-existing)
# - PS7-safe output handling
# - Only prompts for packages that exist on the connected device
# - Protects critical packages by default (requires explicit override)
# - Protects S Pen Air Command + handwriting-to-text (explicit override required)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
# ---------------------------
# Core ADB helpers (PS7-safe)
# ---------------------------
function Require-Adb {
$adb = Get-Command adb -ErrorAction SilentlyContinue
if (-not $adb) {
Write-Host "adb not found in PATH. Install platform-tools (winget install --id Google.PlatformTools) and reopen terminal."
exit 1
}
}
function Run-Adb {
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$Args
)
& adb @Args 2>&1
}
function Get-AdbText {
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$Args
)
# Normalize to a single string regardless of PS version
(Run-Adb @Args | Out-String).TrimEnd()
}
function Ensure-Device {
$out = Get-AdbText devices -l
if ($out -match "unauthorized") {
Write-Host "Device is unauthorized. Check the phone for 'Allow USB debugging' and accept it."
exit 1
}
# Match any line: <serial><spaces>device
if ($out -notmatch "(?m)^\S+\s+device\b") {
Write-Host "No ADB device found. Ensure USB debugging is enabled and USB mode allows data."
Write-Host $out
exit 1
}
}
function Pm([string]$cmd) {
# Avoid sh entirely (One UI quirks). Split the command into tokens for adb shell.
# Supports commands like: "pm list packages -d" or "cmd package install-existing --user 0 x"
$parts = $cmd -split '\s+'
Get-AdbText shell @parts
}
# ---------------------------
# Safety guardrails
# ---------------------------
# Explicit "keep" list for S Pen functionality (Air Command + handwriting-to-text)
# You said you will use these features, so we hard-protect them.
$SPenKeep = @(
# Air Command (hover menu)
"com.samsung.android.service.aircommand",
"com.samsung.android.aircommandmanager",
# Handwriting-to-text / handwriting recognition services
"com.samsung.android.sdk.handwriting",
# Notes and S Pen-centric apps (keep; optional but strongly recommended for S Pen use)
"com.samsung.android.app.notes",
"com.sec.penup",
# S Pen adjacent features often used with Air Command workflows
"com.samsung.android.app.smartcapture", # Smart select / screenshots
"com.sec.android.autodoodle.service" # Auto doodle / drawing integrations
)
# Packages matching these patterns are considered "protected" (core OS / radio / Play Services / system UI, etc.)
# You can still act on them, but only with an explicit override prompt.
$ProtectedPatterns = @(
'^android$',
# Core UI / phone
'^com\.android\.systemui$',
'^com\.android\.settings$',
'^com\.android\.phone$',
'^com\.sec\.phone$',
# Package/permission control
'^com\.google\.android\.permissioncontroller$',
'^com\.google\.android\.packageinstaller$',
'^com\.android\.permissioncontroller$',
'^com\.android\.packageinstaller$',
# Providers + system servers (high-risk)
'^com\.android\.providers\.',
'^com\.android\.server\.',
# Google core services
'^com\.google\.android\.gms$',
'^com\.google\.android\.gsf$',
# IMS / telephony services (high-risk)
'^com\.samsung\.ims\.',
'^com\.sec\.ims',
# OTA / device management
'^com\.wssyncmldm$',
# Networking stack (high-risk)
'^com\.google\.android\.networkstack',
'^com\.samsung\.android\.networkstack',
# SMS/MMS service
'^com\.android\.mms\.service$',
# Printing (you want to keep these)
'^com\.android\.bips$',
'^com\.android\.printspooler$'
)
function IsProtected([string]$pkg) {
# Hard-protect S Pen packages first
if ($SPenKeep -contains $pkg) { return $true }
foreach ($p in $ProtectedPatterns) {
if ($pkg -match $p) { return $true }
}
return $false
}
function Confirm-Override([string]$pkg) {
Write-Host ""
if ($SPenKeep -contains $pkg) {
Write-Host "WARNING: '$pkg' is required for S Pen Air Command/handwriting features you said you intend to use."
} else {
Write-Host "WARNING: '$pkg' looks like a core/critical package."
}
Write-Host "Disabling/removing it may break key phone functions. To proceed, type: YES"
$ans = Read-Host "Proceed?"
return ($ans -eq "YES")
}
# ---------------------------
# Package inventory on device
# ---------------------------
function Get-AllPackagesOnDevice {
$raw = Pm "pm list packages"
@(
$raw -split "`r?`n" |
ForEach-Object { $_.Trim() } |
Where-Object { $_ -like "package:*" } |
ForEach-Object { $_.Substring(8) }
)
}
$DevicePackages = @()
function Refresh-DevicePackages {
# Always keep this as a real array
$script:DevicePackages = @(Get-AllPackagesOnDevice)
}
function IsInstalled([string]$pkg) {
return $DevicePackages -contains $pkg
}
function IsDisabled([string]$pkg) {
$r = Pm "pm list packages -d"
return ($r -match [regex]::Escape("package:$pkg"))
}
# ---------------------------
# Actions
# ---------------------------
function DisablePkg([string]$pkg) {
$out = Pm "pm disable-user --user 0 $pkg"
if ($out -match "Cannot disable a protected package") {
return "SKIP: Android marked '$pkg' as protected; cannot disable via ADB."
}
return $out
}
function UninstallUser0([string]$pkg) {
Pm "pm uninstall --user 0 $pkg"
}
function EnablePkg([string]$pkg) {
Pm "pm enable --user 0 $pkg"
}
function InstallExisting([string]$pkg) {
Pm "cmd package install-existing --user 0 $pkg"
}
# ---------------------------
# UI helpers
# ---------------------------
function Prompt-Choice([string]$prompt, [string[]]$choices) {
while ($true) {
Write-Host ""
Write-Host $prompt
for ($i = 0; $i -lt $choices.Count; $i++) {
Write-Host (" [{0}] {1}" -f ($i + 1), $choices[$i])
}
$sel = Read-Host "Select 1-$($choices.Count)"
$n = 0
if ([int]::TryParse($sel, [ref]$n)) {
if ($n -ge 1 -and $n -le $choices.Count) { return $choices[$n - 1] }
}
Write-Host "Invalid selection."
}
}
# ---------------------------
# Curated starter list (based on your actual installed list)
# ---------------------------
$Packages = @(
# Third-party bloat / optional apps
@{ name="com.facebook.appmanager"; note="Facebook App Manager (preload helper) - Safe" },
@{ name="com.facebook.services"; note="Facebook Services (preload helper) - Safe" },
@{ name="com.facebook.system"; note="Facebook System (preload helper) - Safe" },
@{ name="com.facebook.katana"; note="Facebook app - Safe (if you don't use it)" },
@{ name="com.linkedin.android"; note="LinkedIn - Safe (if you don't use it)" },
@{ name="com.spotify.music"; note="Spotify - Safe (if you don't use it)" },
@{ name="com.netflix.mediaclient"; note="Netflix - Safe (if you don't use it)" },
@{ name="com.microsoft.office.outlook"; note="Outlook - Safe (if you don't use it)" },
@{ name="com.microsoft.office.officehubrow"; note="Microsoft 365/Office Hub - Safe (if you don't use it)" },
@{ name="com.microsoft.appmanager"; note="Microsoft App Manager - Safe" },
@{ name="com.microsoft.skydrive"; note="OneDrive - Caution (Gallery sync may use it)" },
# Google apps (optional)
@{ name="com.google.android.gm"; note="Gmail - Safe (if you use another mail app)" },
@{ name="com.google.android.apps.maps"; note="Google Maps - Safe (if you don't use it)" },
@{ name="com.google.android.apps.docs"; note="Google Drive/Docs - Safe (if you don't use it)" },
@{ name="com.google.android.apps.tachyon"; note="Google Meet - Safe" },
@{ name="com.google.android.apps.youtube.music"; note="YouTube Music - Safe" },
@{ name="com.google.android.videos"; note="Google TV - Safe" },
@{ name="com.google.android.feedback"; note="Google Feedback - Safe" },
@{ name="com.google.android.apps.bard"; note="Google Gemini/Bard - Safe (if you don't use it)" },
@{ name="com.google.ar.core"; note="ARCore - Safe (if you don't use AR apps)" },
# Samsung optional features
@{ name="com.samsung.android.app.tips"; note="Samsung Tips - Safe" },
@{ name="com.samsung.android.voc"; note="Samsung Members - Safe" },
@{ name="com.sec.android.app.samsungapps"; note="Galaxy Store - Caution (Samsung app updates depend on it)" },
@{ name="com.samsung.android.themestore"; note="Theme Store - Safe (if you don't use themes)" },
@{ name="com.samsung.android.themecenter"; note="Theme Center - Safe (if you don't use themes)" },
@{ name="com.samsung.android.app.updatecenter"; note="Samsung app update center - Caution (ties into Galaxy Store)" },
@{ name="com.samsung.android.oneconnect"; note="SmartThings - Safe (if you don't use SmartThings)" },
@{ name="com.samsung.android.service.stplatform"; note="SmartThings platform service - Safe (if not using SmartThings)" },
@{ name="com.samsung.android.scloud"; note="Samsung Cloud - Safe (if you don't use Samsung account/cloud)" },
@{ name="com.samsung.android.spay"; note="Samsung Wallet/Pay - Safe (if you don't use it)" },
@{ name="com.samsung.android.spayfw"; note="Samsung Pay framework - Safe (if you don't use it)" },
@{ name="com.samsung.android.samsungpass"; note="Samsung Pass - Safe (if you don't use it)" },
@{ name="com.samsung.android.samsungpassautofill"; note="Samsung Pass Autofill - Safe (if you don't use it)" },
# Bixby / vision
@{ name="com.samsung.android.bixby.agent"; note="Bixby - Safe (if you don't use it)" },
@{ name="com.samsung.android.bixby.wakeup"; note="Bixby voice wake - Safe" },
@{ name="com.samsung.android.bixbyvision.framework"; note="Bixby Vision framework - Safe" },
@{ name="com.samsung.android.visionintelligence"; note="Vision intelligence hooks - Safe" },
@{ name="com.samsung.android.mdx"; note="Multi-device experience - Caution (continuity features)" },
@{ name="com.samsung.android.mdx.kit"; note="Multi-device kit - Caution" },
# AR / Emoji / stickers
@{ name="com.samsung.android.arzone"; note="AR Zone - Safe" },
@{ name="com.samsung.android.aremoji"; note="AR Emoji - Safe" },
@{ name="com.samsung.android.aremojieditor"; note="AR Emoji editor - Safe" },
@{ name="com.samsung.android.stickercenter"; note="Sticker Center - Safe" },
@{ name="com.sec.android.mimage.avatarstickers"; note="Avatar stickers - Safe" },
@{ name="com.samsung.android.app.camera.sticker.facearavatar.preload"; note="AR avatar preload - Safe" },
# Gaming services
@{ name="com.samsung.android.game.gamehome"; note="Game Launcher - Safe (if you don't use it)" },
@{ name="com.samsung.android.game.gametools"; note="Game Tools - Safe" },
@{ name="com.samsung.android.game.gos"; note="Game Optimizing Service - Safe (may change thermals/battery behavior)" },
# DeX (optional)
@{ name="com.sec.android.desktopmode.uiservice"; note="Samsung DeX - Caution (removes DeX)" },
@{ name="com.sec.android.dexsystemui"; note="DeX SystemUI - Caution" },
@{ name="com.sec.android.app.desktoplauncher"; note="DeX launcher - Caution" },
# Kids / parental
@{ name="com.samsung.android.kidsinstaller"; note="Samsung Kids installer - Safe (if you don't use Kids mode)" },
@{ name="com.sec.android.app.kidshome"; note="Kids Home - Safe (if you don't use Kids mode)" },
@{ name="com.samsung.android.app.parentalcare"; note="Parental controls - Safe (if you don't use it)" },
# Google browser/search (optional)
@{ name="com.android.chrome"; note="Google Chrome – Safe to disable if you use another browser (e.g., Firefox/Edge/Brave). Does NOT affect Android System WebView." },
@{ name="com.google.android.googlequicksearchbox"; note="Google app (Search/Discover/Assistant entrypoint) – Safe to disable if you do not use Discover, Google Search widget, or Assistant." },
# Samsung
@{ name="com.samsung.android.app.spage"; note="Samsung Free / Samsung Daily feed (left home screen) – Safe to disable; removes Samsung content feed." }
@{ name="com.sec.android.app.shealth"; note="Samsung Health – Safe to disable if you do not use health tracking, workouts, or Galaxy Watch integration." }
@{ name = "com.samsung.android.fmm"; note = "Samsung Find My Mobile – Theft recovery and remote control via Samsung account. Safe to disable only if you do NOT use Samsung Find My Mobile features." }
@{ name = "com.samsung.sree"; note = "Samsung Global Goals – UN SDG awareness app. Purely optional; safe to disable or uninstall." }
# Misc
@{ name="com.sec.android.app.sbrowser"; note="Samsung Internet browser – Safe if you use another browser (Chrome/Firefox). WebView and system components do NOT depend on this app." },
@{ name="com.samsung.android.sm.devicesecurity"; note="Device Security (McAfee) - Safe" },
@{ name="com.android.dreams.basic"; note="Android screensaver - Safe" },
@{ name="com.android.dreams.phototable"; note="Photo screensaver - Safe" },
@{ name="com.android.bips"; note="Default print service - Safe (if you never print)" },
@{ name="com.android.printspooler"; note="Print spooler - Safe (if you never print)" },
@{ name="com.google.android.printservice.recommendation"; note="Print recommendations - Safe" }
)
# ---------------------------
# Main flow
# ---------------------------
Require-Adb
Ensure-Device
Refresh-DevicePackages
Write-Host ""
Write-Host "ADB device detected."
Write-Host ("Packages found on device: {0}" -f (($DevicePackages | Measure-Object).Count))
Write-Host "Tip: Prefer DISABLE first. If stable after a day or two, UNINSTALL for user 0."
# Keep only packages that actually exist on the phone
$Packages = $Packages | Where-Object { IsInstalled $_.name }
if (-not $Packages -or $Packages.Count -eq 0) {
Write-Host ""
Write-Host "None of the curated packages are present on this device (or they were already removed)."
Write-Host "Use the 'Custom package list' mode to paste packages you want to act on."
}
$mode = Prompt-Choice "Mode?" @(
"Debloat (Disable/Uninstall)",
"Restore (Enable/Install-existing)",
"Custom package list (paste packages) + Debloat",
"Custom package list (paste packages) + Restore",
"Quit"
)
if ($mode -eq "Quit") { exit 0 }
if ($mode -like "Custom package list*") {
Write-Host ""
Write-Host "Paste package names (one per line). End with an empty line."
$custom = @()
while ($true) {
$line = Read-Host
if ([string]::IsNullOrWhiteSpace($line)) { break }
$pkg = $line.Trim()
if ($pkg.Length -gt 0) { $custom += $pkg }
}
$Packages = $custom | Select-Object -Unique | ForEach-Object { @{ name = $_; note = "(custom)" } }
$Packages = $Packages | Where-Object { IsInstalled $_.name }
}
if ($mode -like "*Debloat*") {
$defaultAction = Prompt-Choice "Default action for each package?" @(
"Disable (safer)",
"Uninstall for user 0 (reversible for preinstalls)",
"Ask per package"
)
$dryRun = Prompt-Choice "Execute commands or dry-run?" @("Execute", "Dry-run")
foreach ($p in $Packages) {
$pkg = $p.name
$note = $p.note
Write-Host ""
Write-Host "Package: $pkg"
Write-Host "Note: $note"
$disabled = IsDisabled $pkg
Write-Host ("Status: Installed{0}" -f ($(if ($disabled) { ", disabled" } else { "" })))
if (IsProtected $pkg) {
if (-not (Confirm-Override $pkg)) {
Write-Host "Skipping protected package."
continue
}
}
if ($defaultAction -eq "Ask per package") {
$action = Prompt-Choice "Action for this package?" @("Skip", "Disable", "Uninstall (user 0)")
} elseif ($defaultAction -like "Disable*") {
$action = "Disable"
} else {
$action = "Uninstall (user 0)"
}
if ($action -eq "Skip") { continue }
if ($dryRun -eq "Dry-run") {
if ($action -eq "Disable") {
Write-Host "DRY: adb shell pm disable-user --user 0 $pkg"
} else {
Write-Host "DRY: adb shell pm uninstall --user 0 $pkg"
}
continue
}
try {
if ($action -eq "Disable") {
DisablePkg $pkg | Write-Host
} else {
UninstallUser0 $pkg | Write-Host
}
} catch {
Write-Host "ERROR: $($_.Exception.Message)"
}
}
Write-Host ""
Write-Host "Done. Consider rebooting your phone now."
}
if ($mode -like "*Restore*") {
$restoreAction = Prompt-Choice "Restore method?" @(
"Enable (for packages you disabled)",
"Install-existing (for packages uninstalled for user 0)",
"Try both (enable then install-existing)"
)
$dryRun = Prompt-Choice "Execute commands or dry-run?" @("Execute", "Dry-run")
foreach ($p in $Packages) {
$pkg = $p.name
Write-Host ""
Write-Host "Package: $pkg"
if (IsProtected $pkg) {
if (-not (Confirm-Override $pkg)) {
Write-Host "Skipping protected package."
continue
}
}
if ($dryRun -eq "Dry-run") {
switch ($restoreAction) {
"Enable (for packages you disabled)" {
Write-Host "DRY: adb shell pm enable --user 0 $pkg"
}
"Install-existing (for packages uninstalled for user 0)" {
Write-Host "DRY: adb shell cmd package install-existing --user 0 $pkg"
}
default {
Write-Host "DRY: adb shell pm enable --user 0 $pkg"
Write-Host "DRY: adb shell cmd package install-existing --user 0 $pkg"
}
}
continue
}
try {
switch ($restoreAction) {
"Enable (for packages you disabled)" {
EnablePkg $pkg | Write-Host
}
"Install-existing (for packages uninstalled for user 0)" {
InstallExisting $pkg | Write-Host
}
default {
EnablePkg $pkg | Out-Null
InstallExisting $pkg | Write-Host
}
}
} catch {
Write-Host "ERROR: $($_.Exception.Message)"
}
}
Write-Host ""
Write-Host "Restore complete. Consider rebooting your phone."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment