# evolution-x-devices/device_xiaomi_raphael architecture

> Architecture diagram of the GitHub repository evolution-x-devices/device_xiaomi_raphael, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/evolution-x-devices/device_xiaomi_raphael
- Repository: https://github.com/evolution-x-devices/device_xiaomi_raphael

## Overview

##### Project type and purpose
- This is an Android “device tree” / OS configuration project for the Redmi K20 Pro (codename “raphael”) maintained by LineageOS.
- It contains device-specific build scripts, HAL modules, init scripts, overlays, SELinux policies, and proprietary file lists to produce a custom Android system image for this hardware.

##### File structure
- Top-level files (Android.bp, .mk, proprietary-files.txt) orchestrate the Android.bp (Soong) build and legacy make build.
- Subdirectories represent distinct OS subsystems and services:
- init/ & libinit/ – device-specific init scripts (.rc, .sh) and initialization libraries
- camera/, audio in configs/, gps in configs/, sensors/, light/, livedisplay/, powerstats/ – native HAL implementations (HIDL or AIDL services)
- parts/ & rro_overlays/ – Android apps and runtime resource overlays for Settings, SystemUI, Telephony, etc.
- sepolicy/ – SELinux policies (public, private, vendor)
- seccomp/ – seccomp policies for media/codecs
- hidl/ – hardware interface definitions and compatibility matrices
- configs/ – XML and JSON hardware configuration files (audio policy, display, thermal, NFC, wifi, GPS)
- device.mk, BoardConfig.mk, AndroidProducts.mk, device prop files (.prop) configure product variables, partitions, kernel cmdline.

##### README
- Confirms that this repository supplies all device-specific bits (HAL services, drivers, configs) to build a LineageOS image for the Xiaomi Mi 9T Pro.

a. Main components:
- Bootloader & kernel (external to this repo, but implied by BoardConfig and device mk files)
- Init subsystem (init binaries + .rc scripts + libinit)
- Hardware Abstraction Layer: native daemons / HIDL services for camera, audio, sensors, light, powerstats, gps, seccomp policies
- SELinux enforcement (sepolicy)
- System partitions: system, system_ext, vendor, odm (with overlays)
- Android framework & apps (Settings, SystemUI, PopupCameraService, etc. under parts/)
- Runtime Resource Overlays (rROs) applied at boot (FrameworksResRaphael, SystemUIResRaphael, TelephonyResCommon, etc.)
- Proprietary libraries and blobs (listed in proprietary-files.txt)

b. Relationships and interactions:
- Bootloader loads kernel → kernel mounts /vendor, /system, /odm → init runs first .rc → loads libinit to set up Dalvik heap, services, filesystems
- init parses device’s init.qcom.rc and xiaomi.rc to start native HAL daemons: light, camera, livedisplay, sensors, powerstats, UDFPS, etc.
- Each HAL service registers with the HIDL service manager for framework to bind via binder IPC
- Android framework (system_server + Java services) invokes HAL interfaces through AIDL/HIDL proxies
- Parts apps (PopupCameraService, ClearSpeakerService) run in the Android app layer, receiving broadcasts from framework, interacting with HAL via Java APIs
- rRO overlays are mounted by vold at runtime to override resources in framework or vendor APKs
- SELinux policies restrict domain permissions for init, HAL daemons, system_server, apps
- Seccomp policies restrict syscalls in mediacodec, vendor systemd

c. Architectural patterns / design principles:
- Layered architecture: hardware drivers → HAL daemons → binder IPC → framework → apps
- Modularization via HIDL interfaces for each hardware domain
- Separation of concerns: configs in XML/JSON under configs/, policies under sepolicy/, code in directories by subsystem
- Soong (Android.bp) + legacy make for reproducible builds
- Runtime Resource Overlay (rRO) for customization without modifying core framework

d. Key technologies / frameworks / libraries:
- Android.bp & mk build system
- HIDL (android.hardware.*@x.x-service)
- SELinux (.te, property_contexts)
- seccomp
- Runtime Resource Overlay (RRO)
- Dalvik/ART initialization (libinit_dalvik_heap)
- Java services in parts/

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Boot & Kernel Layer
    subgraph "Boot & Kernel" 
        direction TB
        Bootloader["Bootloader"]:::native
        Kernel["Linux Kernel"]:::native
    end

    Bootloader -->|"loads"| Kernel

    %% Partitions
    subgraph "Partitions" 
        direction TB
        System["/system"]:::native
        Vendor["/vendor"]:::native
        ODM["/odm"]:::native
        SystemExt["/system_ext"]:::native
        Product["/product"]:::native
    end

    Kernel -->|"mounts"| System & Vendor & ODM & SystemExt & Product

    %% Init Subsystem
    subgraph "Init Subsystem" 
        direction TB
        InitScripts["init/*.rc scripts"]:::native
        LibInit["libinit (dalvik heap, utils)"]:::native
    end

    Kernel -->|"starts"| InitScripts
    InitScripts -->|"uses"| LibInit

    %% SELinux & Seccomp Config
    subgraph "Security & Config" 
        direction TB
        SELinux["sepolicy/ (SELinux policies)"]:::config
        Seccomp["seccomp/ (syscall filters)"]:::config
        Configs["configs/ (XML, JSON hardware configs)"]:::config
    end

    InitScripts -->|"enforces"| SELinux
    HALs -->|"restricted by"| Seccomp
    HALs -->|"reads"| Configs

    %% HAL Daemons Layer
    subgraph "HAL Daemons" 
        direction TB
        CameraHAL["CameraProviderExtension"]:::native
        LightHAL["Light HAL"]:::native
        LiveDisplayHAL["LiveDisplay HAL"]:::native
        PowerStatsHAL["PowerStats HAL"]:::native
        subgraph "Sensor HALs"
            direction TB
            DoubleTap["DoubleTap HAL"]:::native
            SingleTap["SingleTap HAL"]:::native
            UDFPSensor["UnderDisplayFingerprint HAL"]:::native
            UDFPSHandler["UDFPS Handler"]:::native
        end
        HIDLManager["HIDL Service Manager"]:::native
    end

    InitScripts -->|"start service"| CameraHAL & LightHAL & LiveDisplayHAL & PowerStatsHAL & DoubleTap & SingleTap & UDFPSensor & UDFPSHandler

    %% Interface with Framework
    subgraph "Android Framework" 
        direction TB
        SystemServer["system_server"]:::framework
    end

    SystemServer -->|"registers with"| HIDLManager
    SystemServer -->|"binder IPC calls"| CameraHAL & LightHAL & LiveDisplayHAL & PowerStatsHAL & DoubleTap & SingleTap & UDFPSensor & UDFPSHandler

    %% Runtime Resource Overlays
    subgraph "Runtime Resource Overlays" 
        direction TB
        RROFramework["Framework RROs"]:::overlay
        RROSystemUI["SystemUI RROs"]:::overlay
        RROTelephony["Telephony RROs"]:::overlay
        RRORest["Other RROs"]:::overlay
    end

    Vendor -->|"vold mounts"| RROFramework & RROSystemUI & RROTelephony & RRORest

    %% Android Parts (Apps & Services)
    subgraph "Android Parts (Apps & Services)" 
        direction TB
        PopupCamera["PopupCameraService"]:::app
        ClearSpeaker["ClearSpeakerService"]:::app
        SettingsUI["Settings UI Overlays"]:::app
    end

    SystemServer -->|"broadcasts"| PopupCamera & ClearSpeaker & SettingsUI
    PopupCamera & ClearSpeaker -->|"Java APIs -> HAL"| SystemServer

    %% Proprietary Blobs and Build Config
    subgraph "Build & Blobs" 
        direction TB
        AndroidBP["Android.bp & *.mk"]:::config
        ProprietaryList["proprietary-files.txt"]:::config
        DeviceProps["*.prop files"]:::config
    end

    AndroidBP & ProprietaryList & DeviceProps -->|"defines build"| InitScripts & HALs & SystemServer

    %% Click Events
    click InitScripts "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/init/"
    click LibInit "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/libinit/"
    click CameraHAL "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/camera/"
    click LightHAL "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/light/"
    click LiveDisplayHAL "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/livedisplay/"
    click PowerStatsHAL "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/powerstats/"
    click DoubleTap "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/sensors/double_tap/"
    click SingleTap "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/sensors/single_tap/"
    click UDFPSensor "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/sensors/udfps/"
    click UDFPSHandler "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/udfps/"
    click SELinux "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/sepolicy/"
    click Seccomp "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/seccomp/"
    click Configs "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/configs/"
    click RROFramework "https://github.com/evolution-x-devices/device_xiaomi_raphael/tree/vic/rro_overlays/"
    click AndroidBP "https://github.com/evolution-x-devices/device_xiaomi_raphael/blob/vic/Android.bp"
    click ProprietaryList "https://github.com/evolution-x-devices/device_xiaomi_raphael/blob/vic/proprietary-files.txt"
    click DeviceProps "https://github.com/evolution-x-devices/device_xiaomi_raphael/blob/vic/device.mk"
    classDef native fill:#D0E4F5,stroke:#4A90E2,stroke-width:1px
    classDef framework fill:#DFF5D0,stroke:#6AA845,stroke-width:1px
    classDef app fill:#DFF5D0,stroke:#6AA845,stroke-width:1px
    classDef config fill:#FFE4B5,stroke:#E89B00,stroke-width:1px
    classDef overlay fill:#E8D0F5,stroke:#9B4BE8,stroke-width:1px
```
