# App Discovery System Local app discovery without requiring a backend server. ## Status | Feature | Status | |---------|--------| | Directory scanning | βœ… Implemented | | Manifest parsing | βœ… Implemented | | Home screen rendering | βœ… Implemented | | App launching | πŸ”„ In Progress | | Package installation | ⏳ Planned | ## Overview ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Home Screen β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Dialer β”‚ β”‚ Messagesβ”‚ β”‚ TestApp β”‚ β”‚ MyApp β”‚ ← scanned β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ from β”‚ β”‚ apps/ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ /data/data/com.omixlab.mosis/files/ β”‚ β”‚ β”œβ”€β”€ apps/ ← Installed third-party apps β”‚ β”‚ β”‚ β”œβ”€β”€ com.mosis.testapp/ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ manifest.json ← App metadata β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ main.rml ← Entry point β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ app.lua β”‚ β”‚ β”‚ β”‚ └── icon.tga β”‚ β”‚ β”‚ └── com.example.myapp/ β”‚ β”‚ β”‚ └── ... β”‚ β”‚ β”œβ”€β”€ downloads/ ← Pending .mosis packages β”‚ β”‚ └── config/ β”‚ β”‚ └── apps.json ← App registry (optional cache) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## Discovery Flow ### Phase 1: Direct Folder Discovery (MVP) βœ… 1. **On boot**: Home screen calls `mosis.apps.getInstalled()` 2. **AppManager** scans `/files/apps/` for folders containing `manifest.json` 3. **For each app**: Read manifest, extract name/icon/entry point 4. **Home screen**: Render app grid with icons 5. **On tap**: Launch app via `mosis.apps.launch(package_id)` ### Phase 2: Package Installation (Future) 1. User copies `.mosis` file to `/files/downloads/` 2. Store app or file manager shows pending packages 3. User taps "Install" β†’ `mosis.apps.install(path)` 4. Package extracted to `/files/apps/{package_id}/` 5. Home screen refreshes to show new app ## Implementation ### AppManager (C++) The `AppManager::ScanAppsDirectory()` method scans for installed apps: ```cpp // app_manager.cpp void AppManager::ScanAppsDirectory() { std::string apps_dir = m_data_root + "/apps"; for (const auto& entry : fs::directory_iterator(apps_dir)) { if (!entry.is_directory()) continue; // Look for manifest.json std::string manifest_path = entry.path().string() + "/manifest.json"; // Parse and register app... } } ``` ### Lua API ```lua -- Get all installed apps (system + third-party) local apps = mosis.apps.getInstalled() -- Returns: [{package_id, name, icon_path, entry, version, is_system_app}, ...] -- Launch an app mosis.apps.launch("com.mosis.testapp") -- Check if app is running local running = mosis.apps.isRunning("com.mosis.testapp") ``` ### Home Screen (home.lua) The home screen dynamically renders third-party apps: ```lua function initHome(doc) -- Get installed apps, filter to third-party only local apps = mosis.apps.getInstalled() for _, app in ipairs(apps) do if not app.is_system_app then -- Render app icon end end end function launchThirdPartyApp(package_id) mosis.apps.launch(package_id) end ``` ## Test App Deployment To deploy a test app manually: ```bash # 1. Push to temp location (avoid permission issues) adb push test-apps/com.mosis.sandbox-test/ //data/local/tmp/com.mosis.sandbox-test/ # 2. Copy to app's private storage adb shell "run-as com.omixlab.mosis cp -r /data/local/tmp/com.mosis.sandbox-test /data/data/com.omixlab.mosis/files/apps/" # 3. Verify adb shell "run-as com.omixlab.mosis ls /data/data/com.omixlab.mosis/files/apps/com.mosis.sandbox-test/" ``` For Desktop Designer: ```bash # Copy to designer's sandbox_data folder cp -r test-apps/com.mosis.sandbox-test/ designer/build/Debug/sandbox_data/apps/ ``` ## App Manifest Format ```json { "id": "com.mosis.testapp", "name": "Test App", "version": "1.0.0", "version_code": 1, "entry": "main.rml", "icon": "icon.tga", "description": "A test application", "permissions": ["storage", "network"] } ``` ## Directory Structure ### System Apps (bundled in APK assets) ``` assets/apps/ β”œβ”€β”€ home/ # Home screen (always loaded) β”œβ”€β”€ dialer/ β”œβ”€β”€ messages/ β”œβ”€β”€ contacts/ β”œβ”€β”€ settings/ β”œβ”€β”€ browser/ └── store/ ``` ### Third-Party Apps (in private storage) ``` /data/data/com.omixlab.mosis/files/apps/ β”œβ”€β”€ com.mosis.testapp/ β”‚ β”œβ”€β”€ manifest.json β”‚ β”œβ”€β”€ main.rml β”‚ β”œβ”€β”€ app.lua β”‚ β”œβ”€β”€ styles.rcss β”‚ └── icon.tga └── com.example.game/ └── ... ``` ## Future Enhancements 1. **Package signature verification** before installation 2. **Version tracking** in apps.json registry 3. **Update detection** by comparing version_code 4. **Uninstall** with data cleanup option 5. **Store integration** for HTTP-based discovery