How iamr0s/dhizuku works
Main Components
• App Module (UI & Logic): This contains the Android application itself. Break it down into:
– UI Layer: Activities, pages, and themes (packages like ui.activity, ui.page, ui/theme).
– Data Layer: Data models (both “common” and “settings”), Room database integration (evident from the “room” subdirectories, dao, entity, repository implementations) and util classes.
– Service/Server Layer: Components that handle background tasks or system events (e.g., BootCompleteReceiver, DhizukuDAReceiver, MyDhizukuService, RunningService).
– Dependency Injection (DI): Modules for initializing app-wide dependencies (look at di/init, di/preferences_module, etc.).
• Hidden API Module: A separate module that mimics Android’s internal (hidden) APIs. It contains lower-level classes (ActivityThread, ContextImpl, IDevicePolicyManager, etc.) to facilitate privileged operations.
• Build & Configuration Components: Though not “functional” components, the existence of Gradle scripts, build configuration files, and keystore files imply structured build/deployment pipelines.
Relationships and Interactions
• The UI layer communicates with ViewModels (appearing in various ui/page sub-packages) using the MVVM pattern. ViewModels in turn interact with the data layer (repositories in data/settings/repo and DAO classes under data/settings/model/room/dao).
• The DI layer (under di/*) is responsible for instantiating and wiring together the UI controllers, ViewModels, data repositories, and other utilities to promote clean dependency management.
• The Service/Server layer (under server/*) listens to system events (via receivers like BootCompleteReceiver) and manages background operations, leveraging components in the hidden-api module where necessary.
• The Hidden API module is invoked when needing to access Android internals (e.g., DeviceOwner APIs) that are not public. It serves as the low-level abstraction layer for bypassing some of the typical restrictions.
Architectural Patterns & Principles
• MVVM Pattern: Seen via separation into UI pages, view states, view data, and view models.
• Repository & DAO Pattern: For managing data persistence (e.g., Room database related packages).
• Dependency Injection: The use of DI modules indicates reliance on DI frameworks (or a custom DI setup).
• Layered Architecture: Clear separation between UI, business logic, local data storage, and system-level calls (via the hidden API).
Relevant Technologies and Frameworks
• Android SDK: Given the AndroidManifest.xml and resource directories.
• Room Database: Based on the “room” folder structure for data storage.
• Gradle Kotlin DSL: As shown by build.gradle.kts and related Gradle configurations.
• Possibly a DI framework (either Dagger, Koin, or a custom implementation indicated by the “di” packages).
• Custom handling of hidden APIs: Provided by the “hidden-api” module.
Elements
– “App Module” with subdivisions: UI, Data Layer, Service Layer, DI Container.
– “Hidden API Module” for low-level Android system interactions.
• Connection with brief descriptions (e.g., “sends event”, “fetches data”, “initializes service”).
• Don’t overcomplicate by including every single utility class; focus on the architectural layers and their interactions.