#!/usr/bin/env bash
# Android Debloat checklist — informational ADB workflow
# https://debloat.hackinghub.cloud
#
# This file does not remove any packages by itself. It prints the standard
# setup, backup, uninstall/disable, and restore commands so you can copy and
# review them. No root required. User-level only (--user 0).
#
# Do NOT remove core system apps such as Phone/Dialer, Contacts, Messages,
# System UI, Settings, Google Play Services, Play Store, or the keyboard.

set -u

cat << 'GUIDE'
============================================================
Android Debloat — before you start
============================================================

1. Enable Developer options
   Settings → About phone → tap Build number 7 times.

2. Turn on USB debugging
   Settings → System → Developer options → USB debugging.

3. Connect the phone
   USB:
     Install official platform-tools:
       https://developer.android.com/tools/releases/platform-tools
     Plug in a data-capable cable and unlock the phone.

   Android 11+ Wireless debugging (same Wi-Fi as the computer):
     Developer options → Wireless debugging → Pair device with pairing code
       adb pair PHONE_IP:PAIR_PORT
     Then use the connection port shown on the phone:
       adb connect PHONE_IP:PORT

   Classic ADB-over-TCP:
       adb tcpip 5555
       adb connect PHONE_IP:5555
     (Run tcpip once over USB. It resets after a reboot.)

4. Authorize this computer
   Accept "Allow USB debugging?" on the phone, then verify:

       adb devices

   The state must be "device", not "unauthorized" or "offline".

============================================================
Backup the package list (do this first)
============================================================

    adb shell pm list packages > adb-packages-all.txt
    adb shell pm list packages -3 > adb-packages-third-party.txt

  -3 lists third-party / user-installed packages. Review the full list
  before removing anything. Package names vary by OEM, carrier, and region.

============================================================
Safe template commands (replace PACKAGE)
============================================================

  Disable for this user only:
    adb shell pm disable-user --user 0 PACKAGE

  Uninstall for this user only (keeps app data with -k):
    adb shell pm uninstall -k --user 0 PACKAGE

  These are user-level. They are usually reversible without a factory reset.

============================================================
Restore without a factory reset
============================================================

  After uninstall --user 0:
    adb shell cmd package install-existing PACKAGE

  After disable-user:
    adb shell pm enable PACKAGE

  A factory reset also restores preinstalled apps, but wipes the device.

============================================================
Reputable tools
============================================================

  UAD-NG:           https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation
  Platform Tools:   https://developer.android.com/tools/releases/platform-tools
  Shizuku:          https://shizuku.rikka.app/
  Canta:            https://github.com/samolego/Canta

============================================================
GUIDE

if command -v adb >/dev/null 2>&1; then
  echo "adb is on PATH. Current devices:"
  adb devices
else
  echo "adb was not found on PATH. Install Android SDK Platform Tools first:"
  echo "  https://developer.android.com/tools/releases/platform-tools"
fi
