Skip to content

Commit

Permalink
Fix Thread border agent IDs encoded as hex second instance (#3838)
Browse files Browse the repository at this point in the history
* Fix Thread border agent IDs encoded as hex second instance

* Remove unnecessary toByteArray() and brackets

* Fix indentation
  • Loading branch information
agners authored Sep 2, 2023
1 parent ffd46b3 commit 5a9c392
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -166,13 +167,12 @@ 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
}
).toByteArray()
val threadBorderAgent = ThreadBorderAgent.newBuilder(borderAgentId).build()
val borderAgentId = preferredBorderAgentId ?: run {
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)
suspendCoroutine { cont ->
ThreadNetwork.getClient(context).addCredentials(threadBorderAgent, threadNetworkCredentials)
Expand Down

0 comments on commit 5a9c392

Please sign in to comment.