# darkstar085/device_xiaomi_whyred architecture

> Architecture diagram of the GitHub repository darkstar085/device_xiaomi_whyred, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/darkstar085/device_xiaomi_whyred
- Repository: https://github.com/darkstar085/device_xiaomi_whyred

## Overview

##### Project Type and Purpose
- This is an Android device-support (BSP/board configuration) repository for the Xiaomi Redmi Note 5 Pro (codename “whyred”) running LineageOS/Android.
- It contains device-specific build configs, hardware-abstraction-layer (HAL) modules, init scripts, resource overlays, policy files, proprietary file lists, and scripts to produce a flashable system image tailored to the SDM636 SoC platform.

##### File-Structure Analysis
- Top-level build files and device definitions:
- Android.bp / Android.mk / device.mk / BoardConfig.mk / product.mk
- configs/, compatibility_matrix.xml, proprietary-files.txt
- setup-makefiles.sh, extract-files.sh, reloade-libs.py
- Hardware Abstraction Layer (HAL) implementations under:
- audio/ (audio_policy, mixer_paths, platform info XMLs)
- gps/ (multiple versions of HIDL GNSS/GPS services, batching, geofence)
- ir/, light/, doze/ (doze service, IR consumer, light HAL)
- libshims/, libqti-perfd-client/ (vendor shims and performance-d client)
- Runtime & overlay artifacts:
- rootdir/ (init scripts, prebuilt shell scripts, fstab, ueventd)
- overlay-lineage/ and overlay/ and rro_overlays/ (resource overlays for frameworks and apps)
- sepolicy/ (SELinux policy modules for system and vendor apps)
- wifi/, keylayout/, idc/ (peripheral configs)
- Scripts & utilities:
- build helpers (reorder-libs.py, releasetools.py, update-sha1sums.py)
- flash_super_dummy.sh under partitions/

##### Architecture Insights from README
- Confirms device identity, SoC, Android version, and that this is a LineageOS device tree.

##### Components
a. Layers / Components
1. Build System Layer
- Android build (Soong/Make), device-specific Android.bp, Android.mk, BoardConfig, product.mk
- External scripts: extract-files.sh, setup-makefiles.sh
2. Kernel & Drivers Layer
- Linux kernel for SDM636 (outside this repo, but implied)
- Device drivers for GPS, audio codecs, sensors, light, IR
3. Vendor Binaries & Proprietary Blobs
- Lists in proprietary-files*.txt, shipped as vendor.img partitions
4. HAL Services Layer (HIDL / libbinder)
- audio HAL (audio_effects.xml, audio_policy_configuration.xml)
- gps / gnss HIDL services (versions 1.0,1.1,2.0 directories)
- light HAL service
- IR consumer HAL
- Doze Service (Java + native)
- libshims and performance client libraries
5. Init & Service Manager
- init scripts in rootdir/etc/*.rc, init_sdm660.cpp
- HIDL service registration (.rc files alongside HAL XML)
6. Android Framework Layer
- Framework APIs binding to HAL via HIDL interfaces
- Overlays (rro_overlays, overlay-lineage, overlay) that patch framework/UI resources
7. System Apps & Settings
- Dialer, Settings, SystemUI overlays customizing behavior/perms
8. SELinux Policy
- sepolicy/public, sepolicy/private, vendor policies governing access

b. Relationships & Data Flow
- Build System compiles HAL modules, resource overlays, and packages them with vendor blobs.
- At boot, init parses init.rc, invokes kernel modules, and starts HIDL HAL services.
- Services register with Android’s ServiceManager.
- Framework layers (e.g., AudioService, LocationManager) bind to these HIDL services to provide APIs to apps.
- Apps (Settings, Dialer, SystemUI) consume framework APIs for features like Doze, audio controls, location, IR transmitter.
- SELinux policy enforces access control between apps/framework and HAL processes.
- Overlays modify resource values in framework and system apps at runtime without rebuilding AOSP core.

c. Architectural Patterns & Principles
- Layered architecture: clear separation of kernel drivers, hardware abstraction (HAL), framework, and apps.
- Modular HAL: each hardware domain (audio, gps, light, IR) lives in its own HIDL service module.
- Resource-overlay mechanism for vendor customizations.
- SELinux enclaves to isolate process capabilities.
- Build-time composition using Soong/Make and script-driven blob extraction.

d. Key Technologies & Frameworks
- Android build (Soong + Make)
- HIDL (android.hardware.*@x.y)
- SELinux policies (sepolicy/)
- Resource overlays (RRO)
- Device init (init/*.rc, Android.bp)
- Vendor libraries (libqti-perfd, libshims)

##### Detail Level
- SELinux policy as a side-constraint layer on the runtime path.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Kernel & Drivers Layer
    subgraph "Kernel & Drivers"
        direction TB
        Kernel["Linux Kernel & Drivers"]:::infra
    end

    %% Vendor Blobs Layer
    subgraph "Vendor Blobs & Proprietary Binaries"
        direction TB
        PF1["proprietary-files.txt"]:::infra
        PF2["proprietary-files-whyred.txt"]:::infra
        PF3["proprietary-files-ir.txt"]:::infra
        PF4["proprietary-files-fm.txt"]:::infra
    end

    %% Build System Layer
    subgraph "Build System Layer"
        direction TB
        AndroidBP["Android.bp"]:::build
        AndroidMK["Android.mk"]:::build
        BoardConfig["BoardConfig.mk"]:::build
        DeviceMK["device.mk"]:::build
        AndroidProducts["AndroidProducts.mk"]:::build
        SetupMF["setup-makefiles.sh"]:::build
        ExtractFiles["extract-files.sh"]:::build
        ReorderLibs["reorder-libs.py"]:::build
        ReleaseTools["releasetools.py"]:::build
        UpdateSHA["update-sha1sums.py"]:::build
    end

    %% HAL Services Layer
    subgraph "HAL Services Layer"
        direction TB
        audioHAL["Audio HAL Service"]:::hal
        gpsHAL["GPS/GNSS HIDL Services"]:::hal
        irHAL["IR Consumer HAL Service"]:::hal
        lightHAL["Light HAL Service"]:::hal
        dozeService["Doze Service"]:::hal
        libShims["Vendor Shims (libshims)"]:::hal
        libPerf["Perf Client (libqti-perfd-client)"]:::hal
    end

    %% Init & Service Manager Layer
    subgraph "Init & Service Manager"
        direction TB
        InitSrc["init/init_sdm660.cpp"]:::runtime
        InitRC["rootdir/etc/*.rc"]:::runtime
    end

    %% Framework & Overlays Layer
    subgraph "Android Framework & Resource Overlays"
        direction TB
        FWAPIs["Framework APIs"]:::runtime
        Overlays["Resource Overlays"]:::runtime
    end

    %% System Apps Layer
    subgraph "System Apps & Settings"
        direction TB
        Apps["Dialer, Settings, SystemUI"]:::runtime
    end

    %% SELinux Policy Layer (side constraint)
    SELinux["SELinux Policies"]:::infra

    %% Relationships
    Kernel -->|interfaces| audioHAL
    Kernel -->|interfaces| gpsHAL
    Kernel -->|interfaces| irHAL
    Kernel -->|interfaces| lightHAL

    PF1 -->|provides blobs| audioHAL
    PF2 -->|provides blobs| gpsHAL
    PF3 -->|provides blobs| irHAL
    PF4 -->|provides blobs| lightHAL

    AndroidBP --> audioHAL
    AndroidMK --> audioHAL
    BoardConfig --> audioHAL
    DeviceMK --> audioHAL
    AndroidProducts --> audioHAL
    SetupMF --> ExtractFiles
    ExtractFiles --> audioHAL
    ReorderLibs --> audioHAL
    ReleaseTools --> audioHAL
    UpdateSHA --> audioHAL

    audioHAL --> InitSrc
    gpsHAL --> InitSrc
    irHAL --> InitSrc
    lightHAL --> InitSrc
    dozeService --> InitRC
    libShims --> InitRC
    libPerf --> InitRC

    InitSrc --> FWAPIs
    InitRC --> FWAPIs

    FWAPIs --> Apps
    Apps --> FWAPIs

    Overlays --> FWAPIs
    Overlays --> Apps

    SELinux -.-> FWAPIs
    SELinux -.-> Apps
    SELinux -.-> audioHAL

    %% Click Events
    click AndroidBP "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/Android.bp"
    click AndroidMK "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/Android.mk"
    click BoardConfig "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/BoardConfig.mk"
    click DeviceMK "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/device.mk"
    click AndroidProducts "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/AndroidProducts.mk"
    click SetupMF "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/setup-makefiles.sh"
    click ExtractFiles "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/extract-files.sh"
    click ReorderLibs "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/reorder-libs.py"
    click ReleaseTools "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/releasetools.py"
    click UpdateSHA "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/update-sha1sums.py"
    click PF1 "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/proprietary-files.txt"
    click PF2 "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/proprietary-files-whyred.txt"
    click PF3 "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/proprietary-files-ir.txt"
    click PF4 "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/proprietary-files-fm.txt"
    click audioHAL "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/audio/audio_policy_configuration.xml"
    click gpsHAL "https://github.com/darkstar085/device_xiaomi_whyred/tree/fourteen/gps/android/1.0/"
    click irHAL "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/ir/ConsumerIr.cpp"
    click lightHAL "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/light/Light.cpp"
    click dozeService "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/doze/Android.bp"
    click libShims "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/libshims/camera_sdm660_shim.cpp"
    click libPerf "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/libqti-perfd-client/Android.bp"
    click InitSrc "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/init/init_sdm660.cpp"
    click InitRC "https://github.com/darkstar085/device_xiaomi_whyred/blob/fourteen/rootdir/etc/init.*.rc"

    %% Styles
    classDef build fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef hal fill:#FFE5B4,stroke:#d2691e,color:#d2691e
    classDef runtime fill:#E2F0D9,stroke:#228B22,color:#228B22
    classDef infra fill:#F0F0F0,stroke:#808080,color:#808080
```
