Add toggle for voice command intent with Assist (#4478)

This commit is contained in:
Joris Pelgröm 2024-06-26 06:46:52 +02:00 committed by GitHub
parent 3d7aa93d5f
commit 50506f06ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 52 additions and 2 deletions

View file

@ -408,10 +408,18 @@
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>
<activity-alias
android:name=".assist.VoiceCommandIntentActivity"
android:targetActivity=".assist.AssistActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VOICE_COMMAND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity-alias>
<activity android:name=".widgets.assist.AssistShortcutActivity"
android:label="@string/assist_shortcut"

View file

@ -543,6 +543,8 @@ class SettingsFragment(
}
}
override fun getPackageManager(): PackageManager? = context?.packageManager
override fun onPause() {
super.onPause()
snackbar?.dismiss()

View file

@ -1,7 +1,9 @@
package io.homeassistant.companion.android.settings
import android.app.role.RoleManager
import android.content.ComponentName
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.provider.Settings
import android.util.Log
@ -61,6 +63,11 @@ class SettingsPresenterImpl @Inject constructor(
private lateinit var view: SettingsView
private val voiceCommandAppComponent = ComponentName(
BuildConfig.APPLICATION_ID,
"io.homeassistant.companion.android.assist.VoiceCommandIntentActivity"
)
private var suggestionFlow = MutableStateFlow<SettingsHomeSuggestion?>(null)
override fun getBoolean(key: String, defValue: Boolean): Boolean = runBlocking {
@ -71,6 +78,10 @@ class SettingsPresenterImpl @Inject constructor(
"crash_reporting" -> prefsRepository.isCrashReporting()
"autoplay_video" -> prefsRepository.isAutoPlayVideoEnabled()
"always_show_first_view_on_app_start" -> prefsRepository.isAlwaysShowFirstViewOnAppStartEnabled()
"assist_voice_command_intent" -> {
val componentSetting = view.getPackageManager()?.getComponentEnabledSetting(voiceCommandAppComponent)
componentSetting != null && componentSetting != PackageManager.COMPONENT_ENABLED_STATE_DISABLED
}
else -> throw IllegalArgumentException("No boolean found by this key: $key")
}
}
@ -84,6 +95,12 @@ class SettingsPresenterImpl @Inject constructor(
"crash_reporting" -> prefsRepository.setCrashReporting(value)
"autoplay_video" -> prefsRepository.setAutoPlayVideo(value)
"always_show_first_view_on_app_start" -> prefsRepository.setAlwaysShowFirstViewOnAppStart(value)
"assist_voice_command_intent" ->
view.getPackageManager()?.setComponentEnabledSetting(
voiceCommandAppComponent,
if (value) PackageManager.COMPONENT_ENABLED_STATE_DEFAULT else PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
)
else -> throw IllegalArgumentException("No boolean found by this key: $key")
}
}

View file

@ -1,5 +1,8 @@
package io.homeassistant.companion.android.settings
import android.content.pm.PackageManager
interface SettingsView {
fun onAddServerResult(success: Boolean, serverId: Int?)
fun getPackageManager(): PackageManager?
}

View file

@ -0,0 +1 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24"><path android:fillColor="@color/colorAccent" android:pathData="M12,1A9,9 0 0,1 21,10V17A3,3 0 0,1 18,20H15V12H19V10A7,7 0 0,0 12,3A7,7 0 0,0 5,10V12H9V20H6A3,3 0 0,1 3,17V10A9,9 0 0,1 12,1M15,24V22H17V24H15M11,24V22H13V24H11M7,24V22H9V24H7Z" /></vector>

View file

@ -123,6 +123,15 @@
android:icon="@drawable/ic_notifications"
android:summary="@string/rate_limit_summary"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/assist"
android:key="assist">
<SwitchPreference
android:key="assist_voice_command_intent"
android:icon="@drawable/ic_headphones_settings"
android:title="@string/open_with_headphone_button"
android:summary="@string/open_with_headphone_button_summary" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/basic_sensor_name_android_auto"
android:key="android_auto">

View file

@ -421,10 +421,18 @@
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>
<activity-alias
android:name=".assist.VoiceCommandIntentActivity"
android:targetActivity=".assist.AssistActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VOICE_COMMAND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity-alias>
<provider
android:name="androidx.core.content.FileProvider"

View file

@ -489,6 +489,8 @@
<string name="onboarding_notifications_bullet_alert">Get alerted from notifications</string>
<string name="onboarding_notifications_bullet_commands">Send commands to your device</string>
<string name="onboarding_notifications_subtitle">Enable notifications to create a notify service for your device</string>
<string name="open_with_headphone_button">Open with headset button</string>
<string name="open_with_headphone_button_summary">Use Assist with the assistant/voice command button on supported headphones and earbuds</string>
<string name="other_settings">Other settings</string>
<string name="other">Other</string>
<string name="password">Password</string>