mirror of
https://github.com/home-assistant/android
synced 2024-09-06 17:23:32 +00:00
Add toggle for Assist as assistant app on Wear (#3663)
Add toggle for assistant app intent filter on Wear - Adds a toggle for enabling/disabling Assist as an assistant app (= intent filter on Assist activity), as users may not be able to change the app used after choosing 'Always' and Wear OS 2 doesn't ask the user which app to use which can result in Assist instead of the Google Assistant being forced.
This commit is contained in:
parent
cd62f17fac
commit
00c2ef6d9e
|
@ -36,6 +36,7 @@
|
||||||
<string name="automation">Automation</string>
|
<string name="automation">Automation</string>
|
||||||
<string name="autoplay_video_summary">Autoplay Videos when dashboard is active. Enabling this setting may increase data usage unexpectedly, proceed with caution.</string>
|
<string name="autoplay_video_summary">Autoplay Videos when dashboard is active. Enabling this setting may increase data usage unexpectedly, proceed with caution.</string>
|
||||||
<string name="autoplay_video">Autoplay Videos</string>
|
<string name="autoplay_video">Autoplay Videos</string>
|
||||||
|
<string name="available_as_assistant_app">Available as assistant app</string>
|
||||||
<string name="background_access_disabled">Home Assistant does not have access to run in the background. Without this permission the app will not be able to reliably send data back to your server. Click here to request permissions.</string>
|
<string name="background_access_disabled">Home Assistant does not have access to run in the background. Without this permission the app will not be able to reliably send data back to your server. Click here to request permissions.</string>
|
||||||
<string name="background_access_enabled">Home Assistant has access to run in the background.</string>
|
<string name="background_access_enabled">Home Assistant has access to run in the background.</string>
|
||||||
<string name="background_access_title">Background Access</string>
|
<string name="background_access_title">Background Access</string>
|
||||||
|
|
|
@ -64,7 +64,6 @@
|
||||||
<activity android:name=".home.HomeActivity" />
|
<activity android:name=".home.HomeActivity" />
|
||||||
<activity android:name=".splash.SplashActivity"
|
<activity android:name=".splash.SplashActivity"
|
||||||
android:theme="@style/SplashTheme"
|
android:theme="@style/SplashTheme"
|
||||||
android:label="@string/app_name"
|
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
@ -96,12 +95,18 @@
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity-alias
|
||||||
|
android:name=".conversation.AssistantActivity"
|
||||||
|
android:targetActivity=".conversation.ConversationActivity"
|
||||||
|
android:label="@string/ha_assist"
|
||||||
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.ASSIST" />
|
<action android:name="android.intent.action.ASSIST" />
|
||||||
<action android:name="android.intent.action.VOICE_ASSIST"/>
|
<action android:name="android.intent.action.VOICE_ASSIST"/>
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity-alias>
|
||||||
|
|
||||||
<!-- Tiles -->
|
<!-- Tiles -->
|
||||||
<service
|
<service
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package io.homeassistant.companion.android.home
|
package io.homeassistant.companion.android.home
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
@ -12,6 +14,7 @@ import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||||
import androidx.lifecycle.AndroidViewModel
|
import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import io.homeassistant.companion.android.BuildConfig
|
||||||
import io.homeassistant.companion.android.HomeAssistantApplication
|
import io.homeassistant.companion.android.HomeAssistantApplication
|
||||||
import io.homeassistant.companion.android.common.data.integration.Entity
|
import io.homeassistant.companion.android.common.data.integration.Entity
|
||||||
import io.homeassistant.companion.android.common.data.integration.domain
|
import io.homeassistant.companion.android.common.data.integration.domain
|
||||||
|
@ -55,6 +58,8 @@ class MainViewModel @Inject constructor(
|
||||||
LOADING, READY, ERROR
|
LOADING, READY, ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val app = application
|
||||||
|
|
||||||
private lateinit var homePresenter: HomePresenter
|
private lateinit var homePresenter: HomePresenter
|
||||||
private var areaRegistry: List<AreaRegistryResponse>? = null
|
private var areaRegistry: List<AreaRegistryResponse>? = null
|
||||||
private var deviceRegistry: List<DeviceRegistryResponse>? = null
|
private var deviceRegistry: List<DeviceRegistryResponse>? = null
|
||||||
|
@ -114,6 +119,8 @@ class MainViewModel @Inject constructor(
|
||||||
private set
|
private set
|
||||||
var isFavoritesOnly by mutableStateOf(false)
|
var isFavoritesOnly by mutableStateOf(false)
|
||||||
private set
|
private set
|
||||||
|
var isAssistantAppAllowed by mutableStateOf(true)
|
||||||
|
private set
|
||||||
|
|
||||||
fun supportedDomains(): List<String> = HomePresenterImpl.supportedDomains
|
fun supportedDomains(): List<String> = HomePresenterImpl.supportedDomains
|
||||||
|
|
||||||
|
@ -136,6 +143,13 @@ class MainViewModel @Inject constructor(
|
||||||
templateTileContent.value = homePresenter.getTemplateTileContent()
|
templateTileContent.value = homePresenter.getTemplateTileContent()
|
||||||
templateTileRefreshInterval.value = homePresenter.getTemplateTileRefreshInterval()
|
templateTileRefreshInterval.value = homePresenter.getTemplateTileRefreshInterval()
|
||||||
isFavoritesOnly = homePresenter.getWearFavoritesOnly()
|
isFavoritesOnly = homePresenter.getWearFavoritesOnly()
|
||||||
|
|
||||||
|
val assistantAppComponent = ComponentName(
|
||||||
|
BuildConfig.APPLICATION_ID,
|
||||||
|
"io.homeassistant.companion.android.conversation.AssistantActivity"
|
||||||
|
)
|
||||||
|
isAssistantAppAllowed =
|
||||||
|
app.packageManager.getComponentEnabledSetting(assistantAppComponent) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,6 +494,19 @@ class MainViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setAssistantApp(allowed: Boolean) {
|
||||||
|
val assistantAppComponent = ComponentName(
|
||||||
|
BuildConfig.APPLICATION_ID,
|
||||||
|
"io.homeassistant.companion.android.conversation.AssistantActivity"
|
||||||
|
)
|
||||||
|
app.packageManager.setComponentEnabledSetting(
|
||||||
|
assistantAppComponent,
|
||||||
|
if (allowed) PackageManager.COMPONENT_ENABLED_STATE_DEFAULT else PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||||
|
PackageManager.DONT_KILL_APP
|
||||||
|
)
|
||||||
|
isAssistantAppAllowed = allowed
|
||||||
|
}
|
||||||
|
|
||||||
fun logout() {
|
fun logout() {
|
||||||
homePresenter.onLogoutClicked()
|
homePresenter.onLogoutClicked()
|
||||||
|
|
||||||
|
|
|
@ -142,10 +142,13 @@ fun LoadHomePage(
|
||||||
isHapticEnabled = mainViewModel.isHapticEnabled.value,
|
isHapticEnabled = mainViewModel.isHapticEnabled.value,
|
||||||
isToastEnabled = mainViewModel.isToastEnabled.value,
|
isToastEnabled = mainViewModel.isToastEnabled.value,
|
||||||
isFavoritesOnly = mainViewModel.isFavoritesOnly,
|
isFavoritesOnly = mainViewModel.isFavoritesOnly,
|
||||||
|
isAssistantAppAllowed = mainViewModel.isAssistantAppAllowed,
|
||||||
onHapticEnabled = { mainViewModel.setHapticEnabled(it) },
|
onHapticEnabled = { mainViewModel.setHapticEnabled(it) },
|
||||||
onToastEnabled = { mainViewModel.setToastEnabled(it) },
|
onToastEnabled = { mainViewModel.setToastEnabled(it) },
|
||||||
setFavoritesOnly = { mainViewModel.setWearFavoritesOnly(it) }
|
setFavoritesOnly = { mainViewModel.setWearFavoritesOnly(it) },
|
||||||
) { swipeDismissableNavController.navigate(SCREEN_SET_TILE_TEMPLATE) }
|
onClickTemplateTile = { swipeDismissableNavController.navigate(SCREEN_SET_TILE_TEMPLATE) },
|
||||||
|
onAssistantAppAllowed = mainViewModel::setAssistantApp
|
||||||
|
)
|
||||||
}
|
}
|
||||||
composable(SCREEN_SET_FAVORITES) {
|
composable(SCREEN_SET_FAVORITES) {
|
||||||
SetFavoritesView(
|
SetFavoritesView(
|
||||||
|
|
|
@ -70,10 +70,12 @@ fun SettingsView(
|
||||||
isHapticEnabled: Boolean,
|
isHapticEnabled: Boolean,
|
||||||
isToastEnabled: Boolean,
|
isToastEnabled: Boolean,
|
||||||
isFavoritesOnly: Boolean,
|
isFavoritesOnly: Boolean,
|
||||||
|
isAssistantAppAllowed: Boolean,
|
||||||
onHapticEnabled: (Boolean) -> Unit,
|
onHapticEnabled: (Boolean) -> Unit,
|
||||||
onToastEnabled: (Boolean) -> Unit,
|
onToastEnabled: (Boolean) -> Unit,
|
||||||
setFavoritesOnly: (Boolean) -> Unit,
|
setFavoritesOnly: (Boolean) -> Unit,
|
||||||
onClickTemplateTile: () -> Unit
|
onClickTemplateTile: () -> Unit,
|
||||||
|
onAssistantAppAllowed: (Boolean) -> Unit
|
||||||
) {
|
) {
|
||||||
val scalingLazyListState: ScalingLazyListState = rememberScalingLazyListState()
|
val scalingLazyListState: ScalingLazyListState = rememberScalingLazyListState()
|
||||||
|
|
||||||
|
@ -237,6 +239,37 @@ fun SettingsView(
|
||||||
onClick = onClickSensors
|
onClick = onClickSensors
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
item {
|
||||||
|
ListHeader(
|
||||||
|
id = commonR.string.assist
|
||||||
|
)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
ToggleChip(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
checked = isAssistantAppAllowed,
|
||||||
|
onCheckedChange = onAssistantAppAllowed,
|
||||||
|
label = {
|
||||||
|
Text(stringResource(commonR.string.available_as_assistant_app))
|
||||||
|
},
|
||||||
|
appIcon = {
|
||||||
|
Image(
|
||||||
|
asset = CommunityMaterial.Icon.cmd_comment_processing_outline,
|
||||||
|
colorFilter = ColorFilter.tint(wearColorPalette.onSurface)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
toggleControl = {
|
||||||
|
Icon(
|
||||||
|
imageVector = ToggleChipDefaults.switchIcon(isAssistantAppAllowed),
|
||||||
|
contentDescription = if (isFavoritesOnly) {
|
||||||
|
stringResource(commonR.string.enabled)
|
||||||
|
} else {
|
||||||
|
stringResource(commonR.string.disabled)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
item {
|
item {
|
||||||
ListHeader(
|
ListHeader(
|
||||||
id = commonR.string.account
|
id = commonR.string.account
|
||||||
|
@ -287,8 +320,11 @@ private fun PreviewSettingsView() {
|
||||||
isHapticEnabled = true,
|
isHapticEnabled = true,
|
||||||
isToastEnabled = false,
|
isToastEnabled = false,
|
||||||
isFavoritesOnly = false,
|
isFavoritesOnly = false,
|
||||||
|
isAssistantAppAllowed = true,
|
||||||
onHapticEnabled = {},
|
onHapticEnabled = {},
|
||||||
onToastEnabled = {},
|
onToastEnabled = {},
|
||||||
setFavoritesOnly = {}
|
setFavoritesOnly = {},
|
||||||
) {}
|
onClickTemplateTile = {},
|
||||||
|
onAssistantAppAllowed = {}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue