From 6609d2122df8e0339753eaa77921f79f7095adb3 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 1 Sep 2023 08:50:31 +0200 Subject: [PATCH 1/3] Fix Thread border agent IDs encoded as hex second instance --- .../companion/android/thread/ThreadManagerImpl.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt b/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt index 84765259fdc..1ddced764d8 100644 --- a/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt +++ b/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt @@ -158,6 +158,7 @@ class ThreadManagerImpl @Inject constructor( override suspend fun getPreferredDatasetFromServer(serverId: Int): ThreadDatasetResponse? = getDatasetsFromServer(serverId)?.firstOrNull { it.preferred } + @OptIn(ExperimentalStdlibApi::class) override suspend fun importDatasetFromServer( context: Context, datasetId: String, @@ -172,7 +173,8 @@ class ThreadManagerImpl @Inject constructor( BORDER_AGENT_ID } ).toByteArray() - val threadBorderAgent = ThreadBorderAgent.newBuilder(borderAgentId).build() + val idAsBytes = borderAgentId.let { if (it.length == 16) it.toByteArray() else it.hexToByteArray() } + val threadBorderAgent = ThreadBorderAgent.newBuilder(idAsBytes).build() val threadNetworkCredentials = ThreadNetworkCredentials.fromActiveOperationalDataset(tlv) suspendCoroutine { cont -> ThreadNetwork.getClient(context).addCredentials(threadBorderAgent, threadNetworkCredentials) From 4767f90cf0180862b3f0faa5b831aa6e3cf66478 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 1 Sep 2023 09:10:05 +0200 Subject: [PATCH 2/3] Remove unnecessary toByteArray() and brackets --- .../companion/android/thread/ThreadManagerImpl.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt b/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt index 1ddced764d8..6d499edf0d1 100644 --- a/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt +++ b/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt @@ -167,12 +167,10 @@ class ThreadManagerImpl @Inject constructor( ) { val tlv = serverManager.webSocketRepository(serverId).getThreadDatasetTlv(datasetId)?.tlvAsByteArray if (tlv != null) { - val borderAgentId = ( - preferredBorderAgentId ?: run { + val borderAgentId = preferredBorderAgentId ?: run { Log.w(TAG, "Adding dataset with placeholder border agent ID") BORDER_AGENT_ID } - ).toByteArray() val idAsBytes = borderAgentId.let { if (it.length == 16) it.toByteArray() else it.hexToByteArray() } val threadBorderAgent = ThreadBorderAgent.newBuilder(idAsBytes).build() val threadNetworkCredentials = ThreadNetworkCredentials.fromActiveOperationalDataset(tlv) From 42b7d187f651a61a1060df25cb89bacee82f659c Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 1 Sep 2023 09:13:54 +0200 Subject: [PATCH 3/3] Fix indentation --- .../companion/android/thread/ThreadManagerImpl.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt b/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt index 6d499edf0d1..969d938c517 100644 --- a/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt +++ b/app/src/full/java/io/homeassistant/companion/android/thread/ThreadManagerImpl.kt @@ -168,9 +168,9 @@ class ThreadManagerImpl @Inject constructor( val tlv = serverManager.webSocketRepository(serverId).getThreadDatasetTlv(datasetId)?.tlvAsByteArray if (tlv != null) { val borderAgentId = preferredBorderAgentId ?: run { - Log.w(TAG, "Adding dataset with placeholder border agent ID") - BORDER_AGENT_ID - } + Log.w(TAG, "Adding dataset with placeholder border agent ID") + BORDER_AGENT_ID + } val idAsBytes = borderAgentId.let { if (it.length == 16) it.toByteArray() else it.hexToByteArray() } val threadBorderAgent = ThreadBorderAgent.newBuilder(idAsBytes).build() val threadNetworkCredentials = ThreadNetworkCredentials.fromActiveOperationalDataset(tlv)