Skip to main content
Glama
Android AI Optimizer

Android AI Optimizer

📱 Android AI Optimizer (for Google Antigravity)

A zero-dependency, safety-first MCP server and 5-stage ADB optimization pipeline that lets AI agents audit, debloat, and tune non-rooted Android devices with 1-click rollback.

License: MIT Python 3.10+ MCP Compatible Android SDK 28+ Tests CI Security Policy Privacy Official Guide

Interactive Guide & Benchmarks • Quickstart • Architecture • Real-Device Benchmarks • Safety & Rollback • FAQ


WARNING

Use at your own risk. Modifying system packages and Android framework settings via ADB can disrupt device features or cause bootloops if critical OEM services are removed improperly. This project enforces Audit-First Mode, pre-flight backups, UAD-NG cross-checking, offline bootloop blocklists, a PreToolUse safety hook, and 1-click rollback, but you remain responsible for reviewing every proposed action before approving execution.


⚡ What Is Android AI Optimizer?

Android AI Optimizer is an open-source Model Context Protocol (MCP) toolkit for Google Antigravity (IDE, CLI, and App) and compatible MCP clients that automates non-root Android performance tuning via ADB (Android Debug Bridge).

Unlike blind shell scripts or risky "booster" apps, this project enforces a strict Audit → Snapshot → UAD-NG Cross-Check → Human Approval → Execute → Benchmark workflow. Every mutating MCP tool defaults to dry_run=true, validates inputs inside a zero-dependency Python 3.10+ MCP server (mcp_server/server.py), and logs exact undo commands for 100% reversible changes.

Key Capabilities

  • Zero-Dependency Scoped MCP Server: Built on Python 3.10+ stdlib (newline-delimited JSON-RPC 2.0 over stdio) with 10 scoped tools and zero raw shell access.

  • Hallucination-Proof Debloating: Cross-references installed packages against the live Universal Android Debloater Next Generation (UAD-NG) database (uad_lists.json), surfaces neededBy dependency warnings, and enforces a local safety/hard_blocklist.json.

  • SDK-Aware AOSP Tuning: Automatically adapts commands across Android 9–15 (pm art dexopt-packages -r bg-dexopt on Android 14+ / SDK 34+, cmd game set on Android 13+ / SDK 33+, Phenotype-safe Cached Apps Freezer persistence on Android 11+, and exact appops state restoration).

  • Wired, Wireless & On-Device (Termux + Shizuku): Auto-discovers adb on PATH or standard SDK paths, works over Android 11+ Wireless Debugging, and supports PC-less on-device execution via Termux + Shizuku (rish).

Comparison vs Alternatives

Capability

Android AI Optimizer (MCP)

Manual UAD-NG GUI

Raw Shell / Batch Scripts

Play Store "Boosters"

Zero-Shell Scoped MCP (10 tools)

✅ JSON-RPC 2.0 stdio

❌ GUI only

❌ Unrestricted shell

❌ No ADB access

Bootloop Shield + PreToolUse Hook

✅ hard_blocklist.json + UAD-NG

⚠️ Warnings only

❌ None

❌ Kills active caches

Wired, Wireless & Termux + Shizuku

✅ PC & PC-less rish

❌ PC only

⚠️ Manual setup

❌ No ADB bridge

1-Click State + AppOps Rollback

✅ --undo-all (logs/rollback_log.json)

⚠️ Reinstall only

❌ Manual undo

❌ None


Related MCP server: shapeyourphone

📊 Verified Real-Device Benchmark (Oppo A57)

Tested live on a consumer budget phone (OPPO CPH2387 / Oppo A57) running Android 14 (SDK 34), ColorOS V14.0.0, MediaTek Helio G35 (mt6765), and ~3.88 GB RAM (13.62 GB free on /data).

System Resource Impact

Metric

Before

After

Net Delta

Free RAM

1,118.3 MB

1,643.9 MB

+525.7 MB (+47.0%)

Used RAM

3,892.2 MB

3,766.0 MB

-126.2 MB

Active Service Records

166

148

-18 background services

Bloatware Removed (User 0)

0

36 / 37 removed

1 OS-protected package throttled via AppOps

ART speed-profile Apps

40

50+

Partial bg-dexopt + targeted speed-profile

App Cold-Start Latency (am start -W)

Target App

Before (ms)

After (ms)

Delta

YouTube (com.google.android.youtube)

3,475 ms

3,082 ms

-393 ms faster

Instagram (com.instagram.android)

3,178 ms

3,075 ms

-103 ms faster

WhatsApp (com.whatsapp)

3,325 ms

3,928 ms*

*Measured immediately post-dex2oat & DNS change

Real-World Findings:

  • Eliminated com.heytap.mcs (which was firing 2,307 wakeups/alarms) and the Facebook background updater suite (7m30s background CPU + 37s wakelocks).

  • Throttled background sensor/RAM hogs (com.meesho.supply, shopping apps, and social media) via appops + rare standby buckets while keeping WhatsApp, ProtonVPN, Truecaller, and alarms unrestricted.

  • When ColorOS 14 blocked com.nearme.instant.platform with DELETE_FAILED_INTERNAL_ERROR, the pipeline automatically handled the failure and restricted it via Module A AppOps throttling instead.

  • Note: On the Helio G35 (mt6765), pm art dexopt-packages -r bg-dexopt hit its 600s timeout after compiling key apps (speed-profile rose from 40 to 50) and gracefully continued to targeted speed-profile compilation and sm fstrim.


🏗️ 4-Layer Safety Architecture

+------------------------------------------------------------------------+
| LAYER 1: Orchestration & Guardrails (Google Antigravity)               |
| - Root AGENTS.md & .agents/rules/ (Audit-First, Human Approval Gate)   |
| - .agents/skills/ (android-audit, android-debloat, android-tune)       |
| - .agents/hooks.json (PreToolUse hook blocking bootloop & placebo cmds) |
+-----------------------------------+------------------------------------+
                                    | MCP Protocol (JSON-RPC 2.0 / stdio)
+-----------------------------------v------------------------------------+
| LAYER 2: Zero-Dependency Scoped MCP Server (mcp_server/server.py)      |
| - 10 scoped, input-validated tools (zero raw shell access)             |
| - Enforces hard_blocklist.json + snapshot gate + dry_run=true default  |
| - Optional companion: FlashZ/adb-mcp (.agents/mcp_config.adbmcp.example)|
+---------------+-----------------------------------+--------------------+
                | USB / Wireless ADB                | Local JSON
+---------------v--------------------+  +-----------v--------------------+
| LAYER 3: Target Android Device     |  | LAYER 4: Safety Knowledge      |
| - PackageManager (`pm`) & ART      |  | - Runtime-synced UAD-NG        |
| - ActivityManager (`am`) & AppOps  |  |   (`cache/uad_lists.json`)     |
| - Settings & Storage (`sm fstrim`) |  | - `safety/hard_blocklist.json` |
| - Kernel cgroup v2 Freezer         |  | - `logs/rollback_log.json`     |
+------------------------------------+  +--------------------------------+

🚀 Quickstart (Wired & Wireless ADB)

Prerequisites

  • Python 3.10+ (zero pip install dependencies required)

  • Android SDK Platform-Tools (adb) installed — see docs/SETUP_ADB.md

  • Google Antigravity (or any MCP-compatible AI coding agent)

1. Clone the Repository

git clone https://github.com/HamzaShaikhAI/android-ai-optimizer.git
cd android-ai-optimizer

2. Connect Your Android Device

  1. Enable Developer options on your phone (Settings → About phone → tap Build number 7 times).

  2. Enable USB debugging.

    • ColorOS / RealmeUI / OxygenOS: Also toggle Disable permission monitoring ON in Developer options.

    • MIUI / HyperOS: Also enable USB debugging (Security settings).

  3. Plug in via USB, tap Allow on the RSA debugging prompt, and verify:

    adb devices -l

Option B: Wireless ADB (Android 11+ — No Cable Needed)

  1. Connect your PC and phone to the same Wi-Fi network.

  2. Enable Wireless debugging in Developer options → tap Pair device with pairing code.

  3. Pair once and connect:

    adb pair <ip_address>:<pairing_port>
    adb connect <ip_address>:<connect_port>

3. Run the 5-Stage Pipeline in Google Antigravity

Open the repository folder in Google Antigravity. .agents/mcp_config.json automatically registers mcp_server/server.py. Use the prompts in prompts/ or run the CLI tools directly:

  1. Stage 1 — Read-Only Audit: python scripts/audit_device.py collects SDK level, OEM profile, RAM pressure, battery/alarm wakeups, /data free space, Cached Apps Freezer support, and ART dexopt state.

  2. Stage 2 — Pre-Flight Backup: python scripts/backup_packages.py saves logs/packages_backup.txt, logs/settings_backup.txt, and initializes logs/rollback_log.json.

  3. Stage 3 — UAD-NG Check & Safe Debloat: python scripts/sync_uad.py + python scripts/check_packages.py classify bloatware with neededBy dependency warnings; python scripts/debloat_packages.py executes approved User-0 removals.

  4. Stage 4 — SDK-Aware Tuning: python scripts/tune_performance.py applies approved modules (AppOps + standby buckets, Cached Apps Freezer if kernel supports it, ART bg-dexopt + targeted speed-profile, 0.5x animations, disable_window_blurs, Private DNS, and Android 12+ Game Mode).

  5. Stage 5 — Benchmark Report: python scripts/benchmark_device.py generates a before/after logs/optimization_report.md.


Supported Devices & OEM Quirks

OEM / OS

Required Developer Option Tweak

Critical Keep / Notes

Oppo / Realme / OnePlus (ColorOS / RealmeUI / OxygenOS)

Toggle Disable permission monitoring ON

OS-protected com.oplus.* packages may return DELETE_FAILED_INTERNAL_ERROR; throttle via Module A AppOps instead

Xiaomi / Redmi / Poco (MIUI / HyperOS)

Enable USB debugging (Security settings)

Never remove com.miui.securitycenter or com.xiaomi.finddevice (hard-blocked to prevent bootloops)

Samsung (One UI)

Standard USB Debugging

Keep com.samsung.android.knox.* and spay if using Secure Folder or Samsung Pay

Pixel / Motorola / Nothing (AOSP)

Standard USB Debugging

Minimal bloat; focus on AppOps, Cached Apps Freezer, ART speed-profile, and Private DNS

See docs/OEM_NOTES.md, docs/TROUBLESHOOTING.md, and docs/MYTHS_AND_TRAPS.md for full details.


🛡️ Safety Guardrails & 1-Click Rollback

Every change is logged locally in logs/rollback_log.json and logs/removed_packages.txt (excluded from Git via .gitignore).

Restore a single removed app:

python scripts/restore_package.py --package <package_name>

Revert everything (removed packages, settings, Private DNS, Game Mode, and exact prior AppOps states):

python scripts/restore_package.py --undo-all

Built-in Guardrails:

  • Enforces safety/hard_blocklist.json in scripts, the MCP server, and .agents/hooks.json.

  • Blocks destructive placebo commands (cmd package compile -m everything -a, adb shell su, non---user 0 uninstalls).

  • Automatically skips banking, UPI, authenticator, alarm, messaging, VPN, and accessibility packages during AppOps throttling (never_throttle_keywords).

  • Keeps pm trim-caches 100G opt-in (--trim-caches) so healthy devices don't needlessly drop warm app caches.


❓ Frequently Asked Questions

Does this require root or unlocking the bootloader? No. All optimizations use standard, non-root Android Debug Bridge (ADB) commands. Your warranty, Play Integrity, and banking/UPI apps remain intact.

Will this work on Samsung, Xiaomi, OnePlus, Oppo, and Pixel? Yes. The pipeline automatically detects the OEM and Android SDK version (SDK 28+) and applies OEM-specific rules documented in docs/OEM_NOTES.md.

Can the AI accidentally uninstall a critical system app and cause a bootloop? The MCP server and scripts enforce safety/hard_blocklist.json, block raw shell execution, require a pre-flight backup snapshot, cross-check UAD-NG dependency warnings (neededBy), and default all mutating tools to dry_run=true until you explicitly approve.


Running Tests

python -m unittest discover -s tests -v

📄 License, Security & Privacy

  • License: Released under the MIT License. Package classifications are dynamically fetched at runtime from UAD-NG into gitignored cache/.

  • Security: Read our Security Policy for responsible disclosure and MCP threat-model details.

  • Privacy: Read our Privacy Policy — 100% local execution, zero telemetry.

  • Contributing: See CONTRIBUTING.md or submit device benchmarks and blocklist updates via GitHub Issues.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to directly control Android devices via Termux, providing 120+ tools for screen manipulation, file management, app control, and system operations with layered loading and security gating.
      4
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Enables AI agents to debloat, harden privacy, tune settings, and rebuild the home screen of a non-rooted Android phone over adb, using tiered bloat lists, plain-language preferences and time rules. Every change is previewed, requires explicit owner approval, and is undoable with full restore.
      33
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Enables AI agents to inspect and control Android devices through ADB, including shell commands, logcat, UI automation, app management, screenshots, and file transfer, even inside Termux/proot without a native adb binary.
      41
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents to perform exploratory Android QA over adb through ten typed, validated tools — UI dumps, taps, text input, key presses, screenshots, logcat, APK installs, app launches and configured test suites — behind a command allowlist, sandboxed paths, dry-run mode and a JSONL audit log, so agents can test an app without getting a shell.
      10
      MIT