Metadata-Version: 2.5
Name: galaxy-s22-toolkit
Version: 0.7.0
Summary: ADB wrapper library for Samsung Galaxy phone diagnostics and management (S/Note/A, Android 10+)
Project-URL: Homepage, https://github.com/user/galaxy-s22-toolkit
Project-URL: Repository, https://github.com/user/galaxy-s22-toolkit
Project-URL: Issues, https://github.com/user/galaxy-s22-toolkit/issues
Author-email: Phone Toolkit <user@example.com>
License: MIT
Keywords: adb,android,diagnostics,galaxy,mobile,phone,samsung
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.10
Requires-Dist: asyncio
Provides-Extra: dev
Requires-Dist: mypy>=1.5.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
Requires-Dist: pytest-mock>=3.11.0; extra == 'dev'
Requires-Dist: pytest>=7.4.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Requires-Dist: types-requests>=2.31.0; extra == 'dev'
Requires-Dist: windows-toasts>=1.3; (sys_platform == 'win32') and extra == 'dev'
Provides-Extra: notify
Requires-Dist: windows-toasts>=1.3; extra == 'notify'
Provides-Extra: test
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'test'
Requires-Dist: pytest-mock>=3.11.0; extra == 'test'
Requires-Dist: pytest>=7.4.0; extra == 'test'
Description-Content-Type: text/markdown

# Galaxy S22+ Phone Toolkit

A comprehensive Python ADB wrapper library for Samsung Galaxy S22+ (SM-S906B) diagnostics, monitoring, and management.

## Features

- **Typed ADB Client** - Async/sync execution with retry logic and exponential backoff
- **Device Information** - Model, Android version, security patch, build fingerprint, CPU, memory
- **Battery Monitoring** - Level, health, temperature, voltage, charge cycles, charging status
- **Storage Analysis** - Partition usage, large file finder, app storage breakdown
- **Logcat Streaming** - Real-time filtering, crash/ANR detection, permission denial tracking
- **Network Diagnostics** - Wi-Fi/mobile status, DNS, gateway, internet connectivity, speed tests
- **Thermal Monitoring** - Zone temperatures, throttling detection, CPU/GPU thermal status
- **App Management** - List/install/uninstall, permissions, cache/data clearing, freeze/thaw
- **Screen Control** - Screenshots, screen recording, UI dumps, input simulation
- **Root/Magisk** - Root state, Knox status, confirm-gated privileged ops, module markers
- **Multi-Galaxy profiles** - `phone.capabilities.detect_profile()`: marketing name, series, chipset, One UI; unknown models degrade to raw codes, never hard-fail
- **Repair Actions** - ~20 audited actions with approval policy and JSONL history

## Installation

```bash
pip install -e ./phone-lib
```

Or with development dependencies:

```bash
pip install -e ./phone-lib[dev]
```

## Quick Start

```python
from phone import create_client, DeviceModule, BatteryModule, StorageModule

# Create client (auto-detects Galaxy S22+ serial RFCTA0AEKZP)
client = create_client()

# Get device info
device = DeviceModule(client)
info = device.get_device_info()
print(f"{info.model} - Android {info.android_version} - Patch: {info.security_patch}")

# Get battery info
battery = BatteryModule(client)
bat = battery.get_battery_info()
print(f"Battery: {bat.level}% ({bat.health.value}) - {bat.temperature_c:.1f}°C")

# Get storage info
storage = StorageModule(client)
for part in storage.get_storage_info():
    print(f"{part.mount_point}: {part.usage_percent:.1f}% used ({part.free_gb:.1f}GB free)")

# Stream logcat for crashes
logcat = LogcatModule(client)


def on_crash(entry):
    print(f"CRASH: {entry.tag}: {entry.message}")


logcat.monitor_for_crashes(on_crash, package_name="com.example.app")
```

## Async Usage

```python
import asyncio
from phone import create_client


async def main():
    client = create_client()

    # Async shell command
    output = await client.shell_async("dumpsys battery")
    print(output)

    # Async execute
    result = await client.execute_async("getprop", "ro.build.version.release")
    print(f"Android: {result}")


asyncio.run(main())
```

## Modules

| Module | Class | Description |
|--------|-------|-------------|
| `adb` | `AdbClient` | Core ADB connection and command execution |
| `device` | `DeviceModule` | Device properties, CPU, memory info |
| `battery` | `BatteryModule` | Battery health, temperature, charge cycles |
| `storage` | `StorageModule` | Partition usage, large files, app storage |
| `logcat` | `LogcatModule` | Log streaming, crash/ANR detection |
| `network` | `NetworkModule` | Wi-Fi, mobile, DNS, connectivity |
| `thermal` | `ThermalModule` | Thermal zones, throttling status |
| `apps` | `AppsModule` | Package management, permissions |
| `screen` | `ScreenModule` | Screenshots, recording, UI dumps |
| `root` | `RootModule` | Root/Magisk state, confirm-gated privileged ops, module markers |
| `capabilities` | `detect_profile` | Multi-Galaxy DeviceProfile: marketing name, series, chipset, One UI |
| `repair` | `RepairModule` | Approved repair actions with persistent JSONL history |
| `notify` | `DesktopNotifier` | Windows toast notifications with Approve/Deny buttons |
| `paths` | `confined_path` | Path confinement (resolve + fixed-root verification) |

## Repair Actions

`phone.repair.RepairModule` provides ~20 audited repair actions (storage,
apps, network, logcat). Approval policy: actions flagged `auto_approve` or
matching the configured `auto_approve_risk_levels` run without prompting;
everything else requires an explicit approval (toast buttons or callback).
Every executed result is appended to a JSONL history file and reloaded on
the next run.

```python
from phone.repair import RepairModule

repair = RepairModule(client, history_path="logs/repair_history.jsonl")
results = await repair.execute_multiple(["clear_app_caches", "flush_dns"])
```

Actions that need root (e.g. tombstone/ANR cleanup) are flagged
`requires_root=True` and report an honest failure on unrooted devices
instead of a silent no-op. Network toggles always attempt re-enable so a
half-failed reset never leaves a radio off.

## Desktop Notifications

```python
from phone.notify import DesktopNotifier

notifier = DesktopNotifier(app_id="Galaxy S22+ Toolkit", dashboard_url="http://127.0.0.1:8081")
notifier.notify("Health check", "All checks passed")
approved = await notifier.request_approval_async(
    "Repair: reset_wifi", "Toggles Wi-Fi off/on", timeout_s=120
)
```

Requires the optional `notify` extra (`pip install galaxy-s22-toolkit[notify]`,
Windows only). Timeout counts as denial.

## Path Confinement

```python
from phone.paths import confined_path, PathEscapeError

target = confined_path(root_dir, user_supplied)  # raises PathEscapeError
```

Every file write in the library resolves its candidate against a fixed
root and rejects `..` segments outright.

## Data Models

All modules return typed dataclasses with slots for performance:

```python
from phone.models import BatteryInfo, StorageInfo, DeviceInfo, HealthReport

# Full health report
report = HealthReport(
    device=device_info,
    battery=battery_info,
    storage=storage_list,
    network=network_info,
    thermal=thermal_info,
)
print(report.summary)
print(report.is_healthy)
```

## Requirements

- Python 3.10+
- Android SDK Platform Tools (adb in PATH or at default locations)
- Samsung Galaxy S22+ with USB debugging enabled
- Device authorized (RSA key accepted on phone)

## ADB Path Detection

The client automatically searches for ADB at:
1. `C:\Users\tbaltzakis\Android\Sdk\platform-tools\adb.exe` (Windows)
2. `/mnt/c/Users/tbaltzakis/Android/Sdk/platform-tools/adb` (WSL)
3. `~/Android/Sdk/platform-tools/adb` (Linux/macOS)
4. `/c/Users/tbaltzakis/Android/Sdk/platform-tools/adb` (Git Bash)
5. `adb` (system PATH)

## Testing

```bash
# Run unit tests (mocked ADB)
pytest tests/

# Run integration tests (requires physical device)
pytest tests/ -m device

# Run with coverage
pytest --cov=phone tests/
```

## Code Quality

```bash
# Lint
ruff check .

# Format
ruff format .

# Type check
mypy src/phone
```

## License

MIT License