# Android Device Testing

## Prerequisites

```bash
# Check connected device
adb devices -l

# Verify Mosis app is installed
adb shell pm list packages | grep mosis
```

## Build and Install

```bash
# Build debug APK
./gradlew assembleDebug

# Install on device
adb install -r build/outputs/apk/debug/MosisService-debug.apk

# Launch the app
adb shell am start -n com.omixlab.mosis/.MainActivity
```

## Run Gradle Connected Tests

```bash
# Run all connected Android tests
./gradlew connectedAndroidTest
```

## Event Injection via ADB

Inject touch events for automated testing:

```bash
# Click at normalized coordinates (0.0-1.0)
adb shell am broadcast -a com.omixlab.mosis.INJECT_TOUCH \
    --es touch_type "click" --ef x 0.5 --ef y 0.5

# Touch down
adb shell am broadcast -a com.omixlab.mosis.INJECT_TOUCH \
    --es touch_type "down" --ef x 0.2 --ef y 0.9

# Touch up
adb shell am broadcast -a com.omixlab.mosis.INJECT_TOUCH \
    --es touch_type "up" --ef x 0.2 --ef y 0.9
```

## Dock Element Coordinates (Normalized)

| Element | X | Y |
|---------|---|---|
| dock-phone | 0.16 | 0.97 |
| dock-messages | 0.39 | 0.97 |
| dock-contacts | 0.61 | 0.97 |
| dock-browser | 0.84 | 0.97 |
| back-button | 0.10 | 0.05 |

## Full Navigation Test Sequence

```bash
# Clear logs and run navigation test sequence
adb logcat -c

# Click Phone dock icon
adb shell am broadcast -a com.omixlab.mosis.INJECT_TOUCH \
    --es touch_type "click" --ef x 0.16 --ef y 0.97
sleep 2

# Click back to return home
adb shell am broadcast -a com.omixlab.mosis.INJECT_TOUCH \
    --es touch_type "click" --ef x 0.1 --ef y 0.05
sleep 2

# Click Messages dock icon
adb shell am broadcast -a com.omixlab.mosis.INJECT_TOUCH \
    --es touch_type "click" --ef x 0.39 --ef y 0.97
sleep 2

# Click back to return home
adb shell am broadcast -a com.omixlab.mosis.INJECT_TOUCH \
    --es touch_type "click" --ef x 0.1 --ef y 0.05
sleep 2

# Click Contacts dock icon
adb shell am broadcast -a com.omixlab.mosis.INJECT_TOUCH \
    --es touch_type "click" --ef x 0.61 --ef y 0.97
sleep 2

# Click back to return home
adb shell am broadcast -a com.omixlab.mosis.INJECT_TOUCH \
    --es touch_type "click" --ef x 0.1 --ef y 0.05
sleep 2

# Click Browser dock icon
adb shell am broadcast -a com.omixlab.mosis.INJECT_TOUCH \
    --es touch_type "click" --ef x 0.84 --ef y 0.97
```

## Reading Logs

```bash
# Filter for Mosis logs
adb logcat -s MosisTest ServiceTester RMLUI

# Filter for navigation events
adb logcat -d | grep -iE "navigat|loaded|goBack|rml"

# Save to file
adb logcat -s MosisTest > mosis-log.txt

# Clear logs
adb logcat -c
```

## Expected Log Output

Successful navigation shows these log patterns:
```
RMLUI: navigateTo called with: dialer
Loading screen: apps/dialer/dialer.rml
RMLUI: Navigated to: dialer (history depth: 1)

RMLUI: goBack called (history depth: 1)
Loading screen: apps/home/home.rml
RMLUI: Back to: home
```
