mirror of
https://github.com/home-assistant/android
synced 2024-10-04 23:29:31 +00:00
Handle updated intents for Matter commissioning (#3535)
- It looks like fast pair/shared Matter devices now re-use the commissioning activity if it is still open in the background. Set the launch mode to single top to be able to use onNewIntent and get data for new devices.
This commit is contained in:
parent
f811c09175
commit
cb59ce1208
|
@ -14,7 +14,8 @@
|
|||
android:name=".matter.MatterCommissioningActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.HomeAssistant.Config">
|
||||
android:theme="@style/Theme.HomeAssistant.Config"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.android.gms.home.matter.ACTION_COMMISSION_DEVICE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.homeassistant.companion.android.matter
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.setContent
|
||||
|
@ -36,6 +37,7 @@ class MatterCommissioningActivity : AppCompatActivity() {
|
|||
private var deviceCode: String? = null
|
||||
private var deviceName by mutableStateOf<String?>(null)
|
||||
private var servers by mutableStateOf<List<Server>>(emptyList())
|
||||
private var newMatterDevice = false
|
||||
|
||||
private val threadPermissionLauncher = registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result ->
|
||||
deviceCode?.let { viewModel.onThreadPermissionResult(result, it) }
|
||||
|
@ -77,17 +79,24 @@ class MatterCommissioningActivity : AppCompatActivity() {
|
|||
|
||||
deviceName = data.deviceName
|
||||
deviceCode = data.manualPairingCode
|
||||
viewModel.checkSetup()
|
||||
viewModel.checkSetup(newMatterDevice)
|
||||
newMatterDevice = false
|
||||
} catch (e: SharedDeviceData.InvalidSharedDeviceDataException) {
|
||||
Log.e(TAG, "Received incomplete Matter commissioning data, launching webview")
|
||||
continueToApp(true)
|
||||
if (!newMatterDevice) continueToApp(true)
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "No Matter commissioning data, launching webview")
|
||||
continueToApp(true)
|
||||
if (!newMatterDevice) continueToApp(true)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
this.intent = intent // Data is handled by check in onResume()
|
||||
newMatterDevice = true
|
||||
}
|
||||
|
||||
private fun startCommissioning() {
|
||||
lifecycleScope.launch {
|
||||
val threadIntent = viewModel.syncThreadIfNecessary()
|
||||
|
|
|
@ -45,9 +45,13 @@ class MatterCommissioningViewModel @Inject constructor(
|
|||
var serverId by mutableStateOf(0)
|
||||
private set
|
||||
|
||||
fun checkSetup() {
|
||||
fun checkSetup(isNewDevice: Boolean) {
|
||||
viewModelScope.launch {
|
||||
if (step != CommissioningFlowStep.NotStarted) return@launch
|
||||
if (!isNewDevice && step != CommissioningFlowStep.NotStarted) {
|
||||
return@launch
|
||||
} else {
|
||||
step = CommissioningFlowStep.NotStarted
|
||||
}
|
||||
|
||||
if (!serverManager.isRegistered()) {
|
||||
step = CommissioningFlowStep.NotRegistered
|
||||
|
|
Loading…
Reference in a new issue