diff --git a/app/src/main/java/com/openclaw/assistant/service/HotwordService.kt b/app/src/main/java/com/openclaw/assistant/service/HotwordService.kt index 42463121..1e1e50b7 100644 --- a/app/src/main/java/com/openclaw/assistant/service/HotwordService.kt +++ b/app/src/main/java/com/openclaw/assistant/service/HotwordService.kt @@ -55,10 +55,18 @@ class HotwordService : Service(), VoskRecognitionListener { } } catch (e: IllegalStateException) { Log.e(TAG, "Background execution limits prevented starting HotwordService: ${e.message}", e) - context.stopService(intent) + try { + context.stopService(intent) + } catch (e2: Exception) { + Log.e(TAG, "Failed to stopService in IllegalStateException handler", e2) + } } catch (e: SecurityException) { Log.e(TAG, "Security limits prevented starting HotwordService: ${e.message}", e) - context.stopService(intent) + try { + context.stopService(intent) + } catch (e2: Exception) { + Log.e(TAG, "Failed to stopService in SecurityException handler", e2) + } } catch (e: Exception) { Log.e(TAG, "Failed to start HotwordService: ${e.message}", e) } diff --git a/app/src/main/java/com/openclaw/assistant/service/NodeForegroundService.kt b/app/src/main/java/com/openclaw/assistant/service/NodeForegroundService.kt index 031bf835..e8b72d20 100644 --- a/app/src/main/java/com/openclaw/assistant/service/NodeForegroundService.kt +++ b/app/src/main/java/com/openclaw/assistant/service/NodeForegroundService.kt @@ -285,10 +285,18 @@ class NodeForegroundService : Service() { context.startService(intent) } catch (e: IllegalStateException) { android.util.Log.w(TAG, "Failed to send ACTION_STOP via startService, falling back to stopService", e) - context.stopService(intent) + try { + context.stopService(intent) + } catch (stopEx: Exception) { + android.util.Log.e(TAG, "Failed to stopService in IllegalStateException handler", stopEx) + } } catch (e: SecurityException) { android.util.Log.w(TAG, "Failed to send ACTION_STOP via startService, falling back to stopService", e) - context.stopService(intent) + try { + context.stopService(intent) + } catch (stopEx: Exception) { + android.util.Log.e(TAG, "Failed to stopService in SecurityException handler", stopEx) + } } catch (e: Exception) { android.util.Log.w(TAG, "Failed to send ACTION_STOP via startService, falling back to stopService", e) try { diff --git a/app/src/main/java/com/openclaw/assistant/service/SessionForegroundService.kt b/app/src/main/java/com/openclaw/assistant/service/SessionForegroundService.kt index 57a0b80e..ba6affc7 100644 --- a/app/src/main/java/com/openclaw/assistant/service/SessionForegroundService.kt +++ b/app/src/main/java/com/openclaw/assistant/service/SessionForegroundService.kt @@ -40,10 +40,18 @@ class SessionForegroundService : Service() { } } catch (e: IllegalStateException) { Log.e(TAG, "Background execution limits prevented starting SessionForegroundService: ${e.message}", e) - context.stopService(intent) + try { + context.stopService(intent) + } catch (e2: Exception) { + Log.e(TAG, "Failed to stopService in IllegalStateException handler", e2) + } } catch (e: SecurityException) { Log.e(TAG, "Security limits prevented starting SessionForegroundService: ${e.message}", e) - context.stopService(intent) + try { + context.stopService(intent) + } catch (e2: Exception) { + Log.e(TAG, "Failed to stopService in SecurityException handler", e2) + } } catch (e: Exception) { Log.e(TAG, "Failed to start SessionForegroundService: ${e.message}", e) }