mirror of
https://github.com/D-Modem/app.git
synced 2026-11-28 17:38:05 -08:00
Android 17's local network permission; the log copied
An app targeting API 37 may reach the LAN only with ACCESS_LOCAL_NETWORK, which the user grants: without it a SIP server there was refused with "Operation not permitted" (sendto's EPERM) while baresip, targeting older, had it implicitly. It's declared and asked for at launch with notifications; the modem says what to allow when it starts without it, and when SIP gets EPERM. The log screen copies its lines (Copy), and a line can be selected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
4 files changed
+41
-12
No files matched your search
@@ -6,6 +6,8 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<!-- a SIP server, a bridge's client, an SSH host on the LAN (Android 17 asks the user) -->
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCAL_NETWORK" />
|
||||
<!-- the modem runs in a foreground service, its timing kept -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||
|
||||
@@ -53,6 +53,9 @@ class ModemService : Service() {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "ModemService"
|
||||
private const val NO_LOCAL_NETWORK = "Android hasn't allowed D-Modem on the local network, so a SIP server " +
|
||||
"there can't be reached (\"Operation not permitted\"): allow it in Android's settings, " +
|
||||
"Apps > D-Modem > Permissions, then start the modem again"
|
||||
private const val ACTION_START = "com.neodesktop.dmodem.START"
|
||||
private const val ACTION_STOP = "com.neodesktop.dmodem.STOP"
|
||||
/** the ringing call put out of sight (its notification's Ignore) */
|
||||
@@ -182,6 +185,8 @@ class ModemService : Service() {
|
||||
return
|
||||
}
|
||||
ModemState.setError(null)
|
||||
// (not a failure: the SIP server may be on the internet, which needs no leave)
|
||||
if (!settings.peer && !localNetworkAllowed()) log(NO_LOCAL_NETWORK)
|
||||
ModemState.setRun(ModemState.Run.STARTING)
|
||||
if (!startNative()) {
|
||||
fail(ModemState.error.value ?: "the modem didn't start")
|
||||
@@ -348,6 +353,8 @@ class ModemService : Service() {
|
||||
private val nativeListener = object : NativeModem.Listener {
|
||||
override fun onLog(line: String) {
|
||||
ModemState.log.add(line)
|
||||
// (what Android says when the LAN isn't the app's to reach)
|
||||
if (line.endsWith("Operation not permitted") && !localNetworkAllowed()) log(NO_LOCAL_NETWORK)
|
||||
}
|
||||
|
||||
override fun onStatus(status: NativeModem.Status) {
|
||||
@@ -548,6 +555,12 @@ class ModemService : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
/** whether the LAN may be reached: Android 17 asks the user (ACCESS_LOCAL_NETWORK); before, any app may */
|
||||
private fun localNetworkAllowed(): Boolean =
|
||||
android.os.Build.VERSION.SDK_INT < 37 ||
|
||||
checkSelfPermission(android.Manifest.permission.ACCESS_LOCAL_NETWORK) ==
|
||||
android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||
|
||||
private fun log(line: String) {
|
||||
Log.i(TAG, line)
|
||||
ModemState.log.add("app: $line")
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
// Copyright (C) 2026 Neo-Desktop
|
||||
package com.neodesktop.dmodem.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Text
|
||||
@@ -16,6 +19,8 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
@@ -30,10 +35,19 @@ fun LogScreen(modifier: Modifier = Modifier) {
|
||||
if (lines.isNotEmpty()) state.scrollToItem(lines.size - 1)
|
||||
}
|
||||
Column(modifier.fillMaxSize().padding(8.dp)) {
|
||||
OutlinedButton(onClick = { ModemState.log.clear() }) { Text("Clear") }
|
||||
LazyColumn(state = state, modifier = Modifier.fillMaxWidth().weight(1f)) {
|
||||
items(lines) { l ->
|
||||
Text(l, fontFamily = FontFamily.Monospace, style = MaterialTheme.typography.bodySmall)
|
||||
val clipboard = LocalClipboardManager.current
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
OutlinedButton(onClick = { ModemState.log.clear() }) { Text("Clear") }
|
||||
// (all of it, for a bug report; a line's text can be selected too)
|
||||
OutlinedButton(onClick = { clipboard.setText(AnnotatedString(lines.joinToString("\n"))) }, enabled = lines.isNotEmpty()) {
|
||||
Text("Copy")
|
||||
}
|
||||
}
|
||||
SelectionContainer(Modifier.fillMaxWidth().weight(1f)) {
|
||||
LazyColumn(state = state, modifier = Modifier.fillMaxSize()) {
|
||||
items(lines) { l ->
|
||||
Text(l, fontFamily = FontFamily.Monospace, style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,18 +47,18 @@ class MainActivity : ComponentActivity() {
|
||||
/** a tab to go to, from outside the content (a call answered from its notification) */
|
||||
private val goTo = kotlinx.coroutines.flow.MutableStateFlow<Int?>(null)
|
||||
|
||||
private val askNotifications =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { }
|
||||
private val askPermissions =
|
||||
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
if (Build.VERSION.SDK_INT >= 33 &&
|
||||
ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) !=
|
||||
PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
askNotifications.launch(Manifest.permission.POST_NOTIFICATIONS)
|
||||
}
|
||||
// notifications, and the LAN (a SIP server, an SSH host, a bridge's client there: Android 17 asks)
|
||||
val wanted = buildList {
|
||||
if (Build.VERSION.SDK_INT >= 33) add(Manifest.permission.POST_NOTIFICATIONS)
|
||||
if (Build.VERSION.SDK_INT >= 37) add(Manifest.permission.ACCESS_LOCAL_NETWORK)
|
||||
}.filter { ContextCompat.checkSelfPermission(this, it) != PackageManager.PERMISSION_GRANTED }
|
||||
if (wanted.isNotEmpty()) askPermissions.launch(wanted.toTypedArray())
|
||||
// the internet host's service, if it was on (the app in the foreground now: it may start)
|
||||
lifecycleScope.launch {
|
||||
val b = com.neodesktop.dmodem.settings.BridgeSettingsStore(applicationContext).current()
|
||||
|
||||
Reference in new issue
Block a user