# h-mdm/hmdm-android architecture

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

- Interactive diagram: https://gitdiagram.com/h-mdm/hmdm-android
- Repository: https://github.com/h-mdm/hmdm-android

## Overview

##### Project Type & Purpose
- The project is clearly an Android-based, free and open-source Mobile Device Management (MDM) launcher. Its purpose is to manage enterprise Android devices – from device enrollment and configuration to remote management via push notifications and device policies.
- The README confirms it’s a mobile device management launcher with an emphasis on both an APK (app module) and a library (lib module) for integration.

##### Analyzing the File Structure
- The top-level structure separates the project into two principal modules:
- The “lib” module: This contains a reusable MDM functionality library. It includes core classes for MDM, such as HeadwindMDM, push handlers, and service interfaces (MDMService, MDMPushHandler, etc.), as well as its own Android resources.
- Other files indicate integration with build tools (gradle, fastlane metadata) and configuration for code optimization (proguard), which signals careful attention to code distribution and security.

##### Key Components to Capture
a. Main Components:
- App Module:
- User Interface Layer: Activities, layouts, custom UI components (e.g., BatteryStateView, dialogs, MainActivity, AdminActivity) contained under com/hmdm/launcher/ui.
- Service Layer: Background services and workers such as PushLongPollingService, LocationService, ServerService, and various PushNotificationWorker classes.
- Data/Database Layer: DatabaseHelper and related DB tables (DownloadTable, InfoHistoryTable, etc.) representing local data persistence.
- Communication Layer: Components handling remote connections. This includes REST/HTTP interactions (e.g., GetServerConfigTask, SendDeviceInfoTask) and push notifications – possibly using the MQTT library provided under org/eclipse/paho.
- Utility Modules: Helper classes (CertInstaller, ConfigUpdater, CryptoHelper, etc.), JSON model classes for network and configuration data, and logging utilities.
- Lib Module:
- Core MDM Functionality: Key classes such as HeadwindMDM, MDMService, and push handler components that encapsulate business logic for device management.
- API / Integration: AIDl interfaces and resources intended to be called or invoked by the app module.

b. Relationships and Interactions:
- The UI layer interacts with the service layer to initiate commands (e.g., admin tasks, device info updates, notifications).
- Services use background workers to perform tasks like fetching remote configuration, sending device information, and handling push notifications.
- Database operations are used for caching and storing device history, log configurations, and remote file information.
- The lib module is integrated into the app, providing MDM-specific functions that are abstracted away from the UI and service layers.
- External integrations include the MQTT client interactions (org/eclipse/paho libraries) and potential network API calls for remote management.

c. Architectural Patterns and Design Principles:
- The project follows a modular structure—with clear separation between the main application logic and the MDM library.
- There is an observable emphasis on separation of concerns: activities and UI components are distinct from business logic (helpers, services, and tasks) and database components.
- The use of worker classes denotes asynchronous/background processing typical to mobile applications.
- The structure may loosely follow an MVC/MVVM pattern in the way UI components are decoupled from data and network interactions.

d. Technologies and Frameworks:
- Android SDK: Underpins the overall project for UI and service components.
- Gradle: Build system and dependency management.
- Fastlane: Used for deployment and metadata management.
- MQTT (via Eclipse Paho): For push messaging interactions.
- JSON parsing for configuration and server responses.

## Diagram (Mermaid)

```mermaid
graph TB
    %% App Module
    subgraph "App Module"
        %% UI Layer
        subgraph "UI Layer"
            UI["Main UI & Activities"]:::UI
            UILayouts["UI Layouts"]:::UI
        end

        %% Service Layer
        subgraph "Service Layer"
            MainService["Main Services"]:::Service
            ProService["Pro Services"]:::Service
        end

        %% Data/Database Layer
        subgraph "Data Layer"
            Database["Database Layer"]:::Data
        end

        %% Communication/Task Layer
        subgraph "Communication / Task Layer"
            TaskLayer["Task Layer (REST & Notification Tasks)"]:::Task
        end

        %% Utility Modules
        subgraph "Utility Modules"
            Helpers["Helper Classes"]:::Helper
            Utils["Util Classes"]:::Helper
        end

        %% Background Workers/Push Processors
        subgraph "Background Workers / Push Processors"
            Workers["Background Workers"]:::Worker
            PushWorker["PushNotificationWorker"]:::Worker
        end

        %% Broadcast Receivers
        subgraph "Broadcast Receivers"
            Receivers["Broadcast Receivers"]:::Receiver
        end

        %% External Communication Integration
        subgraph "External Communication"
            MQTTNode["MQTT (Eclipse Paho)"]:::MQTT
        end
    end

    %% Lib Module
    subgraph "Lib Module"
        %% Core MDM Functionality
        subgraph "Core MDM Functionality"
            Headwind["HeadwindMDM"]:::Lib
            MDMService["MDMService"]:::Lib
            MDMPush["MDMPushHandler"]:::Lib
        end

        %% Service API / Integration Interface
        subgraph "Service API / Integration Interface"
            MdmApi["IMdmApi.aidl"]:::Lib
        end
    end

    %% Relationships in App Module
    UI -->|"triggers"| MainService
    UI -->|"renders"| UILayouts
    MainService -->|"calls"| ProService
    MainService -->|"uses"| Helpers
    MainService -->|"uses"| Utils
    MainService -->|"executes"| TaskLayer
    TaskLayer -->|"updates"| Database
    TaskLayer -->|"sends"| MQTTNode
    MainService -->|"initiates"| Workers
    Receivers -->|"triggers"| MainService
    Workers -->|"handles"| PushWorker
    PushWorker -->|"processes"| MDMPush

    %% Integration between App and Lib Modules
    MainService -->|"integrates"| Headwind
    MainService -->|"integrates"| MDMService

    %% Relationships within Lib Module
    Headwind -->|"coordinates"| MDMService
    MDMService -->|"utilizes"| MDMPush
    Headwind -->|"calls API"| MdmApi
    MDMService -->|"calls API"| MdmApi

    %% Click Events for App Module Components
    click UI "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/java/com/hmdm/launcher/ui"
    click UILayouts "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/res/layout"
    click MainService "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/java/com/hmdm/launcher/service"
    click ProService "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/java/com/hmdm/launcher/pro/service"
    click Database "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/java/com/hmdm/launcher/db"
    click TaskLayer "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/java/com/hmdm/launcher/task"
    click Helpers "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/java/com/hmdm/launcher/helper"
    click Utils "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/java/com/hmdm/launcher/util"
    click Workers "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/java/com/hmdm/launcher/worker"
    click PushWorker "https://github.com/h-mdm/hmdm-android/blob/master/app/src/main/java/com/hmdm/launcher/worker/PushNotificationWorker.java"
    click Receivers "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/java/com/hmdm/launcher/receiver"
    click MQTTNode "https://github.com/h-mdm/hmdm-android/tree/master/app/src/main/java/org/eclipse/paho/android/service"

    %% Click Events for Lib Module Components
    click Headwind "https://github.com/h-mdm/hmdm-android/blob/master/lib/src/main/java/com/hmdm/HeadwindMDM.java"
    click MDMService "https://github.com/h-mdm/hmdm-android/blob/master/lib/src/main/java/com/hmdm/MDMService.java"
    click MDMPush "https://github.com/h-mdm/hmdm-android/blob/master/lib/src/main/java/com/hmdm/MDMPushHandler.java"
    click MdmApi "https://github.com/h-mdm/hmdm-android/blob/master/lib/src/main/aidl/com/hmdm/IMdmApi.aidl"

    %% Styles
    classDef UI fill:#a1c4fd,stroke:#000,stroke-width:1px;
    classDef Service fill:#c1f0c1,stroke:#000,stroke-width:1px;
    classDef Data fill:#f9c2c2,stroke:#000,stroke-width:1px;
    classDef Task fill:#ffefd5,stroke:#000,stroke-width:1px;
    classDef Helper fill:#edd4f2,stroke:#000,stroke-width:1px;
    classDef Worker fill:#ffd1dc,stroke:#000,stroke-width:1px;
    classDef Receiver fill:#e0e0e0,stroke:#000,stroke-width:1px;
    classDef MQTT fill:#ffffcc,stroke:#000,stroke-width:1px;
    classDef Lib fill:#d1f7c4,stroke:#000,stroke-width:1px;
```
