mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +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
@@ -818,6 +818,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
lossless = lossless,
|
||||
oscMode = oscMode, onScreenButtonsVisible = onScreenButtonsVisible, suspendPolicy = suspendPolicy,
|
||||
steamDownloadsInBackground = steamDownloadsInBackground, touchMode = touchMode,
|
||||
micAvailable = SessionState.micAvailable && !SessionState.suspended,
|
||||
micEnabled = SessionState.micEnabled,
|
||||
onMicEnabled = { SessionService.setMicEnabled(this@SessionActivity, it) },
|
||||
touchAuto = getString(if (usingTouchpad()) R.string.session_touch_auto_touchpad else R.string.session_touch_auto_direct),
|
||||
fexPreset = fexPreset,
|
||||
secondScreenMode = secondScreenMode,
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.audio;
|
||||
import android.os.Process;
|
||||
import android.util.Log;
|
||||
|
||||
import com.droiddeck.launcher.core.FileUtils;
|
||||
import com.droiddeck.launcher.core.SessionPart;
|
||||
import com.droiddeck.launcher.core.HostProcess;
|
||||
|
||||
@@ -19,10 +20,13 @@ public class DirectAudioRelayComponent extends SessionPart {
|
||||
private volatile int pid = -1;
|
||||
private final Object micLock = new Object();
|
||||
private boolean micHot;
|
||||
private final File micControl;
|
||||
public java.util.function.Consumer<Boolean> onMicEnabled;
|
||||
|
||||
public DirectAudioRelayComponent(File socketPath, File micFifoPath) {
|
||||
this.socketPath = socketPath;
|
||||
this.micFifoPath = micFifoPath;
|
||||
this.micControl = micFifoPath == null ? null : new File(micFifoPath.getParentFile(), "mic-enabled");
|
||||
}
|
||||
|
||||
public void setLogFile(File file) {
|
||||
@@ -63,8 +67,13 @@ public class DirectAudioRelayComponent extends SessionPart {
|
||||
StringBuilder command = new StringBuilder(binary.getAbsolutePath());
|
||||
command.append(" --socket ").append(socketPath.getAbsolutePath());
|
||||
command.append(" --log");
|
||||
if (micFifoPath != null) {
|
||||
final boolean withMic = micFifoPath != null && setMicEnabled(true);
|
||||
if (withMic) {
|
||||
command.append(" --mic-fifo ").append(micFifoPath.getAbsolutePath());
|
||||
command.append(" --mic-control ").append(micControl.getAbsolutePath());
|
||||
} else if (micFifoPath != null) {
|
||||
Log.w(TAG, "microphone control unavailable; starting with capture disabled");
|
||||
command.append(" --mic-control /dev/null");
|
||||
}
|
||||
ArrayList<String> env = new ArrayList<>();
|
||||
env.add("HOME=" + app().getFilesDir());
|
||||
@@ -73,7 +82,7 @@ public class DirectAudioRelayComponent extends SessionPart {
|
||||
try {
|
||||
out = new java.io.PrintWriter(new java.io.FileWriter(logFile, true));
|
||||
out.println("== DirectAudio relay helper starting"
|
||||
+ (micFifoPath != null ? " with the microphone" : " (no microphone)"));
|
||||
+ (withMic ? " with the microphone" : " (no microphone)"));
|
||||
out.flush();
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "could not open " + logFile, e);
|
||||
@@ -84,14 +93,23 @@ public class DirectAudioRelayComponent extends SessionPart {
|
||||
app().getFilesDir(), null,
|
||||
line -> {
|
||||
Log.i(TAG, line);
|
||||
trackMic(line);
|
||||
if (withMic) trackMic(line);
|
||||
if (log != null) synchronized (log) { log.println(line); log.flush(); }
|
||||
});
|
||||
Log.i(TAG, "started pid=" + pid + " socket=" + socketPath
|
||||
+ (micFifoPath != null ? " mic=" + micFifoPath : " (no microphone)"));
|
||||
+ (withMic ? " mic=" + micFifoPath : " (no microphone)"));
|
||||
}
|
||||
|
||||
public synchronized boolean setMicEnabled(boolean enabled) {
|
||||
if (micControl == null) return false;
|
||||
File next = new File(micControl.getPath() + ".new");
|
||||
return FileUtils.writeString(next, enabled ? "1" : "0") && next.renameTo(micControl);
|
||||
}
|
||||
|
||||
private void trackMic(String line) {
|
||||
if (line.startsWith("DA-Relay: mic enabled=") && onMicEnabled != null) {
|
||||
onMicEnabled.accept(line.equals("DA-Relay: mic enabled=1"));
|
||||
}
|
||||
boolean start = line.startsWith("DA-Relay: mic start ");
|
||||
if (!start && !line.startsWith("DA-Relay: mic stop ")) return;
|
||||
synchronized (micLock) {
|
||||
|
||||
@@ -278,6 +278,16 @@ class SessionService : Service() {
|
||||
updateSuspendPolicy()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
ACTION_MIC_CHANGED -> {
|
||||
if (SessionState.running && SessionState.micAvailable && !SessionState.suspended) {
|
||||
val enabled = intent.getBooleanExtra("enabled", false)
|
||||
val relay = components.firstNotNullOfOrNull { it as? DirectAudioRelayComponent }
|
||||
if (relay?.setMicEnabled(enabled) != true) {
|
||||
android.widget.Toast.makeText(this, R.string.drawer_mic_failed, android.widget.Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
ACTION_SUSPEND_POLICY_CHANGED -> {
|
||||
if (!SessionState.running) return START_NOT_STICKY
|
||||
suspendPolicy = SessionPrefs.suspendPolicy(this, SessionState.mode)
|
||||
@@ -329,6 +339,8 @@ class SessionService : Service() {
|
||||
freezePending = false
|
||||
suspendAttemptFailed = false
|
||||
suspendController = null
|
||||
SessionState.micAvailable = false
|
||||
SessionState.micEnabled = false
|
||||
SessionState.suspended = false
|
||||
SessionState.resumeRequested = false
|
||||
SessionState.resuming = false
|
||||
@@ -761,6 +773,15 @@ class SessionService : Service() {
|
||||
components.add(pulse)
|
||||
if (wantsDirectAudio || wantsMic) {
|
||||
val relay = DirectAudioRelayComponent(relaySocket, micFifo)
|
||||
val gen = sessionGen
|
||||
relay.onMicEnabled = java.util.function.Consumer { enabled ->
|
||||
mainHandler.post {
|
||||
if (gen == sessionGen && SessionState.running && wantsMic) {
|
||||
SessionState.micAvailable = true
|
||||
SessionState.micEnabled = enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
relay.setLogFile(audioLog)
|
||||
relay.attach(this)
|
||||
components.add(relay)
|
||||
@@ -1656,6 +1677,8 @@ class SessionService : Service() {
|
||||
SessionState.running = false
|
||||
SessionPaths.take() to SessionState.steamClientArch
|
||||
}
|
||||
SessionState.micAvailable = false
|
||||
SessionState.micEnabled = false
|
||||
xrActivityVisible = false
|
||||
updateDownloadMonitoring()
|
||||
val stoppedGen = sessionGen
|
||||
@@ -1948,6 +1971,7 @@ class SessionService : Service() {
|
||||
const val ACTION_LAUNCH_GAME = "com.droiddeck.launcher.LAUNCH_STEAM_GAME"
|
||||
const val ACTION_HOME_GUIDE = "com.droiddeck.launcher.HOME_GUIDE"
|
||||
const val ACTION_AGENT_START = "com.droiddeck.launcher.AGENT_START"
|
||||
private const val ACTION_MIC_CHANGED = "com.droiddeck.launcher.MIC_CHANGED"
|
||||
private const val ACTION_SUSPEND_POLICY_CHANGED = "com.droiddeck.launcher.SUSPEND_POLICY_CHANGED"
|
||||
private const val ACTION_ACTIVITY_VISIBLE = "com.droiddeck.launcher.ACTIVITY_VISIBLE"
|
||||
private const val ACTION_ACTIVITY_HIDDEN = "com.droiddeck.launcher.ACTIVITY_HIDDEN"
|
||||
@@ -2078,6 +2102,11 @@ class SessionService : Service() {
|
||||
}.getOrDefault(false)
|
||||
}
|
||||
|
||||
fun setMicEnabled(context: Context, enabled: Boolean) {
|
||||
context.startService(Intent(context, SessionService::class.java).setAction(ACTION_MIC_CHANGED)
|
||||
.putExtra("enabled", enabled))
|
||||
}
|
||||
|
||||
fun suspendPolicyChanged(context: Context) {
|
||||
if (!SessionState.running) return
|
||||
context.startService(Intent(context, SessionService::class.java).setAction(ACTION_SUSPEND_POLICY_CHANGED))
|
||||
|
||||
@@ -46,6 +46,8 @@ object SessionState {
|
||||
var activityDisplayId = 0
|
||||
@Volatile
|
||||
var runtimeDriver: String? = null
|
||||
var micAvailable by mutableStateOf(false)
|
||||
var micEnabled by mutableStateOf(false)
|
||||
var suspended by mutableStateOf(false)
|
||||
var resumeRequested by mutableStateOf(false)
|
||||
var resuming by mutableStateOf(false)
|
||||
|
||||
@@ -208,6 +208,9 @@ class DrawerActions(
|
||||
val onScreenButtonsVisible: Boolean,
|
||||
val suspendPolicy: String,
|
||||
val steamDownloadsInBackground: Boolean = false,
|
||||
val micAvailable: Boolean = false,
|
||||
val micEnabled: Boolean = false,
|
||||
val onMicEnabled: (Boolean) -> Unit = {},
|
||||
val backActionsInverted: Boolean,
|
||||
val padType: String? = null,
|
||||
val onPadType: (String) -> Unit = {},
|
||||
@@ -669,6 +672,9 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
}
|
||||
}
|
||||
SettingsGroup(stringResource(R.string.drawer_session_behavior)) {
|
||||
if (a.micAvailable) ToggleRow(host, "microphone", stringResource(R.string.mode_mic),
|
||||
stringResource(R.string.drawer_mic_hint), a.micEnabled,
|
||||
chipModifier = focus.track(page, "microphone"), onChange = a.onMicEnabled)
|
||||
ChoiceRow(
|
||||
host, "suspend", stringResource(R.string.mode_suspend),
|
||||
null,
|
||||
|
||||
Reference in new issue
Block a user