# UltraOpt — Native Android Optimization Module (Magisk)

**UltraOpt** is a lightweight Magisk module focused on real, measurable optimization of CPU, memory and idle behavior.
No placebo tweaks, no vendor hacks, no permanent system changes.

All core logic is implemented in native **C++ binaries** to minimize CPU, RAM and battery overhead.

---

## Key Features

### Smart Power & Performance Management
- Automatic CPU governor switching based on screen state
- Safe restore on wake and module removal

### Memory & Background Optimization
- RAM flushing and cache cleanup
- Background process optimization
- ART / DEX optimization tool
- System cleanup utilities

---

## Core Components

### ultraopt (Main Binary)
Unified native binary replacing shell scripts.

Supports:
- Interactive menu
- CLI usage

CLI examples:
```
su -c ultraopt -ram
su -c ultraopt -clean
su -c ultraopt -dex
su -c ultraopt -bg
su -c ultraopt -tcp 
su -c ultraopt -h
```

Menu mode:
```
su -c ultraopt
```

---

### hibernation (Core Daemon)
Native C++ daemon replacing hibernation.sh.

Behavior (100% preserved):
- Screen ON → apply DEFAULT CPU governors
- Screen OFF → apply SLEEP CPU governors
- Live config reload without reboot
- Logging to hibernation.log

Optimizations vs shell version:
- No fork/exec loops
- Minimal dumpsys usage
- Direct sysfs writes
- Signal-safe shutdown
- Lower CPU wakeups and battery drain

---

## Configuration

Config file:
```
/data/adb/modules/UltrOpt/mod.cfg
```

Supported keys:
```
DEFAULT_GOV=schedutil
SLEEP_GOV=powersave

TCP_CC=bbr3
CHECK_INTERVAL=5
```

Changes apply instantly, no reboot required.

---

## Logging

Daemon log:
```
/data/adb/modules/UltrOpt/hibernation.log
```

Example:
```
[12:41:10] SLEEP
[12:55:42] AWAKE
[13:10:01] STOP
```

---

## Compatibility

- Android: 11 – 15
- Architecture - preferably with 64/32-bit support
- ROMs: Stock, AOSP, custom

---

## Safety & Design Principles

- No permanent system modifications
- No changes to /system or /vendor
- Runtime-only behavior
- Automatic fallback if governor is unavailable
- Safe removal via Magisk

---

## Installation

1. Install module via Magisk, APatch, KSUnext 
2. Reboot
3. Configure via:
```
su -c ultraopt
```

---

## Uninstallation

- Disable or remove module in Magisk, APatch, KSUnext
- Reboot
- System returns to stock behavior

---

## Philosophy

Less scripts. Less hacks. More control.

UltraOpt focuses on clean implementation, not aggressive tweaking.
