# Installation Guide

> This build uses **no Firebase / FCM**. Commands and notifications are delivered
> to devices via secure polling (WorkManager heartbeat + `command_fetch`).
> Production domain: **https://emimobilelock.lovableultimate.shop**

## 1. Backend (cPanel / shared hosting)
1. Upload the whole `MDM-System` folder (except `Android-App/`) to the site root of
   your subdomain, so the API lives at `https://emimobilelock.lovableultimate.shop/API/`.
2. Ensure PHP **8.3** and **MySQL** are enabled, with the PDO-MySQL and cURL extensions.
3. Visit `https://emimobilelock.lovableultimate.shop/install.php` in a browser.
4. Enter database credentials, create the admin account, and optionally add your
   Google Maps API key.
5. On success, **delete `install.php`**.
6. Log in at `https://emimobilelock.lovableultimate.shop/Admin-Panel/login.php`.

The installer creates the database, imports `SQL/database.sql`, writes
`API/config.php` and `Admin-Panel/config.php`, and generates random JWT/AES secrets.

### Manual install (alternative)
- Create a MySQL database and import `SQL/database.sql`.
- Edit `API/config.php` and `Admin-Panel/config.php` (or set the `MDM_*` env vars).
- Insert an admin: `INSERT INTO admins(name,email,password_hash,role) VALUES('Admin','admin@x.com','<bcrypt>','superadmin');`
  Generate the hash with `php -r "echo password_hash('yourpass', PASSWORD_DEFAULT);"`.

## 2. Android App
1. Open `Android-App/` in **Android Studio (latest)**.
2. Copy `local.properties.SAMPLE` → `local.properties`, set your SDK path.
3. `API_BASE_URL` is already set to `https://emimobilelock.lovableultimate.shop/API/`
   in `app/build.gradle.kts` — change it only if you move the backend.
4. Sync Gradle, then **Build → Generate Signed Bundle / APK** (or Run).

No `google-services.json` is required — this build has no Firebase dependency.

## 3. Device Owner provisioning (company-owned)
Provision on a **factory-reset device** using an Android Enterprise method (QR code,
`adb shell dpm set-device-owner com.enterprise.mdm/.device.MdmDeviceAdminReceiver`
on a test device, or an EMM token). Device Owner is required for factory reset and
password policy. Basic Device Admin (lock, wallpaper) works without full owner mode.

## 4. How command delivery works (polling)
The device agent runs a periodic `SyncWorker` (every 15 min, WorkManager minimum)
that calls `heartbeat`, syncs status, and fetches pending commands. Open the app or
trigger a manual sync for near-immediate pickup. No push service is used.
