Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ class AssistActivity : BaseActivity() {
private var contextIsLocked = true

companion object {
private const val EXTRA_SERVER = "server"
private const val EXTRA_PIPELINE = "pipeline"
private const val EXTRA_START_LISTENING = "start_listening"
private const val EXTRA_FROM_FRONTEND = "from_frontend"
private const val EXTRA_FROM_WAKE_WORD_PHRASE = "from_wake_word_phrase"
const val EXTRA_SERVER = "server"
const val EXTRA_PIPELINE = "pipeline"
const val EXTRA_START_LISTENING = "start_listening"
const val EXTRA_FROM_FRONTEND = "from_frontend"
const val EXTRA_FROM_WAKE_WORD_PHRASE = "from_wake_word_phrase"
const val EXTRA_TRIGGER_SOURCE = "trigger_source"
const val TRIGGER_SOURCE_ASSIST = "assist"
const val ACTION_TRIGGER_AUTOMOTIVE_ASSIST = "ACTION_TRIGGER_AUTOMOTIVE_ASSIST"
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACTION_TRIGGER_AUTOMOTIVE_ASSIST is a very generic intent action string. To avoid collisions (and accidental triggering by other apps), intent action constants should be fully qualified (e.g., include the application package).

Suggested change
const val ACTION_TRIGGER_AUTOMOTIVE_ASSIST = "ACTION_TRIGGER_AUTOMOTIVE_ASSIST"
const val ACTION_TRIGGER_AUTOMOTIVE_ASSIST =
"io.homeassistant.companion.android.assist.action.TRIGGER_AUTOMOTIVE_ASSIST"

Copilot uses AI. Check for mistakes.

fun newInstance(
context: Context,
Expand All @@ -61,13 +64,15 @@ class AssistActivity : BaseActivity() {
startListening: Boolean = true,
fromFrontend: Boolean = true,
wakeWordPhrase: String? = null,
triggerSource: String? = null,
): Intent {
return Intent(context, AssistActivity::class.java).apply {
putExtra(EXTRA_SERVER, serverId)
putExtra(EXTRA_PIPELINE, pipelineId)
putExtra(EXTRA_START_LISTENING, startListening)
putExtra(EXTRA_FROM_FRONTEND, fromFrontend)
putExtra(EXTRA_FROM_WAKE_WORD_PHRASE, wakeWordPhrase)
putExtra(EXTRA_TRIGGER_SOURCE, triggerSource)
}
}
}
Expand Down Expand Up @@ -113,6 +118,27 @@ class AssistActivity : BaseActivity() {
}

val fromFrontend = intent.getBooleanExtra(EXTRA_FROM_FRONTEND, false)
val triggerSource = intent.getStringExtra(EXTRA_TRIGGER_SOURCE)

if (triggerSource == TRIGGER_SOURCE_ASSIST) {
if (io.homeassistant.companion.android.vehicle.HaCarAppService.carInfo != null) {
val automotiveIntent = Intent(
io.homeassistant.companion.android.vehicle.HaCarAppService.ACTION_NAVIGATE_TO_AUTOMOTIVE_ASSIST,
).apply {
putExtra(
io.homeassistant.companion.android.vehicle.HaCarAppService.EXTRA_SERVER,
if (intent.hasExtra(EXTRA_SERVER)) {
intent.getIntExtra(EXTRA_SERVER, ServerManager.SERVER_ID_ACTIVE)
} else {
ServerManager.SERVER_ID_ACTIVE
},
)
}
sendBroadcast(automotiveIntent)
finish()
Comment on lines +125 to +138
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broadcast to navigate into automotive assist is implicit. Even with an app-specific action, it’s safer to scope it to your app (e.g., set the package/component) so no other app can receive/spoof it. Consider using an explicit intent targeting HaCarAppService (or at least setPackage(packageName)).

Copilot uses AI. Check for mistakes.
return
}
}

setContent {
if (viewModel.shouldFinish) {
Expand Down Expand Up @@ -166,6 +192,9 @@ class AssistActivity : BaseActivity() {

override fun onPause() {
super.onPause()
// The error says onPause() is protected in AssistViewModel.
// We need to call it, but it's protected.
// Let's see if we can change the visibility in AssistViewModel.
Comment on lines +195 to +197
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments are an internal note about a previous visibility issue and are now outdated (the ViewModel methods are overridden). Please remove them to keep production code clean.

Suggested change
// The error says onPause() is protected in AssistViewModel.
// We need to call it, but it's protected.
// Let's see if we can change the visibility in AssistViewModel.

Copilot uses AI. Check for mistakes.
viewModel.onPause()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package io.homeassistant.companion.android.assist

import android.content.Context
import androidx.core.content.getSystemService
import io.homeassistant.companion.android.assist.service.AssistVoiceInteractionService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,13 @@ class AssistViewModel @AssistedInject constructor(
if (!proactive) requestSilently = false
}

fun onPause() {
override fun onPause() {
requestPermission = null
inactivityTimerJob?.cancel()
stopRecording()
}

fun onDestroy() {
override fun onDestroy() {
requestPermission = null
inactivityTimerJob?.cancel()
stopRecording()
Expand Down
Loading