# dhangofa/nettoggle architecture

> Architecture diagram of the GitHub repository dhangofa/nettoggle, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dhangofa/nettoggle
- Repository: https://github.com/dhangofa/nettoggle

## Overview

#### Purpose and Runtime
NetToggle is a native Android app (API 24–36) that exposes a Quick Settings tile for cycling cellular radio/network modes. It operates entirely on-device, bypassing ordinary telephony APIs through privileged shell commands run as Root (`su`) or via Shizuku. Android Gradle builds the single `app` module: `app/build.gradle.kts`, `app/src/main/AndroidManifest.xml`.

#### Android Entry Points
The primary configuration screen is `app/src/main/java/com/dhangofa/networktoggle/MainActivity.java`. The operational entry point is the system-hosted QS tile service, `app/src/main/java/com/dhangofa/networktoggle/NetworkTileService.java`, which applies the next configured mode on tile interaction. `app/src/main/java/com/dhangofa/networktoggle/BootReceiver.java` restores or refreshes relevant tile/application state after device boot.

#### Persistent Configuration and Cycle State
`app/src/main/java/com/dhangofa/networktoggle/config/AppPreferences.java` is the local persistence boundary for execution mode, target SIM, configured cycle, and likely current cycle position. `app/src/main/java/com/dhangofa/networktoggle/cycle/TileCycleManager.java` validates and advances the user-defined two- or three-mode sequence. Core value types keep these decisions explicit: `model/ExecutionMode.java`, `model/NetworkMode.java`, and `model/TargetSim.java`.

#### Privileged Command Execution
The `command` package abstracts the privilege provider behind `app/src/main/java/com/dhangofa/networktoggle/command/CommandExecutor.java` and `CommandExecutorFactory.java`. Concrete executors select Root or Shizuku: `RootCommandExecutor.java` and `ShizukuCommandExecutor.java`. Process output is captured and normalized through `ProcessResultReader.java` and `StreamCollector.java`, producing structured results in `model/CommandResult.java`. This is the critical boundary between app logic and device/ROM-specific shell behavior.

#### Telephony Resolution and Mode Application
The telephony layer determines what can safely be offered and translates selected modes into platform-appropriate commands. `app/src/main/java/com/dhangofa/networktoggle/telephony/NetworkModeController.java` is the main application path, while `LegacyNetworkModeController.java` handles Android 7–11’s headless Java payload approach. `NetworkModePayload.java` represents command-ready mode data. On Android 12+, the README indicates native shell routing is used.

Before execution, `SimResolver.java` maps Auto/SIM targets to physical slots using Android subscription APIs, and `NetworkModeReader.java` reads current state where needed. `NetworkCapabilityResolver.java` filters unsupported radio modes; `LteAndAboveCarrierRegistry.java` supplies carrier constraints for 2G/3G sunset cases.

#### UI, Diagnostics, and External Dependencies
`app/src/main/java/com/dhangofa/networktoggle/ui/TileCycleUiController.java` binds activity UI interactions to preference/cycle configuration, with layouts rooted at `app/src/main/res/layout/activity_main.xml`. Failures and captured stdout/stderr are surfaced locally through `util/DiagnosticReporter.java` and `model/DiagnosticError.java`.

Material dependencies are Android system services (Quick Settings, telephony/subscription APIs), device Root tooling, or the separately installed/running Shizuku service. There is no app backend, telemetry, or network communication; GitHub/Telegram links are user-initiated only.

Main entry points: [`app/src/main/AndroidManifest.xml`](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/AndroidManifest.xml) (Android manifest), [`app/src/main/java/com/dhangofa/networktoggle/ui/TileCycleUiController.java`](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/ui/TileCycleUiController.java) (Tile cycle UI controller), [`app/src/main/java/com/dhangofa/networktoggle/telephony/NetworkModeController.java`](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/telephony/NetworkModeController.java) (Network mode controller), [`app/src/main/java/com/dhangofa/networktoggle/command/CommandExecutor.java`](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/command/CommandExecutor.java) (Command executor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_android["Android app"]
  node_build["Gradle app module<br/>Android build<br/>[build.gradle.kts]"]
  node_manifest["Android manifest<br/>component registration"]
  node_activity["Main activity<br/>configuration screen<br/>[MainActivity.java]"]
  node_tile["Network tile service<br/>Quick Settings service"]
  node_boot["Boot receiver<br/>[BootReceiver.java]"]
  node_ui["Tile cycle UI controller<br/>UI binding"]
  node_layout["Main layout<br/>Android layout<br/>[activity_main.xml]"]
  node_diagnostics["Diagnostic reporter<br/>local diagnostics"]
end

subgraph group_config["Configuration &amp; cycle"]
  node_preferences[("App preferences<br/>local persistence")]
  node_cycle["Tile cycle manager<br/>cycle state machine"]
  node_models["Mode and SIM models<br/>value types"]
end

subgraph group_telephony["Telephony application"]
  node_controller["Network mode controller<br/>mode application"]
  node_legacy["Legacy mode controller<br/>Android 7–11 path"]
  node_resolution["SIM, state &amp; capability resolution<br/>telephony resolution"]
end

subgraph group_commands["Privileged commands"]
  node_executor{{"Command executor factory<br/>privilege selection"}}
  node_command{{"Command executor<br/>command abstraction"}}
  node_result["Process results<br/>command output"]
end

subgraph group_platform["Device platform"]
  node_android_services{{"Android system services"}}
  node_root{{"Root tooling<br/>su provider"}}
  node_shizuku{{"Shizuku service<br/>privilege provider"}}
end

node_build -->|"packages"| node_manifest
node_manifest -->|"registers"| node_activity
node_manifest -->|"registers"| node_tile
node_manifest -->|"registers"| node_boot
node_activity -->|"hosts"| node_ui
node_ui -->|"binds"| node_layout
node_ui -->|"configures"| node_preferences
node_ui -->|"edits cycle"| node_cycle
node_tile -->|"advances"| node_cycle
node_cycle -->|"reads and saves state"| node_preferences
node_preferences -->|"persists"| node_models
node_tile -->|"applies next mode"| node_controller
node_controller -->|"resolves target and support"| node_resolution
node_resolution -->|"uses subscription APIs"| node_android_services
node_controller -.->|"uses on Android 7–11"| node_legacy
node_controller -->|"requests privileged execution"| node_executor
node_executor -->|"creates Root or Shizuku executor"| node_command
node_command -->|"executes via su"| node_root
node_command -->|"executes via service"| node_shizuku
node_command -->|"captures output"| node_result
node_result -->|"reports failures"| node_diagnostics
node_boot -->|"refreshes state"| node_tile

click node_build "https://github.com/dhangofa/nettoggle/blob/main/app/build.gradle.kts"
click node_manifest "https://github.com/dhangofa/nettoggle/blob/main/app/src/main/AndroidManifest.xml"
click node_activity "https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/MainActivity.java"
click node_tile "https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/NetworkTileService.java"
click node_boot "https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/BootReceiver.java"
click node_ui "https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/ui/TileCycleUiController.java"
click node_layout "https://github.com/dhangofa/nettoggle/blob/main/app/src/main/res/layout/activity_main.xml"
click node_preferences "https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/config/AppPreferences.java"
click node_cycle "https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/cycle/TileCycleManager.java"
click node_controller "https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/telephony/NetworkModeController.java"
click node_command "https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/command/CommandExecutor.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_build,node_manifest,node_activity,node_tile,node_boot,node_ui,node_layout,node_diagnostics toneBlue
class node_preferences,node_cycle,node_models toneAmber
class node_controller,node_legacy,node_resolution toneMint
class node_executor,node_command,node_result toneRose
class node_android_services,node_root,node_shizuku toneIndigo
```

## Components

### Android app

- [Gradle app module](https://github.com/dhangofa/nettoggle/blob/main/app/build.gradle.kts): Android build · Builds the single native app module. · `app/build.gradle.kts`
- [Android manifest](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/AndroidManifest.xml): component registration · `app/src/main/AndroidManifest.xml`
- [Main activity](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/MainActivity.java): configuration screen · `app/src/main/java/com/dhangofa/networktoggle/MainActivity.java`
- [Network tile service](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/NetworkTileService.java): Quick Settings service · Applies the next configured network mode on tile interaction. · `app/src/main/java/com/dhangofa/networktoggle/NetworkTileService.java`
- [Boot receiver](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/BootReceiver.java): boot receiver · Refreshes tile or app state after boot. · `app/src/main/java/com/dhangofa/networktoggle/BootReceiver.java`
- [Tile cycle UI controller](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/ui/TileCycleUiController.java): UI binding · `app/src/main/java/com/dhangofa/networktoggle/ui/TileCycleUiController.java`
- [Main layout](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/res/layout/activity_main.xml): Android layout · `app/src/main/res/layout/activity_main.xml`
- **Diagnostic reporter**: local diagnostics · Surfaces failures and captured command output locally.

### Configuration & cycle

- [App preferences](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/config/AppPreferences.java): local persistence · Stores execution mode, target SIM, cycle, and cycle position. · `app/src/main/java/com/dhangofa/networktoggle/config/AppPreferences.java`
- [Tile cycle manager](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/cycle/TileCycleManager.java): cycle state machine · Validates and advances two- or three-mode sequences. · `app/src/main/java/com/dhangofa/networktoggle/cycle/TileCycleManager.java`
- **Mode and SIM models**: value types · Execution mode, network mode, and target SIM decisions.

### Telephony application

- [Network mode controller](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/telephony/NetworkModeController.java): mode application · Main path translating a selected mode into device commands. · `app/src/main/java/com/dhangofa/networktoggle/telephony/NetworkModeController.java`
- **Legacy mode controller**: Android 7–11 path · Uses the headless Java payload approach.
- **SIM, state & capability resolution**: telephony resolution · Resolves slots, reads state, and filters unsupported or carrier-constrained modes.

### Privileged commands

- **Command executor factory**: privilege selection · Selects Root or Shizuku command execution.
- [Command executor](https://github.com/dhangofa/nettoggle/blob/main/app/src/main/java/com/dhangofa/networktoggle/command/CommandExecutor.java): command abstraction · Privileged shell boundary for Root and Shizuku executors. · `app/src/main/java/com/dhangofa/networktoggle/command/CommandExecutor.java`
- **Process results**: command output · Normalized stdout and stderr results.

### Device platform

- **Android system services**: Quick Settings & telephony APIs
- **Root tooling**: su provider
- **Shizuku service**: privilege provider · Separately installed and running service.

## Connections

- Gradle app module → Android manifest: packages
- Android manifest → Main activity: registers
- Android manifest → Network tile service: registers
- Android manifest → Boot receiver: registers
- Main activity → Tile cycle UI controller: hosts
- Tile cycle UI controller → Main layout: binds
- Tile cycle UI controller → App preferences: configures
- Tile cycle UI controller → Tile cycle manager: edits cycle
- Network tile service → Tile cycle manager: advances
- Tile cycle manager → App preferences: reads and saves state
- App preferences → Mode and SIM models: persists
- Network tile service → Network mode controller: applies next mode
- Network mode controller → SIM, state & capability resolution: resolves target and support
- SIM, state & capability resolution → Android system services: uses subscription APIs
- Network mode controller → Legacy mode controller: uses on Android 7–11
- Network mode controller → Command executor factory: requests privileged execution
- Command executor factory → Command executor: creates Root or Shizuku executor
- Command executor → Root tooling: executes via su
- Command executor → Shizuku service: executes via service
- Command executor → Process results: captures output
- Process results → Diagnostic reporter: reports failures
- Boot receiver → Network tile service: refreshes state
