mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Add reversible process limit controls
This commit is contained in:
1 parent
f9848c23a2
commit
f379a1f30a
4 files changed
+177
-50
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package com.droiddeck.launcher
|
||||
|
||||
import android.Manifest
|
||||
import android.app.ActivityOptions
|
||||
import android.content.Intent
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
@@ -354,7 +355,7 @@ class MainActivity : ComponentActivity() {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/The412Banner/DroidDeck/actions/workflows/build.yml")))
|
||||
},
|
||||
onRefreshPhantomStatus = { refreshPhantomStatus() },
|
||||
onOpenDeveloperOptions = { openDeveloperOptions() },
|
||||
onOpenDeveloperOptions = { displayId -> openDeveloperOptions(displayId) },
|
||||
onWirelessAdbPair = { host, port, code, complete ->
|
||||
Thread({
|
||||
val result = runCatching {
|
||||
@@ -370,9 +371,9 @@ class MainActivity : ComponentActivity() {
|
||||
ui.post { complete(port) }
|
||||
}, "wireless-adb-discovery").start()
|
||||
},
|
||||
onWirelessAdbApply = { host, port, complete ->
|
||||
onWirelessAdbApply = { host, port, enabled, complete ->
|
||||
Thread({
|
||||
val result = runCatching { WirelessAdbFix.disableChildProcessLimit(this@MainActivity, host, port) }
|
||||
val result = runCatching { WirelessAdbFix.setChildProcessLimit(this@MainActivity, host, port, enabled) }
|
||||
val error = result.exceptionOrNull()?.let { it.localizedMessage ?: "Wireless ADB command failed" }
|
||||
ui.post {
|
||||
if (error == null) refreshPhantomStatus()
|
||||
@@ -380,6 +381,16 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}, "wireless-adb-fix").start()
|
||||
},
|
||||
onSetPhantomProcessLimit = { enabled, complete ->
|
||||
Thread({
|
||||
val result = runCatching { WirelessAdbFix.setUsingSavedPairing(this@MainActivity, enabled) }
|
||||
val error = result.exceptionOrNull()?.let { it.localizedMessage ?: "Wireless ADB is unavailable" }
|
||||
ui.post {
|
||||
if (error == null) refreshPhantomStatus()
|
||||
complete(error)
|
||||
}
|
||||
}, "wireless-adb-setting").start()
|
||||
},
|
||||
onCopyPhantomCommand = {
|
||||
(getSystemService(CLIPBOARD_SERVICE) as ClipboardManager).setPrimaryClip(
|
||||
ClipData.newPlainText("DroidDeck child-process setting", PhantomProcessLimit.ADB_COMMAND),
|
||||
@@ -1069,12 +1080,20 @@ class MainActivity : ComponentActivity() {
|
||||
} else null
|
||||
}
|
||||
|
||||
private fun openDeveloperOptions() {
|
||||
runCatching {
|
||||
startActivity(Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS))
|
||||
}.onFailure {
|
||||
startActivity(Intent(android.provider.Settings.ACTION_SETTINGS))
|
||||
android.widget.Toast.makeText(this, "Open Developer options in Settings", android.widget.Toast.LENGTH_LONG).show()
|
||||
private fun openDeveloperOptions(displayId: Int?) {
|
||||
val intent = Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
try {
|
||||
if (displayId == null) startActivity(intent)
|
||||
else startActivity(intent, ActivityOptions.makeBasic().setLaunchDisplayId(displayId).toBundle())
|
||||
} catch (error: Exception) {
|
||||
if (displayId != null) {
|
||||
runCatching { startActivity(intent) }
|
||||
android.widget.Toast.makeText(this, "Could not open Settings on the bottom screen; opened it on the main screen.", android.widget.Toast.LENGTH_LONG).show()
|
||||
} else {
|
||||
startActivity(Intent(android.provider.Settings.ACTION_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||
android.widget.Toast.makeText(this, "Open Developer options in Settings", android.widget.Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.ArrayDeque
|
||||
object WirelessAdbFix {
|
||||
private const val CERT_FILE = "wireless-adb-cert.pem"
|
||||
private const val KEY_FILE = "wireless-adb-key.pem"
|
||||
private const val HOST_FILE = "wireless-adb-host.txt"
|
||||
|
||||
@Synchronized
|
||||
private fun loadOrCreateIdentity(context: Context) {
|
||||
@@ -43,6 +44,7 @@ object WirelessAdbFix {
|
||||
suspend fun pair(context: Context, host: String, port: Int, pairingCode: String) {
|
||||
loadOrCreateIdentity(context.applicationContext)
|
||||
Kadb.pair(host, port, pairingCode, "DroidDeck")
|
||||
writeAtomically(File(context.noBackupFilesDir, HOST_FILE), host.toByteArray())
|
||||
}
|
||||
|
||||
/** Finds this paired device's separate TLS connection port from Android's ADB mDNS record. */
|
||||
@@ -115,15 +117,28 @@ object WirelessAdbFix {
|
||||
return resolvedPort.get().takeIf { it in 1..65535 }
|
||||
}
|
||||
|
||||
fun disableChildProcessLimit(context: Context, host: String, port: Int) {
|
||||
fun setChildProcessLimit(context: Context, host: String, port: Int, enabled: Boolean) {
|
||||
loadOrCreateIdentity(context.applicationContext)
|
||||
Kadb.create(host, port).use { adb ->
|
||||
val change = adb.shell(PhantomProcessLimit.SHELL_COMMAND)
|
||||
val value = if (enabled) "true" else "false"
|
||||
val change = adb.shell("settings put global settings_enable_monitor_phantom_procs $value")
|
||||
check(change.exitCode == 0) { change.allOutput.ifBlank { "ADB command failed (${change.exitCode})" } }
|
||||
val result = adb.shell("settings get global settings_enable_monitor_phantom_procs")
|
||||
check(result.exitCode == 0 && result.output.trim() == "false") {
|
||||
"Android did not confirm the child-process limit was disabled: ${result.allOutput.trim()}"
|
||||
check(result.exitCode == 0 && result.output.trim() == value) {
|
||||
"Android did not confirm the child-process limit was changed: ${result.allOutput.trim()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Tries the app's saved pairing without asking for a new pairing code. */
|
||||
fun setUsingSavedPairing(context: Context, enabled: Boolean) {
|
||||
val appContext = context.applicationContext
|
||||
val hostFile = File(appContext.noBackupFilesDir, HOST_FILE)
|
||||
check(hostFile.isFile) { "No Wireless debugging pairing is saved" }
|
||||
val host = hostFile.readText().trim()
|
||||
check(host.isNotEmpty()) { "No Wireless debugging host is saved" }
|
||||
val port = findConnectPort(appContext, host)
|
||||
check(port != null) { "Wireless debugging is unavailable on this network" }
|
||||
setChildProcessLimit(appContext, host, port, enabled)
|
||||
}
|
||||
}
|
||||
@@ -212,10 +212,11 @@ class FrontEndActions(
|
||||
val onBackActionsInverted: (Boolean) -> Unit = {},
|
||||
val onCheckLatestBuild: () -> Unit = {},
|
||||
val onRefreshPhantomStatus: () -> Unit = {},
|
||||
val onOpenDeveloperOptions: () -> Unit = {},
|
||||
val onOpenDeveloperOptions: (Int?) -> Unit = {},
|
||||
val onWirelessAdbPair: (String, Int, String, (String?) -> Unit) -> Unit = { _, _, _, done -> done("Wireless ADB is unavailable") },
|
||||
val onFindWirelessAdbPort: (String, (Int?) -> Unit) -> Unit = { _, done -> done(null) },
|
||||
val onWirelessAdbApply: (String, Int, (String?) -> Unit) -> Unit = { _, _, done -> done("Wireless ADB is unavailable") },
|
||||
val onWirelessAdbApply: (String, Int, Boolean, (String?) -> Unit) -> Unit = { _, _, _, done -> done("Wireless ADB is unavailable") },
|
||||
val onSetPhantomProcessLimit: (Boolean, (String?) -> Unit) -> Unit = { _, done -> done("Wireless ADB is unavailable") },
|
||||
val onCopyPhantomCommand: () -> Unit = {},
|
||||
val onDismissPhantomGate: () -> Unit = {},
|
||||
val controller: ControllerActions? = null,
|
||||
@@ -355,9 +356,19 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
var selected by rememberSaveable { mutableStateOf("steam") }
|
||||
var navOpen by rememberSaveable { mutableStateOf(false) }
|
||||
var showWirelessAdbFix by rememberSaveable { mutableStateOf(false) }
|
||||
var showDeveloperDisplayChoice by rememberSaveable { mutableStateOf(false) }
|
||||
var wirelessAdbDesiredEnabled by rememberSaveable { mutableStateOf(false) }
|
||||
var appToChooseDisplay by remember { mutableStateOf<HomeApp.LaunchableApp?>(null) }
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val ctx = LocalContext.current
|
||||
val requestDeveloperOptions = {
|
||||
if (s.secondScreenDisplays.isEmpty()) a.onOpenDeveloperOptions(null)
|
||||
else showDeveloperDisplayChoice = true
|
||||
}
|
||||
val requestWirelessAdbFix: (Boolean) -> Unit = { enabled ->
|
||||
wirelessAdbDesiredEnabled = enabled
|
||||
showWirelessAdbFix = true
|
||||
}
|
||||
LaunchedEffect(s.showPhantomGate, s.phantomProcessStatus) {
|
||||
if (s.showPhantomGate && PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)) {
|
||||
while (true) {
|
||||
@@ -443,10 +454,15 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
.focusProperties { enter = { frontFocus.paneEntry() } }
|
||||
.focusGroup()
|
||||
val content: @Composable (Modifier) -> Unit = { m ->
|
||||
Pane(s, selected, a, page, m.then(paneFocus), { selected = it }) { app ->
|
||||
if (s.secondScreenDisplays.isEmpty()) a.onAndroidApp(app, null)
|
||||
else appToChooseDisplay = app
|
||||
}
|
||||
Pane(
|
||||
s, selected, a, page, m.then(paneFocus), { selected = it },
|
||||
onAndroidAppClick = { app ->
|
||||
if (s.secondScreenDisplays.isEmpty()) a.onAndroidApp(app, null)
|
||||
else appToChooseDisplay = app
|
||||
},
|
||||
onOpenDeveloperOptions = requestDeveloperOptions,
|
||||
onRequestWirelessAdb = requestWirelessAdbFix,
|
||||
)
|
||||
}
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
@@ -498,16 +514,21 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
onDismissRequest = a.onDismissPhantomGate,
|
||||
title = { Text("Steam cannot start yet") },
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Column(
|
||||
modifier = Modifier.heightIn(max = 320.dp).verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Text(PhantomProcessLimit.title(s.phantomProcessStatus))
|
||||
Text(PhantomProcessLimit.gateInstructions(s.phantomProcessStatus))
|
||||
Text(PhantomProcessLimit.ADB_COMMAND, style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
androidx.compose.material3.TextButton(onClick = a.onOpenDeveloperOptions) { Text("Developer options") }
|
||||
androidx.compose.material3.TextButton(onClick = { showWirelessAdbFix = true }) { Text("Fix over Wi-Fi") }
|
||||
Column(horizontalAlignment = Alignment.End) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
androidx.compose.material3.TextButton(onClick = requestDeveloperOptions) { Text("Developer options") }
|
||||
androidx.compose.material3.TextButton(onClick = { requestWirelessAdbFix(false) }) { Text("Fix over Wi-Fi") }
|
||||
}
|
||||
androidx.compose.material3.TextButton(onClick = a.onCopyPhantomCommand) { Text("Copy ADB") }
|
||||
}
|
||||
},
|
||||
@@ -516,12 +537,40 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
if (showWirelessAdbFix) {
|
||||
WirelessAdbFixDialog(
|
||||
onDismiss = { showWirelessAdbFix = false },
|
||||
onOpenDeveloperOptions = a.onOpenDeveloperOptions,
|
||||
desiredEnabled = wirelessAdbDesiredEnabled,
|
||||
onOpenDeveloperOptions = requestDeveloperOptions,
|
||||
onCopyCommand = a.onCopyPhantomCommand,
|
||||
onPair = a.onWirelessAdbPair,
|
||||
onFindConnectPort = a.onFindWirelessAdbPort,
|
||||
onApply = a.onWirelessAdbApply,
|
||||
)
|
||||
}
|
||||
if (showDeveloperDisplayChoice) {
|
||||
androidx.compose.material3.AlertDialog(
|
||||
onDismissRequest = { showDeveloperDisplayChoice = false },
|
||||
title = { Text("Open Developer options") },
|
||||
text = { Text("Choose where Settings should open.") },
|
||||
confirmButton = {
|
||||
Column(horizontalAlignment = Alignment.End) {
|
||||
androidx.compose.material3.TextButton(onClick = {
|
||||
showDeveloperDisplayChoice = false
|
||||
a.onOpenDeveloperOptions(null)
|
||||
}) { Text("Main screen") }
|
||||
s.secondScreenDisplays.forEach { display ->
|
||||
androidx.compose.material3.TextButton(onClick = {
|
||||
showDeveloperDisplayChoice = false
|
||||
a.onOpenDeveloperOptions(display.id)
|
||||
}) {
|
||||
Text(if (s.secondScreenDisplays.size == 1) "Bottom screen" else display.label)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
androidx.compose.material3.TextButton(onClick = { showDeveloperDisplayChoice = false }) { Text("Cancel") }
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
BackHandler(enabled = navOpen) { navOpen = false }
|
||||
val hasBackTarget = (s.pageKey != null && page != null) ||
|
||||
@@ -740,6 +789,7 @@ private fun NavItem(
|
||||
private fun Pane(
|
||||
s: FrontEndState, selected: String, a: FrontEndActions, page: (@Composable () -> Unit)?, modifier: Modifier,
|
||||
onSelect: (String) -> Unit, onAndroidAppClick: (HomeApp.LaunchableApp) -> Unit,
|
||||
onOpenDeveloperOptions: () -> Unit, onRequestWirelessAdb: (Boolean) -> Unit,
|
||||
) {
|
||||
Box(modifier = modifier) {
|
||||
val wash: Pair<File?, Float> = when {
|
||||
@@ -761,7 +811,10 @@ private fun Pane(
|
||||
.apply { targetContentZIndex = 1f }
|
||||
},
|
||||
label = "pane",
|
||||
) { key -> if (page != null && key == s.pageKey) page() else Content(s, key, a, Modifier.fillMaxSize(), onSelect, onAndroidAppClick) }
|
||||
) { key ->
|
||||
if (page != null && key == s.pageKey) page()
|
||||
else Content(s, key, a, Modifier.fillMaxSize(), onSelect, onAndroidAppClick, onOpenDeveloperOptions, onRequestWirelessAdb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -834,6 +887,7 @@ private fun romFor(s: FrontEndState, selected: String): Pair<Library.Emulator, L
|
||||
private fun Content(
|
||||
s: FrontEndState, selected: String, a: FrontEndActions, modifier: Modifier,
|
||||
onSelect: (String) -> Unit, onAndroidAppClick: (HomeApp.LaunchableApp) -> Unit,
|
||||
onOpenDeveloperOptions: () -> Unit, onRequestWirelessAdb: (Boolean) -> Unit,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val detailPosterWidth = if (LocalConfiguration.current.screenHeightDp < 600) 72.dp else 120.dp
|
||||
@@ -917,7 +971,7 @@ private fun Content(
|
||||
ArtGrid(s.emulators.map { e -> Tile(e.name, if (e.installed) (if (e.id == "retroarch") null else "${e.games.size} game${if (e.games.size == 1) "" else "s"}") else "Select to install", null, "emu:${e.id}", e.iconRes, dim = !e.installed) { onSelect("emu:${e.id}") } })
|
||||
}
|
||||
}
|
||||
selected == "setup" -> SetupPanel(s, a)
|
||||
selected == "setup" -> SetupPanel(s, a, onOpenDeveloperOptions, onRequestWirelessAdb)
|
||||
selected.startsWith("emu:") -> {
|
||||
val e = s.emulators.firstOrNull { "emu:${it.id}" == selected }
|
||||
if (e == null) Note("Not installed.") else {
|
||||
@@ -1036,8 +1090,28 @@ private fun Content(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SetupPanel(s: FrontEndState, a: FrontEndActions) {
|
||||
private fun SetupPanel(
|
||||
s: FrontEndState,
|
||||
a: FrontEndActions,
|
||||
onOpenDeveloperOptions: () -> Unit,
|
||||
onRequestWirelessAdb: (Boolean) -> Unit,
|
||||
) {
|
||||
val host = rememberMenuHost()
|
||||
var processLimitBusy by remember { mutableStateOf(false) }
|
||||
var processLimitMessage by remember { mutableStateOf<String?>(null) }
|
||||
val setProcessLimit: (Boolean) -> Unit = { enabled ->
|
||||
processLimitBusy = true
|
||||
processLimitMessage = null
|
||||
a.onSetPhantomProcessLimit(enabled) { error ->
|
||||
processLimitBusy = false
|
||||
if (error == null) {
|
||||
a.onRefreshPhantomStatus()
|
||||
} else {
|
||||
processLimitMessage = "Wireless ADB is unavailable. Pair this device or use Developer options."
|
||||
onRequestWirelessAdb(enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
val runtime = when {
|
||||
s.busy -> "Working…"
|
||||
!s.ready -> "Install"
|
||||
@@ -1048,22 +1122,32 @@ private fun SetupPanel(s: FrontEndState, a: FrontEndActions) {
|
||||
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(bottom = 24.dp)) {
|
||||
Rise(0) { Eyebrow("Setup") }
|
||||
Rise(1) { Title("Setup") }
|
||||
if (PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)) {
|
||||
SettingsGroup("Android process limit") {
|
||||
Text(
|
||||
PhantomProcessLimit.title(s.phantomProcessStatus),
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
)
|
||||
Text(PhantomProcessLimit.instructions(s.phantomProcessStatus), color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
Text(PhantomProcessLimit.ADB_COMMAND, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
SecondaryButton("Developer options", onClick = a.onOpenDeveloperOptions)
|
||||
SecondaryButton("Check again", onClick = a.onRefreshPhantomStatus)
|
||||
}
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
SecondaryButton("Copy ADB command", onClick = a.onCopyPhantomCommand)
|
||||
SettingsGroup("Android process limit") {
|
||||
Text(
|
||||
PhantomProcessLimit.title(s.phantomProcessStatus),
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = if (PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onBackground,
|
||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp),
|
||||
)
|
||||
Text(
|
||||
"Enabling restores Android’s child-process limit. Disabling it is recommended for Steam sessions.",
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(horizontal = 14.dp),
|
||||
)
|
||||
if (s.phantomProcessStatus != PhantomProcessStatus.NOT_APPLICABLE) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp)) {
|
||||
SecondaryButton("Enable limit", enabled = !processLimitBusy && s.phantomProcessStatus != PhantomProcessStatus.ENABLED) { setProcessLimit(true) }
|
||||
SecondaryButton("Disable limit", enabled = !processLimitBusy && s.phantomProcessStatus != PhantomProcessStatus.DISABLED) { setProcessLimit(false) }
|
||||
}
|
||||
if (processLimitBusy) LinearProgressIndicator(modifier = Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 8.dp))
|
||||
processLimitMessage?.let { Text(it, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 4.dp)) }
|
||||
}
|
||||
Text(PhantomProcessLimit.instructions(s.phantomProcessStatus), color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 4.dp))
|
||||
Text(PhantomProcessLimit.ADB_COMMAND, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 4.dp))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp)) {
|
||||
SecondaryButton("Developer options", onClick = onOpenDeveloperOptions)
|
||||
SecondaryButton("Check again", onClick = a.onRefreshPhantomStatus)
|
||||
SecondaryButton("Copy ADB", onClick = a.onCopyPhantomCommand)
|
||||
}
|
||||
}
|
||||
SettingsGroup("Launcher tools") {
|
||||
|
||||
@@ -24,10 +24,12 @@ import androidx.compose.ui.unit.dp
|
||||
@Composable
|
||||
fun WirelessAdbFixDialog(
|
||||
onDismiss: () -> Unit,
|
||||
desiredEnabled: Boolean,
|
||||
onOpenDeveloperOptions: () -> Unit,
|
||||
onCopyCommand: () -> Unit,
|
||||
onPair: (String, Int, String, (String?) -> Unit) -> Unit,
|
||||
onFindConnectPort: (String, (Int?) -> Unit) -> Unit,
|
||||
onApply: (String, Int, (String?) -> Unit) -> Unit,
|
||||
onApply: (String, Int, Boolean, (String?) -> Unit) -> Unit,
|
||||
) {
|
||||
var step by rememberSaveable { mutableStateOf(0) }
|
||||
var host by rememberSaveable { mutableStateOf("") }
|
||||
@@ -45,17 +47,21 @@ fun WirelessAdbFixDialog(
|
||||
when (step) {
|
||||
0 -> {
|
||||
Text("Enable Developer options and Wireless debugging on this device, and connect to Wi-Fi. Keep DroidDeck visible beside the pairing-code screen, such as in split screen. Android may close the code if you leave that screen.")
|
||||
Text(
|
||||
if (desiredEnabled) "This will restore Android’s child-process limit." else "This will disable Android’s child-process limit for Steam.",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
)
|
||||
Text("Enter the IP address and pairing port shown with the code.", style = MaterialTheme.typography.bodySmall)
|
||||
OutlinedTextField(host, { host = it.trim() }, label = { Text("Device IP address") }, singleLine = true, modifier = Modifier.fillMaxWidth())
|
||||
OutlinedTextField(pairingPort, { pairingPort = it.filter(Char::isDigit).take(5) }, label = { Text("Pairing port") }, singleLine = true, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), modifier = Modifier.fillMaxWidth())
|
||||
OutlinedTextField(pairingCode, { pairingCode = it.filter(Char::isDigit).take(6) }, label = { Text("Pairing code") }, singleLine = true, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
1 -> {
|
||||
Text("Paired. Return to the Wireless debugging screen and enter the current IP address and port shown there. This connect port is different from the pairing port.")
|
||||
Text("Paired. If automatic discovery did not work, enter the current Wireless debugging port shown in Settings. It differs from the pairing port.")
|
||||
OutlinedTextField(host, { host = it.trim() }, label = { Text("Device IP address") }, singleLine = true, modifier = Modifier.fillMaxWidth())
|
||||
OutlinedTextField(connectPort, { connectPort = it.filter(Char::isDigit).take(5) }, label = { Text("Wireless debugging port") }, singleLine = true, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
else -> Text(message ?: "Android confirmed the child-process limit is disabled. You can start Steam now.")
|
||||
else -> Text(message ?: "Android confirmed the child-process limit is ${if (desiredEnabled) "enabled" else "disabled"}.")
|
||||
}
|
||||
message?.let { Text(it, color = MaterialTheme.colorScheme.onSurfaceVariant, style = MaterialTheme.typography.bodySmall) }
|
||||
if (busy) Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
@@ -83,7 +89,7 @@ fun WirelessAdbFixDialog(
|
||||
} else {
|
||||
connectPort = discoveredPort.toString()
|
||||
message = "Device found. Applying the setting…"
|
||||
onApply(host, discoveredPort) { applyError ->
|
||||
onApply(host, discoveredPort, desiredEnabled) { applyError ->
|
||||
busy = false
|
||||
if (applyError == null) { step = 2; message = null }
|
||||
else message = "Could not apply automatically. Check the port below and retry. $applyError"
|
||||
@@ -96,17 +102,20 @@ fun WirelessAdbFixDialog(
|
||||
1 -> TextButton(enabled = !busy && validPort(connectPort), onClick = {
|
||||
busy = true
|
||||
message = null
|
||||
onApply(host, connectPort.toInt()) { error ->
|
||||
onApply(host, connectPort.toInt(), desiredEnabled) { error ->
|
||||
busy = false
|
||||
if (error == null) { step = 2; message = null } else message = error
|
||||
}
|
||||
}) { Text("Disable child-process limit") }
|
||||
}) { Text(if (desiredEnabled) "Enable child-process limit" else "Disable child-process limit") }
|
||||
else -> TextButton(onClick = onDismiss) { Text("Done") }
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
Row {
|
||||
if (step < 2) TextButton(enabled = !busy, onClick = onOpenDeveloperOptions) { Text("Developer options") }
|
||||
Column(horizontalAlignment = androidx.compose.ui.Alignment.End) {
|
||||
if (step < 2) Row {
|
||||
TextButton(enabled = !busy, onClick = onOpenDeveloperOptions) { Text("Developer options") }
|
||||
TextButton(enabled = !busy, onClick = onCopyCommand) { Text("Copy ADB") }
|
||||
}
|
||||
TextButton(enabled = !busy, onClick = onDismiss) { Text(if (step == 2) "Close" else "Cancel") }
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user