Exercise overlay PTT through native capture and permission-loss stop races

This commit is contained in:
evgeny committed 2026-10-29 13:34:23 +01:00
1 parent 88e985e43b
commit ee6f46f555
1 file changed
+30 -4
@@ -82,12 +82,16 @@ class RadioOverlayLifecycleTest {
services.add(it); it.notificationManager = context.notificationManager; it.windowService = wm
it.permissionGranted = context.permissionGranted
it.onCreate(); dispatcher.scheduler.runCurrent()
if (it.foregroundId != 0 && it.stops == 0) { drain(); radio.onSettingsApplied(NativeLib.radioRequest, true); drain() }
}
private fun show(): RadioOverlayService = create().also { it.onStartCommand(null, 0, 1); dispatcher.scheduler.runCurrent() }
private fun diagnostic(fragment: String) = assertTrue("Missing diagnostic: $fragment",
LogManager.entries.any { fragment in it.message && it.level in listOf("ERROR", "WARN") })
private fun touch(action: Int, time: Long = 100, down: Long = time, x: Float = 0f, target: View = view) =
target.touch(MotionEvent(action, rawX = x, eventTime = time, downTime = down))
private fun touch(action: Int, time: Long = 100, down: Long = time, x: Float = 0f, target: View = view): Boolean {
val handled = target.touch(MotionEvent(action, rawX = x, eventTime = time, downTime = down))
drain()
return handled
}
@Test fun foregroundNotificationNeverReplacesOrRemovesThePhoneServiceNotification() {
val manager = requireNotNull(context.notificationManager); val phone = Notification()
@@ -182,9 +186,9 @@ class RadioOverlayLifecycleTest {
}
@Test fun failedDragLayoutCancelsItsPttImmediatelyAndDoesNotEscapeTheListener() {
show(); touch(MotionEvent.ACTION_DOWN); wm.failures = setOf("update")
val service = show(); touch(MotionEvent.ACTION_DOWN); wm.failures = setOf("update")
touch(MotionEvent.ACTION_MOVE, time = 150, down = 100, x = 100f)
assertFalse(radio.isTalking()); diagnostic("Overlay touch failed")
assertFalse(radio.isTalking()); assertTrue(service.stops > 0); diagnostic("Overlay touch failed")
}
@Test fun cancelClearsLatchedTransmissionImmediately() {
@@ -258,4 +262,26 @@ class RadioOverlayLifecycleTest {
Thread { try { RadioOverlayService.setActivityVisible(true) } catch (e: Throwable) { error.set(e) } }.apply { start(); join() }
assertTrue(error.get() is IllegalStateException); assertTrue(context.serviceStarts.isEmpty()); diagnostic("requires main thread")
}
@Test fun aRevokedOverlayPermissionDuringTouchStopsAnOtherwiseUnusedMicrophoneService() {
val service = show(); touch(MotionEvent.ACTION_DOWN); Settings.overlayAllowed = false
touch(MotionEvent.ACTION_MOVE, time = 110, down = 100)
assertTrue(wm.windows.isEmpty()); assertFalse(radio.isTalking()); assertEquals(1, context.serviceStops.size)
assertTrue(static("pendingStop").getBoolean(null)); service.onDestroy()
}
@Test fun partialAddAndFailedRollbackKeepTheOwnerUntilRemovalCanBeConfirmed() {
wm.failures = setOf("add after", "remove"); val service = show()
assertEquals(1, wm.windows.size); assertTrue(RadioOverlayService.isShown.value)
service.onDestroy(); assertSame(service, static("currentService").get(null))
wm.failures = emptySet(); RadioOverlayService.sync(context)
assertTrue(wm.windows.isEmpty()); assertFalse(RadioOverlayService.isShown.value)
}
@Test fun enableRequestedWhileTheOldServiceStopsRestartsOnlyAfterDestroy() {
RadioOverlayService.setActivityVisible(true); val service = show()
RadioOverlayService.stop(context); RadioOverlayService.sync(context)
assertEquals(1, context.serviceStarts.size); assertTrue(static("restartAfterStop").getBoolean(null))
service.onDestroy(); assertEquals(2, context.serviceStarts.size); assertTrue(static("starting").getBoolean(null))
}
}