# Alfred Mobile v1.1.11 - Wake Word in Service

**Release Date:** 2026-02-08

## Changes

### Wake Word Detection Moved to Foreground Service

**Problem:** Wake word detector was stopping after a few seconds with "No speech detected - try again" error. It was managed by MainScreen and didn't survive screen-off or app backgrounding.

**Solution:** Moved wake word lifecycle management into `AlfredConnectionService` foreground service for continuous, uninterrupted listening.

### Implementation Details

#### 1. Updated GatewayListener Interface
- **File:** `app/src/main/java/com/openclaw/alfred/gateway/GatewayClient.kt`
- **Change:** Added `onWakeWordDetected()` method to interface

#### 2. Enhanced AlfredConnectionService
- **File:** `app/src/main/java/com/openclaw/alfred/service/AlfredConnectionService.kt`
- **Changes:**
  - Added `wakeWordDetector` and `wakeWordEnabled` fields
  - Added `startWakeWord()` method to initialize and start wake word detection
  - Added `stopWakeWord()` method to stop detection
  - Updated notification text to show "Listening for wake word..." when active
  - Added auto-restart on errors (except permission errors)
  - Added proper cleanup in `onDestroy()`
  - Forwarding `onWakeWordDetected()` events to external listener

#### 3. Updated MainScreen
- **File:** `app/src/main/java/com/openclaw/alfred/ui/screens/MainScreen.kt`
- **Changes:**
  - Removed local `WakeWordDetector` initialization from `LaunchedEffect(Unit)`
  - Replaced `LaunchedEffect(wakeWordEnabled, wakeWordInitialized)` with simpler `LaunchedEffect(wakeWordEnabled, serviceBound)` that delegates to service
  - Implemented `onWakeWordDetected()` callback to handle wake word detection from service
  - Wake word now managed entirely by the service

#### 4. Improved WakeWordDetector
- **File:** `app/src/main/java/com/openclaw/alfred/voice/WakeWordDetector.kt`
- **Change:** Enhanced logging in `onTimeout()` to clarify continuous mode operation

## Benefits

1. **Continuous Listening:** Wake word detector runs continuously without timeouts
2. **Survives Background:** Works even when app is backgrounded or screen is off
3. **Doze Mode Compatible:** Foreground service survives Android Doze mode
4. **Auto-Recovery:** Automatically restarts on errors (except permissions)
5. **Visual Feedback:** Notification shows "Listening for wake word..." status

## Testing Checklist

- [x] Build successful (v1.1.11)
- [ ] Toggle wake word ON in Settings
- [ ] Verify notification changes to "Listening for wake word..."
- [ ] Test wake word detection works continuously
- [ ] Lock screen → wake word still works
- [ ] Background app → wake word still works
- [ ] Saying "alfred" triggers voice input
- [ ] After voice input completes, wake word resumes automatically

## Deployment

- **Tablet:** Deployed via ADB to `adb-R52R30ASB4Y-BIkpas._adb-tls-connect._tcp`
- **Phone APK:** Copied to `/mnt/c/users/shado/alfred-mobile-v1.1.11.apk`
- **Version Code:** 13
- **Version Name:** 1.1.11

## Files Modified

1. `app/build.gradle.kts` - Updated version to 1.1.11 (versionCode: 13)
2. `app/src/main/java/com/openclaw/alfred/gateway/GatewayClient.kt` - Added `onWakeWordDetected()` to interface
3. `app/src/main/java/com/openclaw/alfred/service/AlfredConnectionService.kt` - Added wake word management
4. `app/src/main/java/com/openclaw/alfred/ui/screens/MainScreen.kt` - Delegated wake word to service
5. `app/src/main/java/com/openclaw/alfred/voice/WakeWordDetector.kt` - Improved logging

## Next Steps

1. Force stop app on tablet
2. Restart app
3. Go to Settings
4. Enable wake word
5. Verify continuous listening works as expected
6. Test all scenarios in the checklist above
