mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Add an in-session microphone toggle (#1506)
This commit is contained in:
1 parent
1f42f512e2
commit
0cf5b42788
13 files changed
+347
-12
No files matched your search
@@ -0,0 +1,86 @@
|
||||
package com.droiddeck.launcher.audio
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.util.ReflectionHelpers
|
||||
import java.io.File
|
||||
import java.util.function.Consumer
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28])
|
||||
class DirectAudioMicrophoneTest {
|
||||
@get:Rule val folder = TemporaryFolder()
|
||||
|
||||
@Test fun toggleOnlyChangesTheSessionCaptureControl() {
|
||||
val fifo = File(folder.root, "mic.fifo")
|
||||
val relay = DirectAudioRelayComponent(File(folder.root, "relay.sock"), fifo)
|
||||
val changes = mutableListOf<Boolean>()
|
||||
relay.onMicEnabled = Consumer { changes.add(it) }
|
||||
val control = File(folder.root, "mic-enabled")
|
||||
assertTrue(relay.setMicEnabled(false))
|
||||
assertEquals("0", control.readText())
|
||||
assertTrue(changes.isEmpty())
|
||||
log(relay, "DA-Relay: mic enabled=0")
|
||||
assertEquals(listOf(false), changes)
|
||||
assertTrue(relay.setMicEnabled(true))
|
||||
assertEquals("1", control.readText())
|
||||
log(relay, "DA-Relay: mic enabled=1")
|
||||
assertEquals(listOf(false, true), changes)
|
||||
assertFalse(fifo.exists())
|
||||
}
|
||||
|
||||
@Test fun sessionWithoutCaptureCannotEnableIt() {
|
||||
val relay = DirectAudioRelayComponent(File(folder.root, "relay.sock"), null)
|
||||
assertFalse(relay.setMicEnabled(true))
|
||||
assertFalse(File(folder.root, "mic-enabled").exists())
|
||||
}
|
||||
|
||||
@Test fun captureDemandDoesNotOverrideTheAcknowledgedToggle() {
|
||||
val relay = DirectAudioRelayComponent(File(folder.root, "relay.sock"), File(folder.root, "mic.fifo"))
|
||||
val changes = mutableListOf<Boolean>()
|
||||
relay.onMicEnabled = Consumer { changes.add(it) }
|
||||
log(relay, "DA-Relay: mic enabled=0")
|
||||
log(relay, "DA-Relay: mic start (game wants it, 1 consumer(s))")
|
||||
log(relay, "DA-Relay: mic stop (game)")
|
||||
assertEquals(listOf(false), changes)
|
||||
assertTrue(relay.awaitMicReleased(0))
|
||||
}
|
||||
|
||||
@Test fun controlWriteFailureStillStartsPlaybackWithCaptureDisabled() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val info = context.applicationInfo
|
||||
val previous = info.nativeLibraryDir
|
||||
val nativeDir = folder.newFolder("native")
|
||||
val args = File(folder.root, "arguments")
|
||||
File(nativeDir, DirectAudioRelayComponent.BINARY).apply {
|
||||
writeText("#!/bin/sh\nprintf '%s\\n' \"\$@\" > '${args.path}.new'\nmv '${args.path}.new' '${args.path}'\n")
|
||||
setExecutable(true)
|
||||
}
|
||||
val fifo = folder.newFile("mic.fifo")
|
||||
File(folder.root, "mic-enabled.new").mkdir()
|
||||
val relay = DirectAudioRelayComponent(File(folder.root, "relay.sock"), fifo)
|
||||
relay.attach(context)
|
||||
try {
|
||||
info.nativeLibraryDir = nativeDir.path
|
||||
relay.start()
|
||||
val deadline = System.nanoTime() + 3_000_000_000L
|
||||
while (!args.isFile && System.nanoTime() < deadline) Thread.sleep(10)
|
||||
assertTrue("Playback helper did not start", args.isFile)
|
||||
val command = args.readLines()
|
||||
assertTrue(command.contains("--socket"))
|
||||
assertFalse(command.contains("--mic-fifo"))
|
||||
assertEquals(listOf("--mic-control", "/dev/null"), command.takeLast(2))
|
||||
} finally {
|
||||
info.nativeLibraryDir = previous
|
||||
}
|
||||
}
|
||||
|
||||
private fun log(relay: DirectAudioRelayComponent, line: String) =
|
||||
ReflectionHelpers.callInstanceMethod<Unit>(relay, "trackMic", ReflectionHelpers.ClassParameter.from(String::class.java, line))
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import androidx.compose.ui.test.*
|
||||
import androidx.compose.ui.semantics.SemanticsProperties.StateDescription
|
||||
import androidx.compose.runtime.MutableState
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
@@ -97,6 +98,42 @@ class SessionSecondScreenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun sessionMicrophoneCanBeTurnedOff() {
|
||||
val changes = mutableListOf<Boolean>()
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(true, SessionDrawerPage.SESSION, false, {},
|
||||
actions(true, emptyList(), micAvailable = true, micEnabled = true, onMic = changes::add))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithTag("setting-microphone").assertIsEnabled()
|
||||
.assert(SemanticsMatcher.expectValue(StateDescription, context.getString(R.string.widgets_on))).performClick()
|
||||
assertEquals(listOf(false), changes)
|
||||
}
|
||||
|
||||
@Test fun sessionMicrophoneCanBeTurnedBackOn() {
|
||||
val changes = mutableListOf<Boolean>()
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(true, SessionDrawerPage.SESSION, false, {},
|
||||
actions(true, emptyList(), micAvailable = true, onMic = changes::add))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithTag("setting-microphone").assertIsEnabled()
|
||||
.assert(SemanticsMatcher.expectValue(StateDescription, context.getString(R.string.widgets_off))).performClick()
|
||||
assertEquals(listOf(true), changes)
|
||||
}
|
||||
|
||||
@Test fun sessionWithoutMicrophoneOmitsCaptureControl() {
|
||||
compose.setContent {
|
||||
DroidDeckTheme {
|
||||
SessionDrawer(true, SessionDrawerPage.SESSION, false, {}, actions(false, emptyList()))
|
||||
}
|
||||
}
|
||||
compose.onNodeWithTag("setting-microphone").assertDoesNotExist()
|
||||
compose.onNodeWithText(context.getString(R.string.mode_mic)).assertDoesNotExist()
|
||||
}
|
||||
|
||||
private fun checkModes(steam: Boolean) {
|
||||
SessionState.mode = if (steam) SessionService.MODE_STEAM else SessionService.MODE_DESKTOP
|
||||
val selected = mutableListOf<SecondScreenMode>()
|
||||
@@ -145,8 +182,11 @@ class SessionSecondScreenTest {
|
||||
if (view is ViewGroup) for (index in 0 until view.childCount) yieldAll(descendants(view.getChildAt(index)))
|
||||
}
|
||||
|
||||
private fun actions(steam: Boolean, displays: List<SecondScreenDisplay>, select: (SecondScreenMode) -> Unit = {}) =
|
||||
private fun actions(steam: Boolean, displays: List<SecondScreenDisplay>,
|
||||
micAvailable: Boolean = false, micEnabled: Boolean = false, onMic: (Boolean) -> Unit = {},
|
||||
select: (SecondScreenMode) -> Unit = {}) =
|
||||
DrawerActions(steam = steam, isHomeApp = false, androidApps = emptyList(), hudOn = false,
|
||||
micAvailable = micAvailable, micEnabled = micEnabled, onMicEnabled = onMic,
|
||||
frameGen = FrameGen.Mode.OFF, lossless = Lossless.State.NONE, oscMode = "never",
|
||||
onScreenButtonsVisible = false, suspendPolicy = "auto", backActionsInverted = false,
|
||||
touchMode = "auto", touchAuto = "trackpad", fexPreset = "default",
|
||||
|
||||
Reference in new issue
Block a user