Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #67 from boswelja/fix-capability-detection
Browse files Browse the repository at this point in the history
fix: Wear OS platform on mobile not detecting capabilities correctly
  • Loading branch information
boswelja authored Nov 16, 2021
2 parents a95e498 + 1a0b465 commit 3cb069f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public actual class WearOSDiscoveryPlatform(
trySend(capabilityInfo.nodes.any { it.id == watchId })
}

// Get the capability info immediately
val hasCapability = capabilityClient
.getCapability(capability, CapabilityClient.FILTER_ALL)
.await()
.nodes
.any { it.id == watchId }
send(hasCapability)

capabilityClient.addListener(listener, capability)

awaitClose {
Expand All @@ -83,6 +91,16 @@ public actual class WearOSDiscoveryPlatform(
trySend(watches)
}

// Get the capability info immediately
val watchesWithCapability = capabilityClient
.getCapability(capability, CapabilityClient.FILTER_ALL)
.await()
.nodes
.map { node ->
Watch(node.displayName, node.id, WEAROS_PLATFORM)
}
send(watchesWithCapability)

capabilityClient.addListener(listener, capability)

awaitClose {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ public class WearOSDiscoveryPlatformTest {
val capability = "capability1"
val node = createNodes(1).first()

var listener: CapabilityClient.OnCapabilityChangedListener? = null
// Mock CapabilityInfo without target node
every {
capabilityClient.getCapability(capability, any())
} returns Tasks.forResult(DummyCapabilityInfo(capability, mutableSetOf(node)))
// Mock listeners
every {
capabilityClient.addListener(any(), capability)
} answers {
listener = firstArg()
Tasks.forResult(null)
}
} returns Tasks.forResult(null)
every { capabilityClient.removeListener(any()) } returns Tasks.forResult(true)

discoveryPlatform.watchHasCapability(node.id, capability).test {
listener!!.onCapabilityChanged(DummyCapabilityInfo(capability, mutableSetOf(node)))
assertTrue(awaitItem())
}
}
Expand All @@ -108,17 +108,17 @@ public class WearOSDiscoveryPlatformTest {
val capability = "capability1"
val node = createNodes(1).first()

var listener: CapabilityClient.OnCapabilityChangedListener? = null
// Mock CapabilityInfo without target node
every {
capabilityClient.getCapability(capability, any())
} returns Tasks.forResult(DummyCapabilityInfo(capability, mutableSetOf()))
// Mock listeners
every {
capabilityClient.addListener(any(), capability)
} answers {
listener = firstArg()
Tasks.forResult(null)
}
} returns Tasks.forResult(null)
every { capabilityClient.removeListener(any()) } returns Tasks.forResult(true)

discoveryPlatform.watchHasCapability(node.id, capability).test {
listener!!.onCapabilityChanged(DummyCapabilityInfo(capability, mutableSetOf()))
assertFalse(awaitItem())
}
}
Expand All @@ -128,12 +128,17 @@ public class WearOSDiscoveryPlatformTest {
val capability = "capability1"
val node = createNodes(1).first()

every {
capabilityClient.getCapability(capability, any())
} returns Tasks.forResult(DummyCapabilityInfo(capability, mutableSetOf()))
every {
capabilityClient.addListener(any(), capability)
} returns Tasks.forResult(null)
every { capabilityClient.removeListener(any()) } returns Tasks.forResult(true)

discoveryPlatform.watchHasCapability(node.id, capability).test {
// We expect at least one item
awaitItem()
cancel()
}
verify { capabilityClient.removeListener(any()) }
Expand Down

0 comments on commit 3cb069f

Please sign in to comment.