Add support for voice command action (#4331)

* Add assistant headset support

* Revert AudioUrlPlayerService back to AudioUrlPlayer

* Address feedback
This commit is contained in:
Joseph 2024-04-20 06:46:35 -07:00 committed by GitHub
parent 4d9498c02b
commit 4965254a69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 1 deletions

View File

@ -403,6 +403,7 @@
android:theme="@style/Theme.HomeAssistant.Assist">
<intent-filter>
<action android:name="android.intent.action.ASSIST" />
<action android:name="android.intent.action.VOICE_COMMAND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

View File

@ -82,6 +82,9 @@ class AssistActivity : BaseActivity() {
},
startListening = if (intent.hasExtra(EXTRA_START_LISTENING)) {
intent.getBooleanExtra(EXTRA_START_LISTENING, true)
} else if (intent.action == Intent.ACTION_VOICE_COMMAND) {
// Always start listening if triggered via the voice command (e.g., from a BT headset).
true
} else {
null
}
@ -134,6 +137,11 @@ class AssistActivity : BaseActivity() {
viewModel.onPause()
}
override fun onDestroy() {
super.onDestroy()
viewModel.onDestroy()
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
this.intent = intent
@ -154,6 +162,7 @@ class AssistActivity : BaseActivity() {
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
} else {
setShowWhenLocked(true)
setTurnScreenOn(true)
}
} else {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) {

View File

@ -125,7 +125,7 @@ class AssistViewModel @Inject constructor(
fun onNewIntent(intent: Intent?, lockedMatches: Boolean) {
if (
(intent?.flags != null && intent.flags and Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT != 0) ||
intent?.action in listOf(Intent.ACTION_ASSIST, "android.intent.action.VOICE_ASSIST")
intent?.action in listOf(Intent.ACTION_ASSIST, "android.intent.action.VOICE_ASSIST", Intent.ACTION_VOICE_COMMAND)
) {
if (!lockedMatches && inputMode != AssistInputMode.BLOCKED) {
_conversation.clear()
@ -330,6 +330,11 @@ class AssistViewModel @Inject constructor(
fun onPause() {
requestPermission = null
stopRecording()
}
fun onDestroy() {
requestPermission = null
stopRecording()
stopPlayback()
}
}

View File

@ -421,6 +421,7 @@
android:theme="@style/Theme.HomeAssistant.Assist">
<intent-filter>
<action android:name="android.intent.action.ASSIST" />
<action android:name="android.intent.action.VOICE_COMMAND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>