Compare commits
12
Commits
dev
...
daf8e2de2f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daf8e2de2f | ||
|
|
a1b58fedd1 | ||
|
|
804ad7c91c | ||
|
|
a5f9769134 | ||
|
|
d907b34f49 | ||
|
|
d4d4091435 | ||
|
|
21b59cffef | ||
|
|
76772e20f8 | ||
|
|
696976c4a0 | ||
|
|
b3b09454c0 | ||
|
|
4bfd43af1a | ||
|
|
3228793f4a |
Binary file not shown.
@@ -0,0 +1,7 @@
|
|||||||
|
package io.nekohasekai.sfa.bg;
|
||||||
|
|
||||||
|
import io.nekohasekai.sfa.bg.ParceledListSlice;
|
||||||
|
|
||||||
|
interface INeighborTableCallback {
|
||||||
|
oneway void onNeighborTableUpdated(in ParceledListSlice entries);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.nekohasekai.sfa.bg;
|
package io.nekohasekai.sfa.bg;
|
||||||
|
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import io.nekohasekai.sfa.bg.INeighborTableCallback;
|
||||||
import io.nekohasekai.sfa.bg.ParceledListSlice;
|
import io.nekohasekai.sfa.bg.ParceledListSlice;
|
||||||
|
|
||||||
interface IRootService {
|
interface IRootService {
|
||||||
@@ -11,4 +12,8 @@ interface IRootService {
|
|||||||
void installPackage(in ParcelFileDescriptor apk, long size, int userId) = 2;
|
void installPackage(in ParcelFileDescriptor apk, long size, int userId) = 2;
|
||||||
|
|
||||||
String exportDebugInfo(String outputPath) = 3;
|
String exportDebugInfo(String outputPath) = 3;
|
||||||
|
|
||||||
|
void registerNeighborTableCallback(in INeighborTableCallback callback) = 4;
|
||||||
|
|
||||||
|
oneway void unregisterNeighborTableCallback(in INeighborTableCallback callback) = 5;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package io.nekohasekai.sfa.bg;
|
||||||
|
|
||||||
|
parcelable NeighborEntry;
|
||||||
@@ -9,13 +9,16 @@ import android.content.IntentFilter
|
|||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
|
import android.util.Log
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import go.Seq
|
|
||||||
import io.nekohasekai.libbox.Libbox
|
import io.nekohasekai.libbox.Libbox
|
||||||
import io.nekohasekai.libbox.SetupOptions
|
import io.nekohasekai.libbox.SetupOptions
|
||||||
import io.nekohasekai.sfa.bg.AppChangeReceiver
|
import io.nekohasekai.sfa.bg.AppChangeReceiver
|
||||||
|
import io.nekohasekai.sfa.bg.CrashReportManager
|
||||||
|
import io.nekohasekai.sfa.bg.OOMReportManager
|
||||||
import io.nekohasekai.sfa.bg.UpdateProfileWork
|
import io.nekohasekai.sfa.bg.UpdateProfileWork
|
||||||
import io.nekohasekai.sfa.constant.Bugs
|
import io.nekohasekai.sfa.constant.Bugs
|
||||||
|
import io.nekohasekai.sfa.database.Settings
|
||||||
import io.nekohasekai.sfa.utils.AppLifecycleObserver
|
import io.nekohasekai.sfa.utils.AppLifecycleObserver
|
||||||
import io.nekohasekai.sfa.utils.HookModuleUpdateNotifier
|
import io.nekohasekai.sfa.utils.HookModuleUpdateNotifier
|
||||||
import io.nekohasekai.sfa.utils.HookStatusClient
|
import io.nekohasekai.sfa.utils.HookStatusClient
|
||||||
@@ -39,13 +42,28 @@ class Application : Application() {
|
|||||||
AppLifecycleObserver.register(this)
|
AppLifecycleObserver.register(this)
|
||||||
|
|
||||||
// Seq.setContext(this)
|
// Seq.setContext(this)
|
||||||
Libbox.setLocale(Locale.getDefault().toLanguageTag().replace("-", "_"))
|
runCatching {
|
||||||
|
Libbox.setLocale(Locale.getDefault().toLanguageTag().replace("-", "_"))
|
||||||
|
}.onFailure {
|
||||||
|
Log.d("Application", "set locale: ${it.message}")
|
||||||
|
}
|
||||||
HookStatusClient.register(this)
|
HookStatusClient.register(this)
|
||||||
PrivilegeSettingsClient.register(this)
|
PrivilegeSettingsClient.register(this)
|
||||||
|
|
||||||
|
val baseDir = filesDir
|
||||||
|
baseDir.mkdirs()
|
||||||
|
val workingDir = getExternalFilesDir(null)
|
||||||
|
val tempDir = cacheDir
|
||||||
|
tempDir.mkdirs()
|
||||||
|
if (workingDir != null) {
|
||||||
|
workingDir.mkdirs()
|
||||||
|
CrashReportManager.install(workingDir, baseDir)
|
||||||
|
OOMReportManager.install(workingDir)
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("OPT_IN_USAGE")
|
@Suppress("OPT_IN_USAGE")
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
initialize()
|
initialize(baseDir, workingDir, tempDir)
|
||||||
UpdateProfileWork.reconfigureUpdater()
|
UpdateProfileWork.reconfigureUpdater()
|
||||||
HookModuleUpdateNotifier.sync(this@Application)
|
HookModuleUpdateNotifier.sync(this@Application)
|
||||||
}
|
}
|
||||||
@@ -62,24 +80,33 @@ class Application : Application() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initialize() {
|
private fun initialize(baseDir: File, workingDir: File?, tempDir: File) {
|
||||||
|
val actualWorkingDir = workingDir ?: return
|
||||||
|
setupLibbox(baseDir, actualWorkingDir, tempDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun reloadSetupOptions() {
|
||||||
val baseDir = filesDir
|
val baseDir = filesDir
|
||||||
baseDir.mkdirs()
|
|
||||||
val workingDir = getExternalFilesDir(null) ?: return
|
val workingDir = getExternalFilesDir(null) ?: return
|
||||||
workingDir.mkdirs()
|
|
||||||
val tempDir = cacheDir
|
val tempDir = cacheDir
|
||||||
tempDir.mkdirs()
|
Libbox.reloadSetupOptions(createSetupOptions(baseDir, workingDir, tempDir))
|
||||||
Libbox.setup(
|
}
|
||||||
SetupOptions().also {
|
|
||||||
it.basePath = baseDir.path
|
private fun setupLibbox(baseDir: File, workingDir: File, tempDir: File) {
|
||||||
it.workingPath = workingDir.path
|
Libbox.setup(createSetupOptions(baseDir, workingDir, tempDir))
|
||||||
it.tempPath = tempDir.path
|
}
|
||||||
it.fixAndroidStack = Bugs.fixAndroidStack
|
|
||||||
it.logMaxLines = 3000
|
private fun createSetupOptions(baseDir: File, workingDir: File, tempDir: File): SetupOptions = SetupOptions().also {
|
||||||
it.debug = BuildConfig.DEBUG
|
it.basePath = baseDir.path
|
||||||
},
|
it.workingPath = workingDir.path
|
||||||
)
|
it.tempPath = tempDir.path
|
||||||
Libbox.redirectStderr(File(workingDir, "stderr.log").path)
|
it.fixAndroidStack = Bugs.fixAndroidStack
|
||||||
|
it.logMaxLines = 3000
|
||||||
|
it.debug = BuildConfig.DEBUG
|
||||||
|
it.crashReportSource = "Application"
|
||||||
|
it.oomKillerEnabled = Settings.oomKillerEnabled
|
||||||
|
it.oomKillerDisabled = Settings.oomKillerDisabled
|
||||||
|
it.oomMemoryLimit = Settings.oomMemoryLimitMB.toLong() * 1024L * 1024L
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ class BootReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
if (Settings.startedByUser) {
|
if (Settings.startedByUser) {
|
||||||
|
CrashReportManager.refresh()
|
||||||
|
if (CrashReportManager.unreadCount.value > 0) {
|
||||||
|
Settings.startedByUser = false
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
BoxService.start()
|
BoxService.start()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -417,6 +417,13 @@ class BoxService(private val service: Service, private val platformInterface: Pl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun triggerNativeCrash() {
|
||||||
|
Thread {
|
||||||
|
Thread.sleep(200)
|
||||||
|
throw RuntimeException("debug native crash")
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
override fun writeDebugMessage(message: String?) {
|
override fun writeDebugMessage(message: String?) {
|
||||||
Log.d("sing-box", message!!)
|
Log.d("sing-box", message!!)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,251 @@
|
|||||||
|
package io.nekohasekai.sfa.bg
|
||||||
|
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.sfa.Application
|
||||||
|
import io.nekohasekai.sfa.BuildConfig
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.io.File
|
||||||
|
import java.io.PrintWriter
|
||||||
|
import java.io.StringWriter
|
||||||
|
import java.text.ParseException
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
|
data class CrashReport(
|
||||||
|
val id: String,
|
||||||
|
val date: Date,
|
||||||
|
val directory: File,
|
||||||
|
val isRead: Boolean,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class CrashReportFile(
|
||||||
|
val kind: Kind,
|
||||||
|
val displayName: String,
|
||||||
|
val file: File,
|
||||||
|
) {
|
||||||
|
enum class Kind {
|
||||||
|
METADATA,
|
||||||
|
GO_LOG,
|
||||||
|
JVM_LOG,
|
||||||
|
CONFIG,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object CrashReportManager {
|
||||||
|
private const val METADATA_FILE_NAME = "metadata.json"
|
||||||
|
private const val GO_LOG_FILE_NAME = "go.log"
|
||||||
|
private const val JVM_LOG_FILE_NAME = "jvm.log"
|
||||||
|
private const val CONFIG_FILE_NAME = "configuration.json"
|
||||||
|
private const val READ_MARKER_FILE_NAME = ".read"
|
||||||
|
private const val CRASH_REPORTS_DIR_NAME = "crash_reports"
|
||||||
|
private const val PENDING_JVM_CRASH_FILE_NAME = "CrashReport-JVM.log"
|
||||||
|
private const val PENDING_JVM_METADATA_FILE_NAME = "CrashReport-JVM-metadata.json"
|
||||||
|
|
||||||
|
private val timestampFormat = SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss", Locale.US).apply {
|
||||||
|
timeZone = TimeZone.getTimeZone("UTC")
|
||||||
|
}
|
||||||
|
|
||||||
|
private lateinit var workingDir: File
|
||||||
|
private lateinit var baseDir: File
|
||||||
|
|
||||||
|
private val _reports = MutableStateFlow<List<CrashReport>>(emptyList())
|
||||||
|
val reports: StateFlow<List<CrashReport>> = _reports
|
||||||
|
private val _unreadCount = MutableStateFlow(0)
|
||||||
|
val unreadCount: StateFlow<Int> = _unreadCount
|
||||||
|
|
||||||
|
fun install(workingDir: File, baseDir: File) {
|
||||||
|
this.workingDir = workingDir
|
||||||
|
this.baseDir = baseDir
|
||||||
|
archivePendingJvmCrashReport()
|
||||||
|
val previous = Thread.getDefaultUncaughtExceptionHandler()
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
|
||||||
|
writePendingJvmCrashReport(thread, throwable)
|
||||||
|
previous?.uncaughtException(thread, throwable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun writePendingJvmCrashReport(thread: Thread, throwable: Throwable) {
|
||||||
|
try {
|
||||||
|
val writer = StringWriter()
|
||||||
|
throwable.printStackTrace(PrintWriter(writer))
|
||||||
|
File(workingDir, PENDING_JVM_CRASH_FILE_NAME).writeText(writer.toString())
|
||||||
|
val metadata = JSONObject().apply {
|
||||||
|
put("source", "Application")
|
||||||
|
put("crashedAt", formatTimestampISO8601(Date()))
|
||||||
|
put("exceptionName", throwable.javaClass.name)
|
||||||
|
put("exceptionReason", throwable.message ?: "")
|
||||||
|
put("processName", Application.application.packageName)
|
||||||
|
put("appVersion", BuildConfig.VERSION_CODE.toString())
|
||||||
|
put("appMarketingVersion", BuildConfig.VERSION_NAME)
|
||||||
|
runCatching {
|
||||||
|
put("coreVersion", Libbox.version())
|
||||||
|
put("goVersion", Libbox.goVersion())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File(workingDir, PENDING_JVM_METADATA_FILE_NAME).writeText(metadata.toString())
|
||||||
|
} catch (_: Throwable) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun refresh() = withContext(Dispatchers.IO) {
|
||||||
|
val reports = scanCrashReports()
|
||||||
|
_reports.value = reports
|
||||||
|
_unreadCount.value = reports.count { !it.isRead }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun archivePendingJvmCrashReport() {
|
||||||
|
val crashFile = File(workingDir, PENDING_JVM_CRASH_FILE_NAME)
|
||||||
|
val metadataFile = File(workingDir, PENDING_JVM_METADATA_FILE_NAME)
|
||||||
|
val configFile = File(baseDir, CONFIG_FILE_NAME)
|
||||||
|
if (!crashFile.exists()) return
|
||||||
|
val content = crashFile.readText().trim()
|
||||||
|
if (content.isEmpty()) {
|
||||||
|
crashFile.delete()
|
||||||
|
metadataFile.delete()
|
||||||
|
configFile.delete()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val crashDate = Date(crashFile.lastModified())
|
||||||
|
val reportDir = nextAvailableReportDir(crashDate)
|
||||||
|
reportDir.mkdirs()
|
||||||
|
crashFile.copyTo(File(reportDir, JVM_LOG_FILE_NAME), overwrite = true)
|
||||||
|
crashFile.delete()
|
||||||
|
if (metadataFile.exists()) {
|
||||||
|
metadataFile.copyTo(File(reportDir, METADATA_FILE_NAME), overwrite = true)
|
||||||
|
metadataFile.delete()
|
||||||
|
}
|
||||||
|
if (configFile.exists()) {
|
||||||
|
val configContent = runCatching { configFile.readText() }.getOrNull()?.trim()
|
||||||
|
if (!configContent.isNullOrEmpty()) {
|
||||||
|
configFile.copyTo(File(reportDir, CONFIG_FILE_NAME), overwrite = true)
|
||||||
|
}
|
||||||
|
configFile.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun scanCrashReports(): List<CrashReport> {
|
||||||
|
val crashReportsDir = File(workingDir, CRASH_REPORTS_DIR_NAME)
|
||||||
|
if (!crashReportsDir.isDirectory) return emptyList()
|
||||||
|
val directories = crashReportsDir.listFiles { file -> file.isDirectory } ?: return emptyList()
|
||||||
|
return directories.mapNotNull { dir ->
|
||||||
|
val date = parseTimestamp(dir.name) ?: return@mapNotNull null
|
||||||
|
CrashReport(
|
||||||
|
id = dir.name,
|
||||||
|
date = date,
|
||||||
|
directory = dir,
|
||||||
|
isRead = File(dir, READ_MARKER_FILE_NAME).exists(),
|
||||||
|
)
|
||||||
|
}.sortedByDescending { it.date }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun availableFiles(report: CrashReport): List<CrashReportFile> {
|
||||||
|
val files = mutableListOf<CrashReportFile>()
|
||||||
|
val metadataFile = File(report.directory, METADATA_FILE_NAME)
|
||||||
|
if (metadataFile.exists()) {
|
||||||
|
files.add(CrashReportFile(CrashReportFile.Kind.METADATA, "Metadata", metadataFile))
|
||||||
|
}
|
||||||
|
val goLogFile = File(report.directory, GO_LOG_FILE_NAME)
|
||||||
|
if (goLogFile.exists()) {
|
||||||
|
files.add(CrashReportFile(CrashReportFile.Kind.GO_LOG, "Go Crash Log", goLogFile))
|
||||||
|
}
|
||||||
|
val jvmLogFile = File(report.directory, JVM_LOG_FILE_NAME)
|
||||||
|
if (jvmLogFile.exists()) {
|
||||||
|
files.add(CrashReportFile(CrashReportFile.Kind.JVM_LOG, "JVM Crash Log", jvmLogFile))
|
||||||
|
}
|
||||||
|
val configFile = File(report.directory, CONFIG_FILE_NAME)
|
||||||
|
if (configFile.exists()) {
|
||||||
|
files.add(CrashReportFile(CrashReportFile.Kind.CONFIG, "Configuration", configFile))
|
||||||
|
}
|
||||||
|
return files
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadFileContent(file: CrashReportFile): String {
|
||||||
|
if (!file.file.exists()) return ""
|
||||||
|
val content = file.file.readText()
|
||||||
|
if (file.kind == CrashReportFile.Kind.METADATA) {
|
||||||
|
return runCatching {
|
||||||
|
JSONObject(content).toString(2)
|
||||||
|
}.getOrDefault(content)
|
||||||
|
}
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
|
fun markAsRead(report: CrashReport) {
|
||||||
|
File(report.directory, READ_MARKER_FILE_NAME).createNewFile()
|
||||||
|
val updated = _reports.value.map {
|
||||||
|
if (it.id == report.id) it.copy(isRead = true) else it
|
||||||
|
}
|
||||||
|
_reports.value = updated
|
||||||
|
_unreadCount.value = updated.count { !it.isRead }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun delete(report: CrashReport) = withContext(Dispatchers.IO) {
|
||||||
|
report.directory.deleteRecursively()
|
||||||
|
val updated = _reports.value.filter { it.id != report.id }
|
||||||
|
_reports.value = updated
|
||||||
|
_unreadCount.value = updated.count { !it.isRead }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun deleteAll() = withContext(Dispatchers.IO) {
|
||||||
|
File(workingDir, CRASH_REPORTS_DIR_NAME).deleteRecursively()
|
||||||
|
_reports.value = emptyList()
|
||||||
|
_unreadCount.value = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hasConfigFile(report: CrashReport): Boolean = File(report.directory, CONFIG_FILE_NAME).exists()
|
||||||
|
|
||||||
|
suspend fun createZipArchive(report: CrashReport, includeConfig: Boolean): File = withContext(Dispatchers.IO) {
|
||||||
|
val cacheDir = File(Application.application.cacheDir, CRASH_REPORTS_DIR_NAME)
|
||||||
|
cacheDir.mkdirs()
|
||||||
|
val zipFile = File(cacheDir, "${report.id}.zip")
|
||||||
|
zipFile.delete()
|
||||||
|
val strippedDir = File(cacheDir, report.id)
|
||||||
|
strippedDir.deleteRecursively()
|
||||||
|
report.directory.copyRecursively(strippedDir, overwrite = true)
|
||||||
|
File(strippedDir, READ_MARKER_FILE_NAME).delete()
|
||||||
|
if (!includeConfig) {
|
||||||
|
File(strippedDir, CONFIG_FILE_NAME).delete()
|
||||||
|
}
|
||||||
|
Libbox.createZipArchive(strippedDir.path, zipFile.path)
|
||||||
|
zipFile
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun nextAvailableReportDir(date: Date): File {
|
||||||
|
val crashReportsDir = File(workingDir, CRASH_REPORTS_DIR_NAME)
|
||||||
|
val baseName = timestampFormat.format(date)
|
||||||
|
var index = 0
|
||||||
|
while (true) {
|
||||||
|
val suffix = if (index == 0) "" else "-$index"
|
||||||
|
val dir = File(crashReportsDir, baseName + suffix)
|
||||||
|
if (!dir.exists()) return dir
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseTimestamp(name: String): Date? {
|
||||||
|
val components = name.split("-")
|
||||||
|
val baseName = if (components.size > 5 && components.last().toIntOrNull() != null) {
|
||||||
|
components.dropLast(1).joinToString("-")
|
||||||
|
} else {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
return try {
|
||||||
|
timestampFormat.parse(baseName)
|
||||||
|
} catch (_: ParseException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun formatTimestampISO8601(date: Date): String {
|
||||||
|
val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US).apply {
|
||||||
|
timeZone = TimeZone.getTimeZone("UTC")
|
||||||
|
}
|
||||||
|
return format.format(date)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package io.nekohasekai.sfa.bg;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
public class NeighborEntry implements Parcelable {
|
||||||
|
@NonNull public final String address;
|
||||||
|
@NonNull public final String macAddress;
|
||||||
|
@NonNull public final String hostname;
|
||||||
|
|
||||||
|
public NeighborEntry(
|
||||||
|
@NonNull String address, @NonNull String macAddress, @NonNull String hostname) {
|
||||||
|
this.address = address;
|
||||||
|
this.macAddress = macAddress;
|
||||||
|
this.hostname = hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected NeighborEntry(Parcel in) {
|
||||||
|
address = in.readString();
|
||||||
|
macAddress = in.readString();
|
||||||
|
hostname = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||||
|
dest.writeString(address);
|
||||||
|
dest.writeString(macAddress);
|
||||||
|
dest.writeString(hostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<NeighborEntry> CREATOR =
|
||||||
|
new Creator<>() {
|
||||||
|
@Override
|
||||||
|
public NeighborEntry createFromParcel(Parcel in) {
|
||||||
|
return new NeighborEntry(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NeighborEntry[] newArray(int size) {
|
||||||
|
return new NeighborEntry[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
package io.nekohasekai.sfa.bg
|
||||||
|
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.sfa.Application
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.io.File
|
||||||
|
import java.text.ParseException
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
|
data class OOMReport(
|
||||||
|
val id: String,
|
||||||
|
val date: Date,
|
||||||
|
val directory: File,
|
||||||
|
val isRead: Boolean,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class OOMReportFile(
|
||||||
|
val kind: Kind,
|
||||||
|
val displayName: String,
|
||||||
|
val file: File,
|
||||||
|
) {
|
||||||
|
enum class Kind {
|
||||||
|
METADATA,
|
||||||
|
CONFIG,
|
||||||
|
PROFILE,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object OOMReportManager {
|
||||||
|
private const val METADATA_FILE_NAME = "metadata.json"
|
||||||
|
private const val CONFIG_FILE_NAME = "configuration.json"
|
||||||
|
private const val CMDLINE_FILE_NAME = "cmdline"
|
||||||
|
private const val READ_MARKER_FILE_NAME = ".read"
|
||||||
|
private const val OOM_REPORTS_DIR_NAME = "oom_reports"
|
||||||
|
|
||||||
|
private val timestampFormat = SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss", Locale.US).apply {
|
||||||
|
timeZone = TimeZone.getTimeZone("UTC")
|
||||||
|
}
|
||||||
|
|
||||||
|
private lateinit var workingDir: File
|
||||||
|
|
||||||
|
private val _reports = MutableStateFlow<List<OOMReport>>(emptyList())
|
||||||
|
val reports: StateFlow<List<OOMReport>> = _reports
|
||||||
|
private val _unreadCount = MutableStateFlow(0)
|
||||||
|
val unreadCount: StateFlow<Int> = _unreadCount
|
||||||
|
|
||||||
|
fun install(workingDir: File) {
|
||||||
|
this.workingDir = workingDir
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun refresh() = withContext(Dispatchers.IO) {
|
||||||
|
val reports = scanReports()
|
||||||
|
_reports.value = reports
|
||||||
|
_unreadCount.value = reports.count { !it.isRead }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun scanReports(): List<OOMReport> {
|
||||||
|
val reportsDir = File(workingDir, OOM_REPORTS_DIR_NAME)
|
||||||
|
if (!reportsDir.isDirectory) return emptyList()
|
||||||
|
val directories = reportsDir.listFiles { file -> file.isDirectory } ?: return emptyList()
|
||||||
|
return directories.mapNotNull { dir ->
|
||||||
|
val date = parseTimestamp(dir.name) ?: return@mapNotNull null
|
||||||
|
OOMReport(
|
||||||
|
id = dir.name,
|
||||||
|
date = date,
|
||||||
|
directory = dir,
|
||||||
|
isRead = File(dir, READ_MARKER_FILE_NAME).exists(),
|
||||||
|
)
|
||||||
|
}.sortedByDescending { it.date }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun availableFiles(report: OOMReport): List<OOMReportFile> {
|
||||||
|
val files = mutableListOf<OOMReportFile>()
|
||||||
|
val metadataFile = File(report.directory, METADATA_FILE_NAME)
|
||||||
|
if (metadataFile.exists()) {
|
||||||
|
files.add(OOMReportFile(OOMReportFile.Kind.METADATA, "Metadata", metadataFile))
|
||||||
|
}
|
||||||
|
val configFile = File(report.directory, CONFIG_FILE_NAME)
|
||||||
|
if (configFile.exists()) {
|
||||||
|
files.add(OOMReportFile(OOMReportFile.Kind.CONFIG, "Configuration", configFile))
|
||||||
|
}
|
||||||
|
report.directory.listFiles()?.filter { file ->
|
||||||
|
file.isFile &&
|
||||||
|
file.name != METADATA_FILE_NAME &&
|
||||||
|
file.name != CONFIG_FILE_NAME &&
|
||||||
|
file.name != CMDLINE_FILE_NAME &&
|
||||||
|
file.name != READ_MARKER_FILE_NAME
|
||||||
|
}?.sortedBy { it.name }?.forEach { file ->
|
||||||
|
files.add(OOMReportFile(OOMReportFile.Kind.PROFILE, file.name, file))
|
||||||
|
}
|
||||||
|
return files
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadFileContent(file: OOMReportFile): String {
|
||||||
|
if (!file.file.exists()) return ""
|
||||||
|
val content = file.file.readText()
|
||||||
|
if (file.kind == OOMReportFile.Kind.METADATA) {
|
||||||
|
return runCatching {
|
||||||
|
JSONObject(content).toString(2)
|
||||||
|
}.getOrDefault(content)
|
||||||
|
}
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
|
fun markAsRead(report: OOMReport) {
|
||||||
|
File(report.directory, READ_MARKER_FILE_NAME).createNewFile()
|
||||||
|
val updated = _reports.value.map {
|
||||||
|
if (it.id == report.id) it.copy(isRead = true) else it
|
||||||
|
}
|
||||||
|
_reports.value = updated
|
||||||
|
_unreadCount.value = updated.count { !it.isRead }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun delete(report: OOMReport) = withContext(Dispatchers.IO) {
|
||||||
|
report.directory.deleteRecursively()
|
||||||
|
val updated = _reports.value.filter { it.id != report.id }
|
||||||
|
_reports.value = updated
|
||||||
|
_unreadCount.value = updated.count { !it.isRead }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun deleteAll() = withContext(Dispatchers.IO) {
|
||||||
|
File(workingDir, OOM_REPORTS_DIR_NAME).deleteRecursively()
|
||||||
|
_reports.value = emptyList()
|
||||||
|
_unreadCount.value = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fun hasConfigFile(report: OOMReport): Boolean = File(report.directory, CONFIG_FILE_NAME).exists()
|
||||||
|
|
||||||
|
suspend fun createZipArchive(report: OOMReport, includeConfig: Boolean): File = withContext(Dispatchers.IO) {
|
||||||
|
val cacheDir = File(Application.application.cacheDir, OOM_REPORTS_DIR_NAME)
|
||||||
|
cacheDir.mkdirs()
|
||||||
|
val zipFile = File(cacheDir, "${report.id}.zip")
|
||||||
|
zipFile.delete()
|
||||||
|
val strippedDir = File(cacheDir, report.id)
|
||||||
|
strippedDir.deleteRecursively()
|
||||||
|
report.directory.copyRecursively(strippedDir, overwrite = true)
|
||||||
|
File(strippedDir, READ_MARKER_FILE_NAME).delete()
|
||||||
|
if (!includeConfig) {
|
||||||
|
File(strippedDir, CONFIG_FILE_NAME).delete()
|
||||||
|
}
|
||||||
|
Libbox.createZipArchive(strippedDir.path, zipFile.path)
|
||||||
|
zipFile
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseTimestamp(name: String): Date? {
|
||||||
|
val components = name.split("-")
|
||||||
|
val baseName = if (components.size > 5 && components.last().toIntOrNull() != null) {
|
||||||
|
components.dropLast(1).joinToString("-")
|
||||||
|
} else {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
return try {
|
||||||
|
timestampFormat.parse(baseName)
|
||||||
|
} catch (_: ParseException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,12 +11,16 @@ import io.nekohasekai.libbox.ConnectionOwner
|
|||||||
import io.nekohasekai.libbox.InterfaceUpdateListener
|
import io.nekohasekai.libbox.InterfaceUpdateListener
|
||||||
import io.nekohasekai.libbox.Libbox
|
import io.nekohasekai.libbox.Libbox
|
||||||
import io.nekohasekai.libbox.LocalDNSTransport
|
import io.nekohasekai.libbox.LocalDNSTransport
|
||||||
|
import io.nekohasekai.libbox.NeighborEntryIterator
|
||||||
|
import io.nekohasekai.libbox.NeighborUpdateListener
|
||||||
import io.nekohasekai.libbox.NetworkInterfaceIterator
|
import io.nekohasekai.libbox.NetworkInterfaceIterator
|
||||||
import io.nekohasekai.libbox.PlatformInterface
|
import io.nekohasekai.libbox.PlatformInterface
|
||||||
import io.nekohasekai.libbox.StringIterator
|
import io.nekohasekai.libbox.StringIterator
|
||||||
import io.nekohasekai.libbox.TunOptions
|
import io.nekohasekai.libbox.TunOptions
|
||||||
import io.nekohasekai.libbox.WIFIState
|
import io.nekohasekai.libbox.WIFIState
|
||||||
import io.nekohasekai.sfa.Application
|
import io.nekohasekai.sfa.Application
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import java.net.Inet6Address
|
import java.net.Inet6Address
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.net.InterfaceAddress
|
import java.net.InterfaceAddress
|
||||||
@@ -24,8 +28,11 @@ import java.net.NetworkInterface
|
|||||||
import java.security.KeyStore
|
import java.security.KeyStore
|
||||||
import kotlin.io.encoding.Base64
|
import kotlin.io.encoding.Base64
|
||||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||||
|
import io.nekohasekai.libbox.NeighborEntry as LibboxNeighborEntry
|
||||||
import io.nekohasekai.libbox.NetworkInterface as LibboxNetworkInterface
|
import io.nekohasekai.libbox.NetworkInterface as LibboxNetworkInterface
|
||||||
|
|
||||||
|
private var neighborCallback: INeighborTableCallback.Stub? = null
|
||||||
|
|
||||||
interface PlatformInterfaceWrapper : PlatformInterface {
|
interface PlatformInterfaceWrapper : PlatformInterface {
|
||||||
override fun usePlatformAutoDetectInterfaceControl(): Boolean = true
|
override fun usePlatformAutoDetectInterfaceControl(): Boolean = true
|
||||||
|
|
||||||
@@ -172,6 +179,49 @@ interface PlatformInterfaceWrapper : PlatformInterface {
|
|||||||
return StringArray(certificates.iterator())
|
return StringArray(certificates.iterator())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun startNeighborMonitor(listener: NeighborUpdateListener?) {
|
||||||
|
if (listener == null) return
|
||||||
|
val callback = object : INeighborTableCallback.Stub() {
|
||||||
|
override fun onNeighborTableUpdated(entries: ParceledListSlice<*>?) {
|
||||||
|
if (entries == null) return
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val list = entries.list as List<NeighborEntry>
|
||||||
|
listener.updateNeighborTable(
|
||||||
|
NeighborEntryArray(
|
||||||
|
list.map { entry ->
|
||||||
|
LibboxNeighborEntry().apply {
|
||||||
|
address = entry.address
|
||||||
|
macAddress = entry.macAddress
|
||||||
|
hostname = entry.hostname
|
||||||
|
}
|
||||||
|
}.iterator(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
neighborCallback = callback
|
||||||
|
runBlocking(Dispatchers.IO) {
|
||||||
|
RootClient.registerNeighborTableCallback(callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun registerMyInterface(name: String?) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun closeNeighborMonitor(listener: NeighborUpdateListener?) {
|
||||||
|
val callback = neighborCallback ?: return
|
||||||
|
neighborCallback = null
|
||||||
|
runBlocking(Dispatchers.IO) {
|
||||||
|
RootClient.unregisterNeighborTableCallback(callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NeighborEntryArray(private val iterator: Iterator<LibboxNeighborEntry>) : NeighborEntryIterator {
|
||||||
|
override fun hasNext(): Boolean = iterator.hasNext()
|
||||||
|
|
||||||
|
override fun next(): LibboxNeighborEntry = iterator.next()
|
||||||
|
}
|
||||||
|
|
||||||
private class InterfaceArray(private val iterator: Iterator<LibboxNetworkInterface>) : NetworkInterfaceIterator {
|
private class InterfaceArray(private val iterator: Iterator<LibboxNetworkInterface>) : NetworkInterfaceIterator {
|
||||||
override fun hasNext(): Boolean = iterator.hasNext()
|
override fun hasNext(): Boolean = iterator.hasNext()
|
||||||
|
|
||||||
|
|||||||
@@ -133,4 +133,21 @@ object RootClient {
|
|||||||
throw e.rethrowFromSystemServer()
|
throw e.rethrowFromSystemServer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun registerNeighborTableCallback(callback: INeighborTableCallback) {
|
||||||
|
val svc = bindService()
|
||||||
|
try {
|
||||||
|
svc.registerNeighborTableCallback(callback)
|
||||||
|
} catch (e: RemoteException) {
|
||||||
|
throw e.rethrowFromSystemServer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun unregisterNeighborTableCallback(callback: INeighborTableCallback) {
|
||||||
|
try {
|
||||||
|
service?.unregisterNeighborTableCallback(callback)
|
||||||
|
} catch (e: RemoteException) {
|
||||||
|
throw e.rethrowFromSystemServer()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,36 @@ package io.nekohasekai.sfa.bg
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.ParcelFileDescriptor
|
import android.os.ParcelFileDescriptor
|
||||||
|
import android.os.RemoteCallbackList
|
||||||
|
import android.util.Log
|
||||||
import com.topjohnwu.superuser.ipc.RootService
|
import com.topjohnwu.superuser.ipc.RootService
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.libbox.NeighborEntryIterator
|
||||||
|
import io.nekohasekai.libbox.NeighborSubscription
|
||||||
|
import io.nekohasekai.libbox.NeighborUpdateListener
|
||||||
import io.nekohasekai.sfa.BuildConfig
|
import io.nekohasekai.sfa.BuildConfig
|
||||||
import io.nekohasekai.sfa.vendor.PrivilegedServiceUtils
|
import io.nekohasekai.sfa.vendor.PrivilegedServiceUtils
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.lang.reflect.Proxy
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
class RootServer : RootService() {
|
class RootServer : RootService() {
|
||||||
|
|
||||||
|
private val neighborCallbacks = RemoteCallbackList<INeighborTableCallback>()
|
||||||
|
private var neighborSubscription: NeighborSubscription? = null
|
||||||
|
|
||||||
|
private val hostnameByMAC = ConcurrentHashMap<String, String>()
|
||||||
|
|
||||||
|
@Volatile
|
||||||
|
private var lastNeighborEntries: List<Pair<String, String>>? = null
|
||||||
|
|
||||||
|
private var tetheringCallback: Any? = null
|
||||||
|
private var tetheringManager: Any? = null
|
||||||
|
|
||||||
private val binder = object : IRootService.Stub() {
|
private val binder = object : IRootService.Stub() {
|
||||||
override fun destroy() {
|
override fun destroy() {
|
||||||
stopSelf()
|
stopSelf()
|
||||||
@@ -31,7 +52,174 @@ class RootServer : RootService() {
|
|||||||
outputPath!!,
|
outputPath!!,
|
||||||
BuildConfig.APPLICATION_ID,
|
BuildConfig.APPLICATION_ID,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override fun registerNeighborTableCallback(callback: INeighborTableCallback?) {
|
||||||
|
if (callback == null) return
|
||||||
|
neighborCallbacks.register(callback)
|
||||||
|
synchronized(neighborCallbacks) {
|
||||||
|
if (neighborSubscription == null) {
|
||||||
|
try {
|
||||||
|
neighborSubscription =
|
||||||
|
Libbox.subscribeNeighborTable(object : NeighborUpdateListener {
|
||||||
|
override fun updateNeighborTable(entries: NeighborEntryIterator?) {
|
||||||
|
if (entries == null) return
|
||||||
|
val rawList = mutableListOf<Pair<String, String>>()
|
||||||
|
while (entries.hasNext()) {
|
||||||
|
val entry = entries.next()
|
||||||
|
rawList.add(entry.address to entry.macAddress)
|
||||||
|
}
|
||||||
|
lastNeighborEntries = rawList
|
||||||
|
broadcastEnrichedEntries(rawList)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("RootServer", "subscribeNeighborTable failed", e)
|
||||||
|
}
|
||||||
|
startTetheringMonitor()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun unregisterNeighborTableCallback(callback: INeighborTableCallback?) {
|
||||||
|
if (callback == null) return
|
||||||
|
neighborCallbacks.unregister(callback)
|
||||||
|
synchronized(neighborCallbacks) {
|
||||||
|
if (neighborCallbacks.registeredCallbackCount == 0) {
|
||||||
|
neighborSubscription?.close()
|
||||||
|
neighborSubscription = null
|
||||||
|
stopTetheringMonitor()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun broadcastEnrichedEntries(rawList: List<Pair<String, String>>) {
|
||||||
|
val list = rawList.map { (address, mac) ->
|
||||||
|
NeighborEntry(address, mac, hostnameByMAC[mac.uppercase()] ?: "")
|
||||||
|
}
|
||||||
|
Log.d("RootServer", "neighborTable updated: ${list.size} entries")
|
||||||
|
val slice = ParceledListSlice(list)
|
||||||
|
val count = neighborCallbacks.beginBroadcast()
|
||||||
|
try {
|
||||||
|
repeat(count) { i ->
|
||||||
|
try {
|
||||||
|
neighborCallbacks.getBroadcastItem(i).onNeighborTableUpdated(slice)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
neighborCallbacks.finishBroadcast()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TetheringManager reflection (API 30+)
|
||||||
|
|
||||||
|
private val classTetheredClient by lazy {
|
||||||
|
Class.forName("android.net.TetheredClient")
|
||||||
|
}
|
||||||
|
private val getMacAddress by lazy {
|
||||||
|
classTetheredClient.getDeclaredMethod("getMacAddress")
|
||||||
|
}
|
||||||
|
private val getAddresses by lazy {
|
||||||
|
classTetheredClient.getDeclaredMethod("getAddresses")
|
||||||
|
}
|
||||||
|
private val classAddressInfo by lazy {
|
||||||
|
Class.forName("android.net.TetheredClient\$AddressInfo")
|
||||||
|
}
|
||||||
|
private val getHostname by lazy {
|
||||||
|
classAddressInfo.getDeclaredMethod("getHostname")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startTetheringMonitor() {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) return
|
||||||
|
try {
|
||||||
|
val manager = getSystemService("tethering") ?: return
|
||||||
|
tetheringManager = manager
|
||||||
|
val callbackClass =
|
||||||
|
Class.forName("android.net.TetheringManager\$TetheringEventCallback")
|
||||||
|
val registerMethod = manager.javaClass.getMethod(
|
||||||
|
"registerTetheringEventCallback",
|
||||||
|
java.util.concurrent.Executor::class.java,
|
||||||
|
callbackClass,
|
||||||
|
)
|
||||||
|
val proxy = Proxy.newProxyInstance(
|
||||||
|
callbackClass.classLoader,
|
||||||
|
arrayOf(callbackClass),
|
||||||
|
) { proxyObject, method, args ->
|
||||||
|
when (method.name) {
|
||||||
|
"hashCode" -> System.identityHashCode(proxyObject)
|
||||||
|
"equals" -> proxyObject === args?.get(0)
|
||||||
|
"toString" ->
|
||||||
|
proxyObject.javaClass.name + "@" +
|
||||||
|
Integer.toHexString(System.identityHashCode(proxyObject))
|
||||||
|
"onClientsChanged" -> {
|
||||||
|
if (args != null) {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
handleClientsChanged(args[0] as Collection<*>)
|
||||||
|
}
|
||||||
|
null
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tetheringCallback = proxy
|
||||||
|
registerMethod.invoke(manager, Executors.newSingleThreadExecutor(), proxy)
|
||||||
|
Log.d("RootServer", "TetheringManager monitor started")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("RootServer", "startTetheringMonitor failed", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopTetheringMonitor() {
|
||||||
|
val manager = tetheringManager ?: return
|
||||||
|
val callback = tetheringCallback ?: return
|
||||||
|
try {
|
||||||
|
val callbackClass =
|
||||||
|
Class.forName("android.net.TetheringManager\$TetheringEventCallback")
|
||||||
|
val unregisterMethod = manager.javaClass.getMethod(
|
||||||
|
"unregisterTetheringEventCallback",
|
||||||
|
callbackClass,
|
||||||
|
)
|
||||||
|
unregisterMethod.invoke(manager, callback)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("RootServer", "stopTetheringMonitor failed", e)
|
||||||
|
}
|
||||||
|
tetheringCallback = null
|
||||||
|
tetheringManager = null
|
||||||
|
hostnameByMAC.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleClientsChanged(clients: Collection<*>) {
|
||||||
|
hostnameByMAC.clear()
|
||||||
|
for (client in clients) {
|
||||||
|
if (client == null) continue
|
||||||
|
try {
|
||||||
|
val mac = getMacAddress.invoke(client).toString().uppercase()
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
val addresses = getAddresses.invoke(client) as List<*>
|
||||||
|
for (info in addresses) {
|
||||||
|
if (info == null) continue
|
||||||
|
val hostname = getHostname.invoke(info) as? String
|
||||||
|
if (!hostname.isNullOrEmpty()) {
|
||||||
|
hostnameByMAC[mac] = hostname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("RootServer", "handleClientsChanged reflection error", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.d("RootServer", "tethered clients updated: ${hostnameByMAC.size} hostnames")
|
||||||
|
lastNeighborEntries?.let { broadcastEnrichedEntries(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent): IBinder = binder
|
override fun onBind(intent: Intent): IBinder = binder
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
stopTetheringMonitor()
|
||||||
|
neighborSubscription?.close()
|
||||||
|
neighborSubscription = null
|
||||||
|
neighborCallbacks.kill()
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.net.VpnService
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
import io.nekohasekai.libbox.Notification
|
import io.nekohasekai.libbox.Notification
|
||||||
import io.nekohasekai.libbox.TunOptions
|
import io.nekohasekai.libbox.TunOptions
|
||||||
import io.nekohasekai.sfa.database.Settings
|
import io.nekohasekai.sfa.database.Settings
|
||||||
@@ -83,7 +84,12 @@ class VPNService :
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options.autoRoute) {
|
if (options.autoRoute) {
|
||||||
builder.addDnsServer(options.dnsServerAddress.value)
|
if (options.dnsMode.value != Libbox.DNSModeDisabled) {
|
||||||
|
val dnsServerAddress = options.dnsServerAddress
|
||||||
|
while (dnsServerAddress.hasNext()) {
|
||||||
|
builder.addDnsServer(dnsServerAddress.next())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
val inet4RouteAddress = options.inet4RouteAddress
|
val inet4RouteAddress = options.inet4RouteAddress
|
||||||
|
|||||||
@@ -87,6 +87,9 @@ import io.nekohasekai.libbox.Libbox
|
|||||||
import io.nekohasekai.sfa.Application
|
import io.nekohasekai.sfa.Application
|
||||||
import io.nekohasekai.sfa.BuildConfig
|
import io.nekohasekai.sfa.BuildConfig
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.bg.BoxService
|
||||||
|
import io.nekohasekai.sfa.bg.CrashReportManager
|
||||||
|
import io.nekohasekai.sfa.bg.OOMReportManager
|
||||||
import io.nekohasekai.sfa.bg.ServiceConnection
|
import io.nekohasekai.sfa.bg.ServiceConnection
|
||||||
import io.nekohasekai.sfa.bg.ServiceNotification
|
import io.nekohasekai.sfa.bg.ServiceNotification
|
||||||
import io.nekohasekai.sfa.compat.WindowSizeClassCompat
|
import io.nekohasekai.sfa.compat.WindowSizeClassCompat
|
||||||
@@ -111,6 +114,7 @@ import io.nekohasekai.sfa.compose.screen.dashboard.DashboardViewModel
|
|||||||
import io.nekohasekai.sfa.compose.screen.dashboard.GroupsCard
|
import io.nekohasekai.sfa.compose.screen.dashboard.GroupsCard
|
||||||
import io.nekohasekai.sfa.compose.screen.dashboard.groups.GroupsViewModel
|
import io.nekohasekai.sfa.compose.screen.dashboard.groups.GroupsViewModel
|
||||||
import io.nekohasekai.sfa.compose.screen.log.LogViewModel
|
import io.nekohasekai.sfa.compose.screen.log.LogViewModel
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.TailscaleStatusViewModel
|
||||||
import io.nekohasekai.sfa.compose.theme.SFATheme
|
import io.nekohasekai.sfa.compose.theme.SFATheme
|
||||||
import io.nekohasekai.sfa.compose.topbar.LocalTopBarController
|
import io.nekohasekai.sfa.compose.topbar.LocalTopBarController
|
||||||
import io.nekohasekai.sfa.compose.topbar.TopBarController
|
import io.nekohasekai.sfa.compose.topbar.TopBarController
|
||||||
@@ -126,6 +130,7 @@ import io.nekohasekai.sfa.update.UpdateState
|
|||||||
import io.nekohasekai.sfa.vendor.Vendor
|
import io.nekohasekai.sfa.vendor.Vendor
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@@ -327,6 +332,89 @@ class MainActivity :
|
|||||||
|
|
||||||
// Snackbar state
|
// Snackbar state
|
||||||
val snackbarHostState = remember { SnackbarHostState() }
|
val snackbarHostState = remember { SnackbarHostState() }
|
||||||
|
// Error dialog state for UiEvent.ShowError
|
||||||
|
var showErrorDialog by remember { mutableStateOf(false) }
|
||||||
|
var errorMessage by remember { mutableStateOf("") }
|
||||||
|
var pendingApplyServiceChangeMode by remember { mutableStateOf<UiEvent.ApplyServiceChange.Mode?>(null) }
|
||||||
|
var activeApplyServiceChangeMode by remember { mutableStateOf<UiEvent.ApplyServiceChange.Mode?>(null) }
|
||||||
|
var applyServiceChangeJob by remember { mutableStateOf<Job?>(null) }
|
||||||
|
|
||||||
|
fun mergeApplyServiceChangeMode(
|
||||||
|
current: UiEvent.ApplyServiceChange.Mode?,
|
||||||
|
incoming: UiEvent.ApplyServiceChange.Mode,
|
||||||
|
): UiEvent.ApplyServiceChange.Mode = when {
|
||||||
|
current == UiEvent.ApplyServiceChange.Mode.Restart ||
|
||||||
|
incoming == UiEvent.ApplyServiceChange.Mode.Restart -> {
|
||||||
|
UiEvent.ApplyServiceChange.Mode.Restart
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> incoming
|
||||||
|
}
|
||||||
|
|
||||||
|
fun enqueueApplyServiceChange(mode: UiEvent.ApplyServiceChange.Mode) {
|
||||||
|
if (currentServiceStatus != Status.Started) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pendingApplyServiceChangeMode = mergeApplyServiceChangeMode(pendingApplyServiceChangeMode, mode)
|
||||||
|
|
||||||
|
val activeMode = activeApplyServiceChangeMode
|
||||||
|
if (activeMode != null &&
|
||||||
|
mergeApplyServiceChangeMode(activeMode, mode) != activeMode
|
||||||
|
) {
|
||||||
|
snackbarHostState.currentSnackbarData?.dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (applyServiceChangeJob?.isActive == true) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
applyServiceChangeJob =
|
||||||
|
scope.launch {
|
||||||
|
while (true) {
|
||||||
|
val modeToShow = pendingApplyServiceChangeMode ?: break
|
||||||
|
pendingApplyServiceChangeMode = null
|
||||||
|
activeApplyServiceChangeMode = modeToShow
|
||||||
|
val (message, actionLabel) =
|
||||||
|
when (modeToShow) {
|
||||||
|
UiEvent.ApplyServiceChange.Mode.Reload -> {
|
||||||
|
getString(R.string.service_reload_required) to
|
||||||
|
getString(R.string.action_reload)
|
||||||
|
}
|
||||||
|
|
||||||
|
UiEvent.ApplyServiceChange.Mode.Restart -> {
|
||||||
|
getString(R.string.service_restart_required) to
|
||||||
|
getString(R.string.action_restart)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val result =
|
||||||
|
snackbarHostState.showSnackbar(
|
||||||
|
message = message,
|
||||||
|
actionLabel = actionLabel,
|
||||||
|
duration = androidx.compose.material3.SnackbarDuration.Short,
|
||||||
|
)
|
||||||
|
activeApplyServiceChangeMode = null
|
||||||
|
if (result == androidx.compose.material3.SnackbarResult.ActionPerformed) {
|
||||||
|
try {
|
||||||
|
when (modeToShow) {
|
||||||
|
UiEvent.ApplyServiceChange.Mode.Reload -> {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
Libbox.newStandaloneCommandClient().serviceReload()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UiEvent.ApplyServiceChange.Mode.Restart -> {
|
||||||
|
restartServiceForApplyChange()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
errorMessage = e.message ?: e.toString()
|
||||||
|
showErrorDialog = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Groups Sheet state
|
// Groups Sheet state
|
||||||
var showGroupsSheet by remember { mutableStateOf(false) }
|
var showGroupsSheet by remember { mutableStateOf(false) }
|
||||||
@@ -335,8 +423,6 @@ class MainActivity :
|
|||||||
var showConnectionsSheet by remember { mutableStateOf(false) }
|
var showConnectionsSheet by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
// Error dialog state for UiEvent.ShowError
|
// Error dialog state for UiEvent.ShowError
|
||||||
var showErrorDialog by remember { mutableStateOf(false) }
|
|
||||||
var errorMessage by remember { mutableStateOf("") }
|
|
||||||
val pendingIntentError = pendingIntentErrorMessage
|
val pendingIntentError = pendingIntentErrorMessage
|
||||||
LaunchedEffect(pendingIntentError) {
|
LaunchedEffect(pendingIntentError) {
|
||||||
if (pendingIntentError != null) {
|
if (pendingIntentError != null) {
|
||||||
@@ -616,11 +702,13 @@ class MainActivity :
|
|||||||
val dashboardUiState by dashboardViewModel.uiState.collectAsState()
|
val dashboardUiState by dashboardViewModel.uiState.collectAsState()
|
||||||
|
|
||||||
val isSettingsSubScreen = currentRoute?.startsWith("settings/") == true
|
val isSettingsSubScreen = currentRoute?.startsWith("settings/") == true
|
||||||
|
val isToolsSubScreen = currentRoute?.startsWith("tools/") == true
|
||||||
val isConnectionsDetail = currentRoute?.startsWith("connections/detail") == true
|
val isConnectionsDetail = currentRoute?.startsWith("connections/detail") == true
|
||||||
val isProfileRoute = currentRoute?.startsWith("profile/") == true
|
val isProfileRoute = currentRoute?.startsWith("profile/") == true
|
||||||
val currentRootRoute =
|
val currentRootRoute =
|
||||||
when {
|
when {
|
||||||
isSettingsSubScreen -> Screen.Settings.route
|
isSettingsSubScreen -> Screen.Settings.route
|
||||||
|
isToolsSubScreen -> Screen.Tools.route
|
||||||
currentRoute?.startsWith(Screen.Connections.route) == true -> Screen.Connections.route
|
currentRoute?.startsWith(Screen.Connections.route) == true -> Screen.Connections.route
|
||||||
currentRoute?.startsWith(Screen.Log.route) == true -> Screen.Log.route
|
currentRoute?.startsWith(Screen.Log.route) == true -> Screen.Log.route
|
||||||
isProfileRoute -> Screen.Dashboard.route
|
isProfileRoute -> Screen.Dashboard.route
|
||||||
@@ -630,7 +718,7 @@ class MainActivity :
|
|||||||
val isGroupsRoute = currentRootRoute == Screen.Groups.route
|
val isGroupsRoute = currentRootRoute == Screen.Groups.route
|
||||||
val isLogRoute = currentRootRoute == Screen.Log.route
|
val isLogRoute = currentRootRoute == Screen.Log.route
|
||||||
|
|
||||||
val isSubScreen = isSettingsSubScreen || isConnectionsDetail || isProfileRoute
|
val isSubScreen = isSettingsSubScreen || isToolsSubScreen || isConnectionsDetail || isProfileRoute
|
||||||
// Get LogViewModel instance if we're on the Log screen
|
// Get LogViewModel instance if we're on the Log screen
|
||||||
val logViewModel: LogViewModel? =
|
val logViewModel: LogViewModel? =
|
||||||
if (isLogRoute) {
|
if (isLogRoute) {
|
||||||
@@ -660,6 +748,14 @@ class MainActivity :
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isToolsRoute = currentRootRoute == Screen.Tools.route
|
||||||
|
val tailscaleStatusViewModel: TailscaleStatusViewModel? =
|
||||||
|
if (isToolsRoute) {
|
||||||
|
viewModel()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
val showGroupsInNav = dashboardUiState.hasGroups
|
val showGroupsInNav = dashboardUiState.hasGroups
|
||||||
val showConnectionsInNav =
|
val showConnectionsInNav =
|
||||||
currentServiceStatus == Status.Started || currentServiceStatus == Status.Starting
|
currentServiceStatus == Status.Started || currentServiceStatus == Status.Starting
|
||||||
@@ -674,6 +770,7 @@ class MainActivity :
|
|||||||
add(Screen.Connections)
|
add(Screen.Connections)
|
||||||
}
|
}
|
||||||
add(Screen.Log)
|
add(Screen.Log)
|
||||||
|
add(Screen.Tools)
|
||||||
add(Screen.Settings)
|
add(Screen.Settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,6 +778,7 @@ class MainActivity :
|
|||||||
buildSet {
|
buildSet {
|
||||||
add(Screen.Dashboard.route)
|
add(Screen.Dashboard.route)
|
||||||
add(Screen.Log.route)
|
add(Screen.Log.route)
|
||||||
|
add(Screen.Tools.route)
|
||||||
add(Screen.Settings.route)
|
add(Screen.Settings.route)
|
||||||
if (useNavigationRail && showGroupsInNav) {
|
if (useNavigationRail && showGroupsInNav) {
|
||||||
add(Screen.Groups.route)
|
add(Screen.Groups.route)
|
||||||
@@ -739,24 +837,7 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is UiEvent.RestartToTakeEffect -> {
|
is UiEvent.ApplyServiceChange -> enqueueApplyServiceChange(event.mode)
|
||||||
if (currentServiceStatus == Status.Started) {
|
|
||||||
scope.launch {
|
|
||||||
snackbarHostState.currentSnackbarData?.dismiss()
|
|
||||||
val result =
|
|
||||||
snackbarHostState.showSnackbar(
|
|
||||||
message = "Restart to take effect",
|
|
||||||
actionLabel = "Restart",
|
|
||||||
duration = androidx.compose.material3.SnackbarDuration.Short,
|
|
||||||
)
|
|
||||||
if (result == androidx.compose.material3.SnackbarResult.ActionPerformed) {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
Libbox.newStandaloneCommandClient().serviceReload()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -789,6 +870,7 @@ class MainActivity :
|
|||||||
logViewModel = logViewModel,
|
logViewModel = logViewModel,
|
||||||
groupsViewModel = groupsViewModel,
|
groupsViewModel = groupsViewModel,
|
||||||
connectionsViewModel = connectionsViewModel,
|
connectionsViewModel = connectionsViewModel,
|
||||||
|
tailscaleStatusViewModel = tailscaleStatusViewModel,
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
)
|
)
|
||||||
if (!useNavigationRail) {
|
if (!useNavigationRail) {
|
||||||
@@ -919,6 +1001,17 @@ class MainActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val crashReportUnreadCount by CrashReportManager.unreadCount.collectAsState()
|
||||||
|
val oomReportUnreadCount by OOMReportManager.unreadCount.collectAsState()
|
||||||
|
val toolsUnreadCount = crashReportUnreadCount + oomReportUnreadCount
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
CrashReportManager.refresh()
|
||||||
|
OOMReportManager.refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CompositionLocalProvider(LocalTopBarController provides topBarController) {
|
CompositionLocalProvider(LocalTopBarController provides topBarController) {
|
||||||
if (useNavigationRail) {
|
if (useNavigationRail) {
|
||||||
Row(modifier = Modifier.fillMaxSize()) {
|
Row(modifier = Modifier.fillMaxSize()) {
|
||||||
@@ -936,6 +1029,10 @@ class MainActivity :
|
|||||||
BadgedBox(badge = { Badge(containerColor = MaterialTheme.colorScheme.primary) }) {
|
BadgedBox(badge = { Badge(containerColor = MaterialTheme.colorScheme.primary) }) {
|
||||||
Icon(screen.icon, contentDescription = null)
|
Icon(screen.icon, contentDescription = null)
|
||||||
}
|
}
|
||||||
|
} else if (screen == Screen.Tools && toolsUnreadCount > 0) {
|
||||||
|
BadgedBox(badge = { Badge(containerColor = MaterialTheme.colorScheme.error) { Text("$toolsUnreadCount") } }) {
|
||||||
|
Icon(screen.icon, contentDescription = null)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Icon(screen.icon, contentDescription = null)
|
Icon(screen.icon, contentDescription = null)
|
||||||
}
|
}
|
||||||
@@ -980,6 +1077,10 @@ class MainActivity :
|
|||||||
BadgedBox(badge = { Badge(containerColor = MaterialTheme.colorScheme.primary) }) {
|
BadgedBox(badge = { Badge(containerColor = MaterialTheme.colorScheme.primary) }) {
|
||||||
Icon(screen.icon, contentDescription = null)
|
Icon(screen.icon, contentDescription = null)
|
||||||
}
|
}
|
||||||
|
} else if (screen == Screen.Tools && toolsUnreadCount > 0) {
|
||||||
|
BadgedBox(badge = { Badge(containerColor = MaterialTheme.colorScheme.error) { Text("$toolsUnreadCount") } }) {
|
||||||
|
Icon(screen.icon, contentDescription = null)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Icon(screen.icon, contentDescription = null)
|
Icon(screen.icon, contentDescription = null)
|
||||||
}
|
}
|
||||||
@@ -1192,6 +1293,30 @@ class MainActivity :
|
|||||||
showBackgroundLocationDialog = true
|
showBackgroundLocationDialog = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun restartServiceForApplyChange() {
|
||||||
|
if (currentServiceStatus != Status.Started) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
BoxService.stop()
|
||||||
|
while (true) {
|
||||||
|
when (currentServiceStatus) {
|
||||||
|
Status.Stopped -> {
|
||||||
|
startService()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Status.Starting -> {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Status.Started, Status.Stopping -> {
|
||||||
|
delay(100L)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
connection.disconnect()
|
connection.disconnect()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.base
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import io.nekohasekai.sfa.constant.Status
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun rememberApplyServiceChangeNotifier(
|
||||||
|
serviceStatus: Status,
|
||||||
|
): (UiEvent.ApplyServiceChange.Mode) -> Unit = remember(serviceStatus) {
|
||||||
|
{ mode ->
|
||||||
|
if (serviceStatus == Status.Started) {
|
||||||
|
GlobalEventBus.tryEmit(UiEvent.ApplyServiceChange(mode))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,12 @@ sealed class UiEvent {
|
|||||||
|
|
||||||
object RequestReconnectService : UiEvent()
|
object RequestReconnectService : UiEvent()
|
||||||
|
|
||||||
object RestartToTakeEffect : UiEvent()
|
data class ApplyServiceChange(val mode: Mode) : UiEvent() {
|
||||||
|
enum class Mode {
|
||||||
|
Reload,
|
||||||
|
Restart,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.compose.material.icons.filled.Dashboard
|
|||||||
import androidx.compose.material.icons.filled.Folder
|
import androidx.compose.material.icons.filled.Folder
|
||||||
import androidx.compose.material.icons.filled.Settings
|
import androidx.compose.material.icons.filled.Settings
|
||||||
import androidx.compose.material.icons.filled.SwapVert
|
import androidx.compose.material.icons.filled.SwapVert
|
||||||
|
import androidx.compose.material.icons.filled.Terminal
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
|
|
||||||
@@ -35,6 +36,12 @@ sealed class Screen(val route: String, @StringRes val titleRes: Int, val icon: I
|
|||||||
icon = Icons.Default.SwapVert,
|
icon = Icons.Default.SwapVert,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
object Tools : Screen(
|
||||||
|
route = "tools",
|
||||||
|
titleRes = R.string.title_tools,
|
||||||
|
icon = Icons.Default.Terminal,
|
||||||
|
)
|
||||||
|
|
||||||
object Settings : Screen(
|
object Settings : Screen(
|
||||||
route = "settings",
|
route = "settings",
|
||||||
titleRes = R.string.title_settings,
|
titleRes = R.string.title_settings,
|
||||||
@@ -46,5 +53,6 @@ val bottomNavigationScreens =
|
|||||||
listOf(
|
listOf(
|
||||||
Screen.Dashboard,
|
Screen.Dashboard,
|
||||||
Screen.Log,
|
Screen.Log,
|
||||||
|
Screen.Tools,
|
||||||
Screen.Settings,
|
Screen.Settings,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.NavType
|
import androidx.navigation.NavType
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
@@ -33,6 +34,21 @@ import io.nekohasekai.sfa.compose.screen.settings.PrivilegeSettingsScreen
|
|||||||
import io.nekohasekai.sfa.compose.screen.settings.ProfileOverrideScreen
|
import io.nekohasekai.sfa.compose.screen.settings.ProfileOverrideScreen
|
||||||
import io.nekohasekai.sfa.compose.screen.settings.ServiceSettingsScreen
|
import io.nekohasekai.sfa.compose.screen.settings.ServiceSettingsScreen
|
||||||
import io.nekohasekai.sfa.compose.screen.settings.SettingsScreen
|
import io.nekohasekai.sfa.compose.screen.settings.SettingsScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.CrashReportDetailScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.CrashReportFileContentScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.CrashReportListScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.CrashReportMetadataScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.NetworkQualityScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.OOMReportDetailScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.OOMReportFileContentScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.OOMReportListScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.OOMReportMetadataScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.OutboundPickerScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.STUNTestScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.TailscaleEndpointScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.TailscalePeerScreen
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.TailscaleStatusViewModel
|
||||||
|
import io.nekohasekai.sfa.compose.screen.tools.ToolsScreen
|
||||||
import io.nekohasekai.sfa.constant.Status
|
import io.nekohasekai.sfa.constant.Status
|
||||||
|
|
||||||
private val slideInFromRight: AnimatedContentTransitionScope<*>.() -> androidx.compose.animation.EnterTransition = {
|
private val slideInFromRight: AnimatedContentTransitionScope<*>.() -> androidx.compose.animation.EnterTransition = {
|
||||||
@@ -64,6 +80,7 @@ fun SFANavHost(
|
|||||||
logViewModel: LogViewModel? = null,
|
logViewModel: LogViewModel? = null,
|
||||||
groupsViewModel: GroupsViewModel? = null,
|
groupsViewModel: GroupsViewModel? = null,
|
||||||
connectionsViewModel: ConnectionsViewModel? = null,
|
connectionsViewModel: ConnectionsViewModel? = null,
|
||||||
|
tailscaleStatusViewModel: TailscaleStatusViewModel? = null,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
NavHost(
|
NavHost(
|
||||||
@@ -210,6 +227,174 @@ fun SFANavHost(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
composable(Screen.Tools.route) {
|
||||||
|
val tailscaleViewModel: TailscaleStatusViewModel = tailscaleStatusViewModel ?: viewModel()
|
||||||
|
ToolsScreen(navController = navController, serviceStatus = serviceStatus, tailscaleViewModel = tailscaleViewModel)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tools subscreens with slide animations
|
||||||
|
composable(
|
||||||
|
route = "tools/network_quality",
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) {
|
||||||
|
NetworkQualityScreen(navController = navController, serviceStatus = serviceStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/stun_test",
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) {
|
||||||
|
STUNTestScreen(navController = navController, serviceStatus = serviceStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/outbound_picker/{selectedOutbound}",
|
||||||
|
arguments = listOf(navArgument("selectedOutbound") { type = NavType.StringType }),
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) { backStackEntry ->
|
||||||
|
val selectedOutbound = Uri.decode(backStackEntry.arguments?.getString("selectedOutbound") ?: "")
|
||||||
|
OutboundPickerScreen(navController = navController, selectedOutbound = selectedOutbound)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/tailscale/{endpointTag}",
|
||||||
|
arguments = listOf(navArgument("endpointTag") { type = NavType.StringType }),
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) { backStackEntry ->
|
||||||
|
val endpointTag = Uri.decode(backStackEntry.arguments?.getString("endpointTag") ?: return@composable)
|
||||||
|
val tailscaleViewModel: TailscaleStatusViewModel = tailscaleStatusViewModel ?: viewModel()
|
||||||
|
TailscaleEndpointScreen(navController = navController, viewModel = tailscaleViewModel, endpointTag = endpointTag)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/tailscale/{endpointTag}/peer/{peerId}",
|
||||||
|
arguments = listOf(
|
||||||
|
navArgument("endpointTag") { type = NavType.StringType },
|
||||||
|
navArgument("peerId") { type = NavType.StringType },
|
||||||
|
),
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) { backStackEntry ->
|
||||||
|
val endpointTag = Uri.decode(backStackEntry.arguments?.getString("endpointTag") ?: return@composable)
|
||||||
|
val peerId = Uri.decode(backStackEntry.arguments?.getString("peerId") ?: return@composable)
|
||||||
|
val tailscaleViewModel: TailscaleStatusViewModel = tailscaleStatusViewModel ?: viewModel()
|
||||||
|
TailscalePeerScreen(navController = navController, viewModel = tailscaleViewModel, endpointTag = endpointTag, peerId = peerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/crash_report",
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) {
|
||||||
|
CrashReportListScreen(navController = navController)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/crash_report/{reportId}",
|
||||||
|
arguments = listOf(navArgument("reportId") { type = NavType.StringType }),
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) { backStackEntry ->
|
||||||
|
val reportId = backStackEntry.arguments?.getString("reportId") ?: return@composable
|
||||||
|
CrashReportDetailScreen(navController = navController, reportId = reportId)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/crash_report/{reportId}/metadata",
|
||||||
|
arguments = listOf(navArgument("reportId") { type = NavType.StringType }),
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) { backStackEntry ->
|
||||||
|
val reportId = backStackEntry.arguments?.getString("reportId") ?: return@composable
|
||||||
|
CrashReportMetadataScreen(navController = navController, reportId = reportId)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/crash_report/{reportId}/file/{fileKind}",
|
||||||
|
arguments = listOf(
|
||||||
|
navArgument("reportId") { type = NavType.StringType },
|
||||||
|
navArgument("fileKind") { type = NavType.StringType },
|
||||||
|
),
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) { backStackEntry ->
|
||||||
|
val reportId = backStackEntry.arguments?.getString("reportId") ?: return@composable
|
||||||
|
val fileKind = backStackEntry.arguments?.getString("fileKind") ?: return@composable
|
||||||
|
CrashReportFileContentScreen(navController = navController, reportId = reportId, fileKind = fileKind)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/oom_report",
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) {
|
||||||
|
OOMReportListScreen(navController = navController, serviceStatus = serviceStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/oom_report/{reportId}",
|
||||||
|
arguments = listOf(navArgument("reportId") { type = NavType.StringType }),
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) { backStackEntry ->
|
||||||
|
val reportId = backStackEntry.arguments?.getString("reportId") ?: return@composable
|
||||||
|
OOMReportDetailScreen(navController = navController, reportId = reportId)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/oom_report/{reportId}/metadata",
|
||||||
|
arguments = listOf(navArgument("reportId") { type = NavType.StringType }),
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) { backStackEntry ->
|
||||||
|
val reportId = backStackEntry.arguments?.getString("reportId") ?: return@composable
|
||||||
|
OOMReportMetadataScreen(navController = navController, reportId = reportId)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(
|
||||||
|
route = "tools/oom_report/{reportId}/file/{fileKind}",
|
||||||
|
arguments = listOf(
|
||||||
|
navArgument("reportId") { type = NavType.StringType },
|
||||||
|
navArgument("fileKind") { type = NavType.StringType },
|
||||||
|
),
|
||||||
|
enterTransition = slideInFromRight,
|
||||||
|
exitTransition = slideOutToLeft,
|
||||||
|
popEnterTransition = slideInFromLeft,
|
||||||
|
popExitTransition = slideOutToRight,
|
||||||
|
) { backStackEntry ->
|
||||||
|
val reportId = backStackEntry.arguments?.getString("reportId") ?: return@composable
|
||||||
|
val fileKind = backStackEntry.arguments?.getString("fileKind") ?: return@composable
|
||||||
|
OOMReportFileContentScreen(navController = navController, reportId = reportId, fileKind = fileKind)
|
||||||
|
}
|
||||||
|
|
||||||
composable(Screen.Settings.route) {
|
composable(Screen.Settings.route) {
|
||||||
SettingsScreen(navController = navController)
|
SettingsScreen(navController = navController)
|
||||||
}
|
}
|
||||||
@@ -222,7 +407,7 @@ fun SFANavHost(
|
|||||||
popEnterTransition = slideInFromLeft,
|
popEnterTransition = slideInFromLeft,
|
||||||
popExitTransition = slideOutToRight,
|
popExitTransition = slideOutToRight,
|
||||||
) {
|
) {
|
||||||
AppSettingsScreen(navController = navController)
|
AppSettingsScreen(navController = navController, serviceStatus = serviceStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(
|
composable(
|
||||||
@@ -252,7 +437,7 @@ fun SFANavHost(
|
|||||||
popEnterTransition = slideInFromLeft,
|
popEnterTransition = slideInFromLeft,
|
||||||
popExitTransition = slideOutToRight,
|
popExitTransition = slideOutToRight,
|
||||||
) {
|
) {
|
||||||
ServiceSettingsScreen(navController = navController)
|
ServiceSettingsScreen(navController = navController, serviceStatus = serviceStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(
|
composable(
|
||||||
@@ -262,7 +447,7 @@ fun SFANavHost(
|
|||||||
popEnterTransition = slideInFromLeft,
|
popEnterTransition = slideInFromLeft,
|
||||||
popExitTransition = slideOutToRight,
|
popExitTransition = slideOutToRight,
|
||||||
) {
|
) {
|
||||||
ProfileOverrideScreen(navController = navController)
|
ProfileOverrideScreen(navController = navController, serviceStatus = serviceStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(
|
composable(
|
||||||
@@ -272,7 +457,7 @@ fun SFANavHost(
|
|||||||
popEnterTransition = slideInFromLeft,
|
popEnterTransition = slideInFromLeft,
|
||||||
popExitTransition = slideOutToRight,
|
popExitTransition = slideOutToRight,
|
||||||
) {
|
) {
|
||||||
PerAppProxyScreen(onBack = { navController.navigateUp() })
|
PerAppProxyScreen(onBack = { navController.navigateUp() }, serviceStatus = serviceStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(
|
composable(
|
||||||
@@ -292,7 +477,7 @@ fun SFANavHost(
|
|||||||
popEnterTransition = slideInFromLeft,
|
popEnterTransition = slideInFromLeft,
|
||||||
popExitTransition = slideOutToRight,
|
popExitTransition = slideOutToRight,
|
||||||
) {
|
) {
|
||||||
PrivilegeSettingsManageScreen(onBack = { navController.navigateUp() })
|
PrivilegeSettingsManageScreen(onBack = { navController.navigateUp() }, serviceStatus = serviceStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(
|
composable(
|
||||||
|
|||||||
+10
-1
@@ -53,11 +53,14 @@ import androidx.compose.ui.platform.LocalFocusManager
|
|||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.compose.base.UiEvent
|
||||||
|
import io.nekohasekai.sfa.compose.base.rememberApplyServiceChangeNotifier
|
||||||
import io.nekohasekai.sfa.compose.shared.AppSelectionCard
|
import io.nekohasekai.sfa.compose.shared.AppSelectionCard
|
||||||
import io.nekohasekai.sfa.compose.shared.PackageCache
|
import io.nekohasekai.sfa.compose.shared.PackageCache
|
||||||
import io.nekohasekai.sfa.compose.shared.SortMode
|
import io.nekohasekai.sfa.compose.shared.SortMode
|
||||||
import io.nekohasekai.sfa.compose.shared.buildDisplayPackages
|
import io.nekohasekai.sfa.compose.shared.buildDisplayPackages
|
||||||
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.constant.Status
|
||||||
import io.nekohasekai.sfa.database.Settings
|
import io.nekohasekai.sfa.database.Settings
|
||||||
import io.nekohasekai.sfa.ktx.clipboardText
|
import io.nekohasekai.sfa.ktx.clipboardText
|
||||||
import io.nekohasekai.sfa.utils.PrivilegeSettingsClient
|
import io.nekohasekai.sfa.utils.PrivilegeSettingsClient
|
||||||
@@ -95,10 +98,14 @@ private enum class RiskCategory {
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun PrivilegeSettingsManageScreen(onBack: () -> Unit) {
|
fun PrivilegeSettingsManageScreen(
|
||||||
|
onBack: () -> Unit,
|
||||||
|
serviceStatus: Status = Status.Stopped,
|
||||||
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
val notifyApplyChange = rememberApplyServiceChangeNotifier(serviceStatus)
|
||||||
|
|
||||||
var sortMode by remember { mutableStateOf(SortMode.NAME) }
|
var sortMode by remember { mutableStateOf(SortMode.NAME) }
|
||||||
var sortReverse by remember { mutableStateOf(false) }
|
var sortReverse by remember { mutableStateOf(false) }
|
||||||
@@ -176,6 +183,8 @@ fun PrivilegeSettingsManageScreen(onBack: () -> Unit) {
|
|||||||
}
|
}
|
||||||
if (failure != null) {
|
if (failure != null) {
|
||||||
syncErrorMessage = failure.message ?: failure.toString()
|
syncErrorMessage = failure.message ?: failure.toString()
|
||||||
|
} else {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-3
@@ -77,11 +77,14 @@ import androidx.compose.ui.window.DialogProperties
|
|||||||
import com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile
|
import com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile
|
||||||
import io.nekohasekai.sfa.Application
|
import io.nekohasekai.sfa.Application
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.compose.base.UiEvent
|
||||||
|
import io.nekohasekai.sfa.compose.base.rememberApplyServiceChangeNotifier
|
||||||
import io.nekohasekai.sfa.compose.shared.AppSelectionCard
|
import io.nekohasekai.sfa.compose.shared.AppSelectionCard
|
||||||
import io.nekohasekai.sfa.compose.shared.PackageCache
|
import io.nekohasekai.sfa.compose.shared.PackageCache
|
||||||
import io.nekohasekai.sfa.compose.shared.SortMode
|
import io.nekohasekai.sfa.compose.shared.SortMode
|
||||||
import io.nekohasekai.sfa.compose.shared.buildDisplayPackages
|
import io.nekohasekai.sfa.compose.shared.buildDisplayPackages
|
||||||
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.constant.Status
|
||||||
import io.nekohasekai.sfa.database.Settings
|
import io.nekohasekai.sfa.database.Settings
|
||||||
import io.nekohasekai.sfa.ktx.clipboardText
|
import io.nekohasekai.sfa.ktx.clipboardText
|
||||||
import io.nekohasekai.sfa.vendor.PackageQueryManager
|
import io.nekohasekai.sfa.vendor.PackageQueryManager
|
||||||
@@ -106,10 +109,14 @@ private sealed class ScanResult {
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun PerAppProxyScreen(onBack: () -> Unit) {
|
fun PerAppProxyScreen(
|
||||||
|
onBack: () -> Unit,
|
||||||
|
serviceStatus: Status = Status.Stopped,
|
||||||
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val focusManager = LocalFocusManager.current
|
val focusManager = LocalFocusManager.current
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
val notifyApplyChange = rememberApplyServiceChangeNotifier(serviceStatus)
|
||||||
|
|
||||||
var proxyMode by remember { mutableStateOf(Settings.perAppProxyMode) }
|
var proxyMode by remember { mutableStateOf(Settings.perAppProxyMode) }
|
||||||
var sortMode by remember { mutableStateOf(SortMode.NAME) }
|
var sortMode by remember { mutableStateOf(SortMode.NAME) }
|
||||||
@@ -164,7 +171,10 @@ fun PerAppProxyScreen(onBack: () -> Unit) {
|
|||||||
|
|
||||||
fun saveSelectedApplications(newUids: Set<Int>) {
|
fun saveSelectedApplications(newUids: Set<Int>) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
Settings.perAppProxyList = buildPackageList(newUids)
|
withContext(Dispatchers.IO) {
|
||||||
|
Settings.perAppProxyList = buildPackageList(newUids)
|
||||||
|
}
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +333,10 @@ fun PerAppProxyScreen(onBack: () -> Unit) {
|
|||||||
onModeChange = { mode ->
|
onModeChange = { mode ->
|
||||||
proxyMode = mode
|
proxyMode = mode
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
Settings.perAppProxyMode = mode
|
withContext(Dispatchers.IO) {
|
||||||
|
Settings.perAppProxyMode = mode
|
||||||
|
}
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSortModeChange = { mode ->
|
onSortModeChange = { mode ->
|
||||||
|
|||||||
@@ -87,8 +87,11 @@ import io.nekohasekai.libbox.Libbox
|
|||||||
import io.nekohasekai.sfa.Application
|
import io.nekohasekai.sfa.Application
|
||||||
import io.nekohasekai.sfa.BuildConfig
|
import io.nekohasekai.sfa.BuildConfig
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.compose.base.UiEvent
|
||||||
|
import io.nekohasekai.sfa.compose.base.rememberApplyServiceChangeNotifier
|
||||||
import io.nekohasekai.sfa.compose.component.UpdateAvailableDialog
|
import io.nekohasekai.sfa.compose.component.UpdateAvailableDialog
|
||||||
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.constant.Status
|
||||||
import io.nekohasekai.sfa.database.Settings
|
import io.nekohasekai.sfa.database.Settings
|
||||||
import io.nekohasekai.sfa.ktx.clipboardText
|
import io.nekohasekai.sfa.ktx.clipboardText
|
||||||
import io.nekohasekai.sfa.update.UpdateCheckException
|
import io.nekohasekai.sfa.update.UpdateCheckException
|
||||||
@@ -109,7 +112,10 @@ import android.provider.Settings as AndroidSettings
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun AppSettingsScreen(navController: NavController) {
|
fun AppSettingsScreen(
|
||||||
|
navController: NavController,
|
||||||
|
serviceStatus: Status = Status.Stopped,
|
||||||
|
) {
|
||||||
OverrideTopBar {
|
OverrideTopBar {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = { Text(stringResource(R.string.title_app_settings)) },
|
title = { Text(stringResource(R.string.title_app_settings)) },
|
||||||
@@ -155,6 +161,7 @@ fun AppSettingsScreen(navController: NavController) {
|
|||||||
var notificationEnabled by remember { mutableStateOf(true) }
|
var notificationEnabled by remember { mutableStateOf(true) }
|
||||||
var dynamicNotification by remember { mutableStateOf(Settings.dynamicNotification) }
|
var dynamicNotification by remember { mutableStateOf(Settings.dynamicNotification) }
|
||||||
var showDisableNotificationDialog by remember { mutableStateOf(false) }
|
var showDisableNotificationDialog by remember { mutableStateOf(false) }
|
||||||
|
val notifyApplyChange = rememberApplyServiceChangeNotifier(serviceStatus)
|
||||||
|
|
||||||
var showLanguageDialog by remember { mutableStateOf(false) }
|
var showLanguageDialog by remember { mutableStateOf(false) }
|
||||||
val availableLocales = remember { getSupportedLocales(context) }
|
val availableLocales = remember { getSupportedLocales(context) }
|
||||||
@@ -679,6 +686,9 @@ fun AppSettingsScreen(navController: NavController) {
|
|||||||
dynamicNotification = checked
|
dynamicNotification = checked
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
Settings.dynamicNotification = checked
|
Settings.dynamicNotification = checked
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Restart)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
+8
-7
@@ -62,9 +62,9 @@ import androidx.core.content.FileProvider
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import io.nekohasekai.libbox.Libbox
|
import io.nekohasekai.libbox.Libbox
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
import io.nekohasekai.sfa.compose.base.GlobalEventBus
|
|
||||||
import io.nekohasekai.sfa.compose.base.SelectableMessageDialog
|
import io.nekohasekai.sfa.compose.base.SelectableMessageDialog
|
||||||
import io.nekohasekai.sfa.compose.base.UiEvent
|
import io.nekohasekai.sfa.compose.base.UiEvent
|
||||||
|
import io.nekohasekai.sfa.compose.base.rememberApplyServiceChangeNotifier
|
||||||
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
import io.nekohasekai.sfa.constant.Status
|
import io.nekohasekai.sfa.constant.Status
|
||||||
import io.nekohasekai.sfa.database.Settings
|
import io.nekohasekai.sfa.database.Settings
|
||||||
@@ -101,6 +101,7 @@ fun PrivilegeSettingsScreen(navController: NavController, serviceStatus: Status
|
|||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
val notifyApplyChange = rememberApplyServiceChangeNotifier(serviceStatus)
|
||||||
val systemHookStatus by HookStatusClient.status.collectAsState()
|
val systemHookStatus by HookStatusClient.status.collectAsState()
|
||||||
var privilegeSettingsEnabled by remember { mutableStateOf(Settings.privilegeSettingsEnabled) }
|
var privilegeSettingsEnabled by remember { mutableStateOf(Settings.privilegeSettingsEnabled) }
|
||||||
|
|
||||||
@@ -198,8 +199,8 @@ fun PrivilegeSettingsScreen(navController: NavController, serviceStatus: Status
|
|||||||
messageDialogTitle = context.getString(R.string.error_title)
|
messageDialogTitle = context.getString(R.string.error_title)
|
||||||
messageDialogMessage = failure.message ?: failure.toString()
|
messageDialogMessage = failure.message ?: failure.toString()
|
||||||
showMessageDialog = true
|
showMessageDialog = true
|
||||||
} else if (serviceStatus == Status.Started) {
|
} else {
|
||||||
GlobalEventBus.tryEmit(UiEvent.RestartToTakeEffect)
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -608,8 +609,8 @@ fun PrivilegeSettingsScreen(navController: NavController, serviceStatus: Status
|
|||||||
messageDialogTitle = context.getString(R.string.error_title)
|
messageDialogTitle = context.getString(R.string.error_title)
|
||||||
messageDialogMessage = failure.message ?: failure.toString()
|
messageDialogMessage = failure.message ?: failure.toString()
|
||||||
showMessageDialog = true
|
showMessageDialog = true
|
||||||
} else if (checked && serviceStatus == Status.Started) {
|
} else {
|
||||||
GlobalEventBus.tryEmit(UiEvent.RestartToTakeEffect)
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -716,8 +717,8 @@ fun PrivilegeSettingsScreen(navController: NavController, serviceStatus: Status
|
|||||||
messageDialogTitle = context.getString(R.string.error_title)
|
messageDialogTitle = context.getString(R.string.error_title)
|
||||||
messageDialogMessage = failure.message ?: failure.toString()
|
messageDialogMessage = failure.message ?: failure.toString()
|
||||||
showMessageDialog = true
|
showMessageDialog = true
|
||||||
} else if (serviceStatus == Status.Started) {
|
} else {
|
||||||
GlobalEventBus.tryEmit(UiEvent.RestartToTakeEffect)
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+40
-7
@@ -57,8 +57,11 @@ import androidx.lifecycle.LifecycleEventObserver
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
import io.nekohasekai.sfa.bg.RootClient
|
import io.nekohasekai.sfa.bg.RootClient
|
||||||
|
import io.nekohasekai.sfa.compose.base.UiEvent
|
||||||
|
import io.nekohasekai.sfa.compose.base.rememberApplyServiceChangeNotifier
|
||||||
import io.nekohasekai.sfa.compose.screen.profileoverride.PerAppProxyScanner
|
import io.nekohasekai.sfa.compose.screen.profileoverride.PerAppProxyScanner
|
||||||
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.constant.Status
|
||||||
import io.nekohasekai.sfa.database.Settings
|
import io.nekohasekai.sfa.database.Settings
|
||||||
import io.nekohasekai.sfa.vendor.PackageQueryManager
|
import io.nekohasekai.sfa.vendor.PackageQueryManager
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -67,7 +70,10 @@ import kotlinx.coroutines.withContext
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ProfileOverrideScreen(navController: NavController) {
|
fun ProfileOverrideScreen(
|
||||||
|
navController: NavController,
|
||||||
|
serviceStatus: Status = Status.Stopped,
|
||||||
|
) {
|
||||||
OverrideTopBar {
|
OverrideTopBar {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = { Text(stringResource(R.string.profile_override)) },
|
title = { Text(stringResource(R.string.profile_override)) },
|
||||||
@@ -89,8 +95,9 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
var perAppProxyEnabled by remember { mutableStateOf(Settings.perAppProxyEnabled) }
|
var perAppProxyEnabled by remember { mutableStateOf(Settings.perAppProxyEnabled) }
|
||||||
var managedModeEnabled by remember { mutableStateOf(Settings.perAppProxyManagedMode) }
|
var managedModeEnabled by remember { mutableStateOf(Settings.perAppProxyManagedMode) }
|
||||||
var isScanning by remember { mutableStateOf(false) }
|
var isScanning by remember { mutableStateOf(false) }
|
||||||
|
val notifyApplyChange = rememberApplyServiceChangeNotifier(serviceStatus)
|
||||||
|
|
||||||
fun scanAndSaveManagedList() {
|
fun scanAndSaveManagedList(shouldNotify: Boolean = false) {
|
||||||
isScanning = true
|
isScanning = true
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val chinaApps = PerAppProxyScanner.scanAllChinaApps()
|
val chinaApps = PerAppProxyScanner.scanAllChinaApps()
|
||||||
@@ -98,6 +105,9 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
Settings.perAppProxyManagedList = chinaApps
|
Settings.perAppProxyManagedList = chinaApps
|
||||||
}
|
}
|
||||||
isScanning = false
|
isScanning = false
|
||||||
|
if (shouldNotify) {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +179,9 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
Settings.perAppProxyEnabled = true
|
Settings.perAppProxyEnabled = true
|
||||||
}
|
}
|
||||||
if (managedModeEnabled) {
|
if (managedModeEnabled) {
|
||||||
scanAndSaveManagedList()
|
scanAndSaveManagedList(shouldNotify = true)
|
||||||
|
} else {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,6 +239,7 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
Settings.autoRedirect = true
|
Settings.autoRedirect = true
|
||||||
}
|
}
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
context,
|
||||||
@@ -239,6 +252,9 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
autoRedirect = false
|
autoRedirect = false
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
Settings.autoRedirect = false
|
Settings.autoRedirect = false
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -364,9 +380,14 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
perAppProxyEnabled = checked
|
perAppProxyEnabled = checked
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
Settings.perAppProxyEnabled = checked
|
Settings.perAppProxyEnabled = checked
|
||||||
|
if (!checked || !managedModeEnabled) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (checked && managedModeEnabled) {
|
if (checked && managedModeEnabled) {
|
||||||
scanAndSaveManagedList()
|
scanAndSaveManagedList(shouldNotify = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -475,11 +496,14 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
Settings.perAppProxyManagedMode = true
|
Settings.perAppProxyManagedMode = true
|
||||||
}
|
}
|
||||||
scanAndSaveManagedList()
|
scanAndSaveManagedList(shouldNotify = true)
|
||||||
} else {
|
} else {
|
||||||
managedModeEnabled = false
|
managedModeEnabled = false
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
Settings.perAppProxyManagedMode = false
|
Settings.perAppProxyManagedMode = false
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -515,9 +539,14 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
perAppProxyEnabled = true
|
perAppProxyEnabled = true
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
Settings.perAppProxyEnabled = true
|
Settings.perAppProxyEnabled = true
|
||||||
|
if (!managedModeEnabled) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (managedModeEnabled) {
|
if (managedModeEnabled) {
|
||||||
scanAndSaveManagedList()
|
scanAndSaveManagedList(shouldNotify = true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
@@ -593,7 +622,9 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
Settings.perAppProxyEnabled = true
|
Settings.perAppProxyEnabled = true
|
||||||
}
|
}
|
||||||
if (managedModeEnabled) {
|
if (managedModeEnabled) {
|
||||||
scanAndSaveManagedList()
|
scanAndSaveManagedList(shouldNotify = true)
|
||||||
|
} else {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showRootDialog = false
|
showRootDialog = false
|
||||||
@@ -652,6 +683,7 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
Settings.perAppProxyEnabled = false
|
Settings.perAppProxyEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
showModeDialog = false
|
showModeDialog = false
|
||||||
},
|
},
|
||||||
colors = ListItemDefaults.colors(
|
colors = ListItemDefaults.colors(
|
||||||
@@ -672,6 +704,7 @@ fun ProfileOverrideScreen(navController: NavController) {
|
|||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
Settings.perAppProxyPackageQueryMode = Settings.PACKAGE_QUERY_MODE_ROOT
|
Settings.perAppProxyPackageQueryMode = Settings.PACKAGE_QUERY_MODE_ROOT
|
||||||
}
|
}
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
showModeDialog = false
|
showModeDialog = false
|
||||||
},
|
},
|
||||||
colors = ListItemDefaults.colors(
|
colors = ListItemDefaults.colors(
|
||||||
|
|||||||
+13
-1
@@ -57,15 +57,23 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import io.nekohasekai.sfa.R
|
import io.nekohasekai.sfa.R
|
||||||
import io.nekohasekai.sfa.bg.ServiceConnection
|
import io.nekohasekai.sfa.bg.ServiceConnection
|
||||||
|
import io.nekohasekai.sfa.compose.base.UiEvent
|
||||||
|
import io.nekohasekai.sfa.compose.base.rememberApplyServiceChangeNotifier
|
||||||
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.constant.Status
|
||||||
import io.nekohasekai.sfa.database.Settings
|
import io.nekohasekai.sfa.database.Settings
|
||||||
import io.nekohasekai.sfa.ktx.launchCustomTab
|
import io.nekohasekai.sfa.ktx.launchCustomTab
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ServiceSettingsScreen(navController: NavController, serviceConnection: ServiceConnection? = null) {
|
fun ServiceSettingsScreen(
|
||||||
|
navController: NavController,
|
||||||
|
serviceConnection: ServiceConnection? = null,
|
||||||
|
serviceStatus: Status = Status.Stopped,
|
||||||
|
) {
|
||||||
OverrideTopBar {
|
OverrideTopBar {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = { Text(stringResource(R.string.service)) },
|
title = { Text(stringResource(R.string.service)) },
|
||||||
@@ -84,6 +92,7 @@ fun ServiceSettingsScreen(navController: NavController, serviceConnection: Servi
|
|||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
var isBatteryOptimizationIgnored by remember { mutableStateOf(false) }
|
var isBatteryOptimizationIgnored by remember { mutableStateOf(false) }
|
||||||
var allowBypass by remember { mutableStateOf(Settings.allowBypass) }
|
var allowBypass by remember { mutableStateOf(Settings.allowBypass) }
|
||||||
|
val notifyApplyChange = rememberApplyServiceChangeNotifier(serviceStatus)
|
||||||
val requestBatteryOptimizationLauncher =
|
val requestBatteryOptimizationLauncher =
|
||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
ActivityResultContracts.StartActivityForResult(),
|
ActivityResultContracts.StartActivityForResult(),
|
||||||
@@ -255,6 +264,9 @@ fun ServiceSettingsScreen(navController: NavController, serviceConnection: Servi
|
|||||||
allowBypass = checked
|
allowBypass = checked
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
Settings.allowBypass = checked
|
Settings.allowBypass = checked
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Reload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,459 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.DataObject
|
||||||
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material.icons.filled.Share
|
||||||
|
import androidx.compose.material.icons.filled.Terminal
|
||||||
|
import androidx.compose.material.icons.outlined.BugReport
|
||||||
|
import androidx.compose.material.icons.outlined.Settings
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.ListItem
|
||||||
|
import androidx.compose.material3.ListItemDefaults
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.bg.CrashReport
|
||||||
|
import io.nekohasekai.sfa.bg.CrashReportFile
|
||||||
|
import io.nekohasekai.sfa.bg.CrashReportManager
|
||||||
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.text.DateFormat
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun CrashReportDetailScreen(navController: NavController, reportId: String) {
|
||||||
|
val reports by CrashReportManager.reports.collectAsState()
|
||||||
|
val report = reports.find { it.id == reportId }
|
||||||
|
var files by remember { mutableStateOf<List<CrashReportFile>>(emptyList()) }
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
var shareMenuExpanded by remember { mutableStateOf(false) }
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
LaunchedEffect(report) {
|
||||||
|
if (report != null) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
files = CrashReportManager.availableFiles(report)
|
||||||
|
}
|
||||||
|
CrashReportManager.markAsRead(report)
|
||||||
|
}
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
val title = if (report != null) {
|
||||||
|
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(report.date)
|
||||||
|
} else {
|
||||||
|
reportId
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasConfig = report != null && CrashReportManager.hasConfigFile(report)
|
||||||
|
|
||||||
|
fun shareReport(includeConfig: Boolean) {
|
||||||
|
val currentReport = report ?: return
|
||||||
|
scope.launch {
|
||||||
|
val zipFile = CrashReportManager.createZipArchive(currentReport, includeConfig)
|
||||||
|
val uri = FileProvider.getUriForFile(context, "${context.packageName}.cache", zipFile)
|
||||||
|
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||||
|
type = "application/zip"
|
||||||
|
putExtra(Intent.EXTRA_STREAM, uri)
|
||||||
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
}
|
||||||
|
context.startActivity(Intent.createChooser(intent, null))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(title) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
if (!isLoading && files.isNotEmpty()) {
|
||||||
|
if (hasConfig) {
|
||||||
|
IconButton(onClick = { shareMenuExpanded = true }) {
|
||||||
|
Icon(Icons.Default.Share, contentDescription = null)
|
||||||
|
}
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = shareMenuExpanded,
|
||||||
|
onDismissRequest = { shareMenuExpanded = false },
|
||||||
|
) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(stringResource(R.string.report_share)) },
|
||||||
|
onClick = {
|
||||||
|
shareMenuExpanded = false
|
||||||
|
shareReport(includeConfig = false)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(stringResource(R.string.report_share_with_config)) },
|
||||||
|
onClick = {
|
||||||
|
shareMenuExpanded = false
|
||||||
|
shareReport(includeConfig = true)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
IconButton(onClick = { shareReport(includeConfig = false) }) {
|
||||||
|
Icon(Icons.Default.Share, contentDescription = null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IconButton(onClick = {
|
||||||
|
scope.launch {
|
||||||
|
if (report != null) {
|
||||||
|
CrashReportManager.delete(report)
|
||||||
|
}
|
||||||
|
navController.navigateUp()
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Delete,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.error,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
} else if (files.isEmpty()) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_empty),
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_section_files),
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
files.forEachIndexed { index, file ->
|
||||||
|
val shape = when {
|
||||||
|
files.size == 1 -> RoundedCornerShape(12.dp)
|
||||||
|
index == 0 -> RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp)
|
||||||
|
index == files.lastIndex -> RoundedCornerShape(
|
||||||
|
bottomStart = 12.dp,
|
||||||
|
bottomEnd = 12.dp,
|
||||||
|
)
|
||||||
|
else -> RoundedCornerShape(0.dp)
|
||||||
|
}
|
||||||
|
val icon = when (file.kind) {
|
||||||
|
CrashReportFile.Kind.METADATA -> Icons.Default.DataObject
|
||||||
|
CrashReportFile.Kind.GO_LOG -> Icons.Default.Terminal
|
||||||
|
CrashReportFile.Kind.JVM_LOG -> Icons.Outlined.BugReport
|
||||||
|
CrashReportFile.Kind.CONFIG -> Icons.Outlined.Settings
|
||||||
|
}
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
file.displayName,
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(shape)
|
||||||
|
.clickable {
|
||||||
|
if (file.kind == CrashReportFile.Kind.METADATA) {
|
||||||
|
navController.navigate("tools/crash_report/$reportId/metadata")
|
||||||
|
} else {
|
||||||
|
navController.navigate("tools/crash_report/$reportId/file/${file.kind.name}")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun CrashReportMetadataScreen(navController: NavController, reportId: String) {
|
||||||
|
val reports by CrashReportManager.reports.collectAsState()
|
||||||
|
val report = reports.find { it.id == reportId }
|
||||||
|
var entries by remember { mutableStateOf<List<Pair<String, String>>>(emptyList()) }
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
|
LaunchedEffect(report) {
|
||||||
|
if (report != null) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
entries = loadMetadataEntries(report)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.report_metadata)) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
} else if (entries.isEmpty()) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_empty),
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SelectionContainer {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
entries.forEachIndexed { index, (key, value) ->
|
||||||
|
val shape = when {
|
||||||
|
entries.size == 1 -> RoundedCornerShape(12.dp)
|
||||||
|
index == 0 -> RoundedCornerShape(
|
||||||
|
topStart = 12.dp,
|
||||||
|
topEnd = 12.dp,
|
||||||
|
)
|
||||||
|
index == entries.lastIndex -> RoundedCornerShape(
|
||||||
|
bottomStart = 12.dp,
|
||||||
|
bottomEnd = 12.dp,
|
||||||
|
)
|
||||||
|
else -> RoundedCornerShape(0.dp)
|
||||||
|
}
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
key,
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
supportingContent = {
|
||||||
|
Text(value)
|
||||||
|
},
|
||||||
|
modifier = Modifier.clip(shape),
|
||||||
|
colors = ListItemDefaults.colors(
|
||||||
|
containerColor = Color.Transparent,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadMetadataEntries(report: CrashReport): List<Pair<String, String>> {
|
||||||
|
val metadataFile = CrashReportManager.availableFiles(report)
|
||||||
|
.find { it.kind == CrashReportFile.Kind.METADATA } ?: return emptyList()
|
||||||
|
val content = metadataFile.file.readText()
|
||||||
|
val json = runCatching { JSONObject(content) }.getOrNull() ?: return emptyList()
|
||||||
|
return json.keys().asSequence()
|
||||||
|
.mapNotNull { key ->
|
||||||
|
val value = json.optString(key, "")
|
||||||
|
if (value.isNotBlank()) key to value else null
|
||||||
|
}
|
||||||
|
.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun CrashReportFileContentScreen(navController: NavController, reportId: String, fileKind: String) {
|
||||||
|
val reports by CrashReportManager.reports.collectAsState()
|
||||||
|
val report = reports.find { it.id == reportId }
|
||||||
|
var content by remember { mutableStateOf("") }
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
|
val kind = runCatching { CrashReportFile.Kind.valueOf(fileKind) }.getOrNull()
|
||||||
|
val displayName = when (kind) {
|
||||||
|
CrashReportFile.Kind.GO_LOG -> stringResource(R.string.crash_report_go_log)
|
||||||
|
CrashReportFile.Kind.JVM_LOG -> stringResource(R.string.crash_report_jvm_log)
|
||||||
|
CrashReportFile.Kind.CONFIG -> stringResource(R.string.report_configuration)
|
||||||
|
else -> fileKind
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(report, kind) {
|
||||||
|
if (report != null && kind != null) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
val file = CrashReportManager.availableFiles(report).find { it.kind == kind }
|
||||||
|
content = if (file != null) CrashReportManager.loadFileContent(file) else ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(displayName) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
} else if (content.isEmpty()) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_empty),
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SelectionContainer {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(16.dp),
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = content,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
|
import androidx.compose.material.icons.outlined.DeleteSweep
|
||||||
|
import androidx.compose.material.icons.outlined.FlashOn
|
||||||
|
import androidx.compose.material3.Badge
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.ListItem
|
||||||
|
import androidx.compose.material3.ListItemDefaults
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.sfa.BuildConfig
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.bg.CrashReportManager
|
||||||
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import java.text.DateFormat
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun CrashReportListScreen(navController: NavController) {
|
||||||
|
val reports by CrashReportManager.reports.collectAsState()
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
var menuExpanded by remember { mutableStateOf(false) }
|
||||||
|
var crashTriggerExpanded by remember { mutableStateOf(false) }
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
CrashReportManager.refresh()
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.crash_report)) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
if (reports.isNotEmpty() || BuildConfig.DEBUG) {
|
||||||
|
IconButton(onClick = { menuExpanded = true }) {
|
||||||
|
Icon(Icons.Default.MoreVert, contentDescription = null)
|
||||||
|
}
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = menuExpanded,
|
||||||
|
onDismissRequest = {
|
||||||
|
menuExpanded = false
|
||||||
|
crashTriggerExpanded = false
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text("Crash Trigger") },
|
||||||
|
leadingIcon = {
|
||||||
|
Icon(
|
||||||
|
Icons.Outlined.FlashOn,
|
||||||
|
contentDescription = null,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = { crashTriggerExpanded = !crashTriggerExpanded },
|
||||||
|
)
|
||||||
|
if (crashTriggerExpanded) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
"Go Crash",
|
||||||
|
modifier = Modifier.padding(start = 16.dp),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
menuExpanded = false
|
||||||
|
crashTriggerExpanded = false
|
||||||
|
Libbox.triggerGoPanic()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
"Native Crash",
|
||||||
|
modifier = Modifier.padding(start = 16.dp),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
menuExpanded = false
|
||||||
|
crashTriggerExpanded = false
|
||||||
|
Thread {
|
||||||
|
Thread.sleep(200)
|
||||||
|
throw RuntimeException("debug native crash")
|
||||||
|
}.start()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (reports.isNotEmpty()) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_delete_all),
|
||||||
|
color = MaterialTheme.colorScheme.error,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingIcon = {
|
||||||
|
Icon(
|
||||||
|
Icons.Outlined.DeleteSweep,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.error,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
menuExpanded = false
|
||||||
|
scope.launch {
|
||||||
|
CrashReportManager.deleteAll()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_section_reports),
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
if (reports.isEmpty()) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_empty),
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
reports.forEachIndexed { index, report ->
|
||||||
|
val shape = when {
|
||||||
|
reports.size == 1 -> RoundedCornerShape(12.dp)
|
||||||
|
index == 0 -> RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp)
|
||||||
|
index == reports.lastIndex -> RoundedCornerShape(
|
||||||
|
bottomStart = 12.dp,
|
||||||
|
bottomEnd = 12.dp,
|
||||||
|
)
|
||||||
|
else -> RoundedCornerShape(0.dp)
|
||||||
|
}
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
formatDate(report.date),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
fontWeight = if (report.isRead) FontWeight.Normal else FontWeight.SemiBold,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = if (!report.isRead) {
|
||||||
|
{
|
||||||
|
Badge(
|
||||||
|
containerColor = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(shape)
|
||||||
|
.clickable {
|
||||||
|
navController.navigate("tools/crash_report/${report.id}")
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.crash_report_description),
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun formatDate(date: Date): String = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(date)
|
||||||
@@ -0,0 +1,470 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
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.layout.size
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.RadioButton
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Switch
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.constant.Status
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun NetworkQualityScreen(
|
||||||
|
navController: NavController,
|
||||||
|
serviceStatus: Status = Status.Stopped,
|
||||||
|
viewModel: NetworkQualityViewModel = viewModel(),
|
||||||
|
) {
|
||||||
|
val state by viewModel.uiState.collectAsState()
|
||||||
|
val vpnRunning = serviceStatus == Status.Started
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
var showConfigURLDialog by remember { mutableStateOf(false) }
|
||||||
|
var showMaxRuntimeDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.network_quality)) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(vpnRunning) {
|
||||||
|
if (!vpnRunning) {
|
||||||
|
viewModel.onVpnDisconnected()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val selectedOutboundResult = navController.currentBackStackEntry
|
||||||
|
?.savedStateHandle
|
||||||
|
?.getStateFlow("selected_outbound", state.selectedOutbound)
|
||||||
|
?.collectAsState()
|
||||||
|
LaunchedEffect(selectedOutboundResult?.value) {
|
||||||
|
selectedOutboundResult?.value?.let { viewModel.selectOutbound(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
DisposableEffect(Unit) {
|
||||||
|
onDispose {
|
||||||
|
if (state.isRunning) {
|
||||||
|
viewModel.cancelTest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.showMeteredWarning) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { viewModel.dismissMeteredWarning() },
|
||||||
|
title = { Text(stringResource(R.string.network_quality_metered_title)) },
|
||||||
|
text = { Text(stringResource(R.string.network_quality_metered_message)) },
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = { viewModel.confirmMeteredStart(vpnRunning) }) {
|
||||||
|
Text(stringResource(R.string.network_quality_metered_continue))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { viewModel.dismissMeteredWarning() }) {
|
||||||
|
Text(stringResource(android.R.string.cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showConfigURLDialog) {
|
||||||
|
ConfigURLDialog(
|
||||||
|
currentURL = state.configURL,
|
||||||
|
onURLChanged = { viewModel.updateConfigURL(it) },
|
||||||
|
onDismiss = { showConfigURLDialog = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showMaxRuntimeDialog) {
|
||||||
|
MaxRuntimeDialog(
|
||||||
|
currentOption = state.maxRuntime,
|
||||||
|
onOptionSelected = {
|
||||||
|
viewModel.setMaxRuntime(it)
|
||||||
|
showMaxRuntimeDialog = false
|
||||||
|
},
|
||||||
|
onDismiss = { showMaxRuntimeDialog = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.3f),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.tool_configuration),
|
||||||
|
style = MaterialTheme.typography.titleSmall,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clip(RoundedCornerShape(12.dp))
|
||||||
|
.clickable { showConfigURLDialog = true },
|
||||||
|
color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f),
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.network_quality_url),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
state.configURL,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(20.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.network_quality_serial),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
Switch(
|
||||||
|
checked = state.serial,
|
||||||
|
onCheckedChange = { viewModel.setSerial(it) },
|
||||||
|
enabled = !state.isRunning,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.network_quality_http3),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
Switch(
|
||||||
|
checked = state.http3,
|
||||||
|
onCheckedChange = { viewModel.setHttp3(it) },
|
||||||
|
enabled = !state.isRunning,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clip(RoundedCornerShape(12.dp))
|
||||||
|
.clickable(enabled = !state.isRunning) { showMaxRuntimeDialog = true },
|
||||||
|
color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f),
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.network_quality_max_runtime),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
stringResource(state.maxRuntime.labelRes),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(20.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vpnRunning) {
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
OutboundPickerRow(
|
||||||
|
selectedOutbound = state.selectedOutbound,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
"tools/outbound_picker/${android.net.Uri.encode(state.selectedOutbound)}",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.isRunning) {
|
||||||
|
Button(
|
||||||
|
onClick = { viewModel.cancelTest() },
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = ButtonDefaults.buttonColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.error,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.network_quality_cancel))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Button(
|
||||||
|
onClick = { viewModel.requestStartTest(context, vpnRunning) },
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.network_quality_start))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.phase >= 0) {
|
||||||
|
val phaseDownload = Libbox.NetworkQualityPhaseDownload.toInt()
|
||||||
|
val phaseUpload = Libbox.NetworkQualityPhaseUpload.toInt()
|
||||||
|
val downloadActive =
|
||||||
|
(state.isRunning && !state.serial && state.phase in phaseDownload..phaseUpload) || state.phase == phaseDownload
|
||||||
|
val uploadActive =
|
||||||
|
(state.isRunning && !state.serial && state.phase in phaseDownload..phaseUpload) || state.phase == phaseUpload
|
||||||
|
val done = state.phase == Libbox.NetworkQualityPhaseDone.toInt()
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.3f),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.tool_results),
|
||||||
|
style = MaterialTheme.typography.titleSmall,
|
||||||
|
color = MaterialTheme.colorScheme.secondary,
|
||||||
|
modifier = Modifier.padding(bottom = 8.dp),
|
||||||
|
)
|
||||||
|
|
||||||
|
ResultItem(
|
||||||
|
label = stringResource(R.string.network_quality_idle_latency),
|
||||||
|
value = if (state.idleLatencyMs > 0) "${state.idleLatencyMs} ms" else null,
|
||||||
|
isActive = state.phase == Libbox.NetworkQualityPhaseIdle.toInt(),
|
||||||
|
isRunning = state.isRunning,
|
||||||
|
)
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
ResultItem(
|
||||||
|
label = stringResource(R.string.network_quality_download),
|
||||||
|
value = if (state.downloadCapacity > 0) Libbox.formatBitrate(state.downloadCapacity) else null,
|
||||||
|
isActive = downloadActive,
|
||||||
|
isRunning = state.isRunning,
|
||||||
|
accuracy = if (done) accuracyLabel(state.downloadCapacityAccuracy).first else null,
|
||||||
|
accuracyColor = if (done) accuracyLabel(state.downloadCapacityAccuracy).second else null,
|
||||||
|
)
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
ResultItem(
|
||||||
|
label = stringResource(R.string.network_quality_download_rpm),
|
||||||
|
value = if (state.downloadRPM > 0) "${state.downloadRPM}" else null,
|
||||||
|
isActive = downloadActive,
|
||||||
|
isRunning = state.isRunning,
|
||||||
|
accuracy = if (done) accuracyLabel(state.downloadRPMAccuracy).first else null,
|
||||||
|
accuracyColor = if (done) accuracyLabel(state.downloadRPMAccuracy).second else null,
|
||||||
|
)
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
ResultItem(
|
||||||
|
label = stringResource(R.string.network_quality_upload),
|
||||||
|
value = if (state.uploadCapacity > 0) Libbox.formatBitrate(state.uploadCapacity) else null,
|
||||||
|
isActive = uploadActive,
|
||||||
|
isRunning = state.isRunning,
|
||||||
|
accuracy = if (done) accuracyLabel(state.uploadCapacityAccuracy).first else null,
|
||||||
|
accuracyColor = if (done) accuracyLabel(state.uploadCapacityAccuracy).second else null,
|
||||||
|
)
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
ResultItem(
|
||||||
|
label = stringResource(R.string.network_quality_upload_rpm),
|
||||||
|
value = if (state.uploadRPM > 0) "${state.uploadRPM}" else null,
|
||||||
|
isActive = uploadActive,
|
||||||
|
isRunning = state.isRunning,
|
||||||
|
accuracy = if (done) accuracyLabel(state.uploadRPMAccuracy).first else null,
|
||||||
|
accuracyColor = if (done) accuracyLabel(state.uploadRPMAccuracy).second else null,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun accuracyLabel(value: Int): Pair<String, Color> = when (value) {
|
||||||
|
Libbox.NetworkQualityAccuracyHigh -> stringResource(R.string.network_quality_confidence_high) to Color.Green
|
||||||
|
Libbox.NetworkQualityAccuracyMedium -> stringResource(R.string.network_quality_confidence_medium) to Color.Yellow
|
||||||
|
else -> stringResource(R.string.network_quality_confidence_low) to Color.Red
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ConfigURLDialog(
|
||||||
|
currentURL: String,
|
||||||
|
onURLChanged: (String) -> Unit,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
) {
|
||||||
|
var text by remember { mutableStateOf(currentURL) }
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = { Text(stringResource(R.string.network_quality_url)) },
|
||||||
|
text = {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = text,
|
||||||
|
onValueChange = { text = it },
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = {
|
||||||
|
onURLChanged(text)
|
||||||
|
onDismiss()
|
||||||
|
}) {
|
||||||
|
Text(stringResource(android.R.string.ok))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text(stringResource(android.R.string.cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun MaxRuntimeDialog(
|
||||||
|
currentOption: MaxRuntimeOption,
|
||||||
|
onOptionSelected: (MaxRuntimeOption) -> Unit,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = { Text(stringResource(R.string.network_quality_max_runtime)) },
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
MaxRuntimeOption.entries.forEach { option ->
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.clickable { onOptionSelected(option) }
|
||||||
|
.padding(vertical = 8.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
RadioButton(
|
||||||
|
selected = currentOption == option,
|
||||||
|
onClick = { onOptionSelected(option) },
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = stringResource(option.labelRes),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
modifier = Modifier.padding(start = 8.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text(stringResource(android.R.string.cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.libbox.NetworkQualityProgress
|
||||||
|
import io.nekohasekai.libbox.NetworkQualityResult
|
||||||
|
import io.nekohasekai.libbox.NetworkQualityTestHandler
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.compose.base.BaseViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
enum class MaxRuntimeOption(val seconds: Int, val labelRes: Int) {
|
||||||
|
THIRTY(30, R.string.network_quality_max_runtime_30s),
|
||||||
|
SIXTY(60, R.string.network_quality_max_runtime_60s),
|
||||||
|
}
|
||||||
|
|
||||||
|
data class NetworkQualityState(
|
||||||
|
val phase: Int = -1,
|
||||||
|
val idleLatencyMs: Int = 0,
|
||||||
|
val downloadCapacity: Long = 0,
|
||||||
|
val uploadCapacity: Long = 0,
|
||||||
|
val downloadRPM: Int = 0,
|
||||||
|
val uploadRPM: Int = 0,
|
||||||
|
val downloadCapacityAccuracy: Int = 0,
|
||||||
|
val uploadCapacityAccuracy: Int = 0,
|
||||||
|
val downloadRPMAccuracy: Int = 0,
|
||||||
|
val uploadRPMAccuracy: Int = 0,
|
||||||
|
val isRunning: Boolean = false,
|
||||||
|
val configURL: String = Libbox.NetworkQualityDefaultConfigURL,
|
||||||
|
val serial: Boolean = false,
|
||||||
|
val http3: Boolean = false,
|
||||||
|
val maxRuntime: MaxRuntimeOption = MaxRuntimeOption.THIRTY,
|
||||||
|
val selectedOutbound: String = "",
|
||||||
|
val showMeteredWarning: Boolean = false,
|
||||||
|
)
|
||||||
|
|
||||||
|
class NetworkQualityViewModel : BaseViewModel<NetworkQualityState, Nothing>() {
|
||||||
|
private var standaloneTest: io.nekohasekai.libbox.NetworkQualityTest? = null
|
||||||
|
private var grpcJob: Job? = null
|
||||||
|
|
||||||
|
override fun createInitialState() = NetworkQualityState()
|
||||||
|
|
||||||
|
fun updateConfigURL(url: String) {
|
||||||
|
updateState { copy(configURL = url) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun selectOutbound(tag: String) {
|
||||||
|
updateState { copy(selectedOutbound = tag) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setSerial(value: Boolean) {
|
||||||
|
updateState { copy(serial = value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setHttp3(value: Boolean) {
|
||||||
|
updateState { copy(http3 = value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setMaxRuntime(option: MaxRuntimeOption) {
|
||||||
|
updateState { copy(maxRuntime = option) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onVpnDisconnected() {
|
||||||
|
cancelTest()
|
||||||
|
updateState { copy(selectedOutbound = "") }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun requestStartTest(context: Context, vpnRunning: Boolean) {
|
||||||
|
val connectivityManager =
|
||||||
|
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
if (connectivityManager.isActiveNetworkMetered) {
|
||||||
|
updateState { copy(showMeteredWarning = true) }
|
||||||
|
} else {
|
||||||
|
startTest(vpnRunning)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun dismissMeteredWarning() {
|
||||||
|
updateState { copy(showMeteredWarning = false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun confirmMeteredStart(vpnRunning: Boolean) {
|
||||||
|
updateState { copy(showMeteredWarning = false) }
|
||||||
|
startTest(vpnRunning)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startTest(vpnRunning: Boolean) {
|
||||||
|
updateState {
|
||||||
|
copy(
|
||||||
|
phase = -1,
|
||||||
|
idleLatencyMs = 0,
|
||||||
|
downloadCapacity = 0,
|
||||||
|
uploadCapacity = 0,
|
||||||
|
downloadRPM = 0,
|
||||||
|
uploadRPM = 0,
|
||||||
|
downloadCapacityAccuracy = 0,
|
||||||
|
uploadCapacityAccuracy = 0,
|
||||||
|
downloadRPMAccuracy = 0,
|
||||||
|
uploadRPMAccuracy = 0,
|
||||||
|
isRunning = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val configURL = currentState.configURL
|
||||||
|
val outboundTag = currentState.selectedOutbound
|
||||||
|
val serial = currentState.serial
|
||||||
|
val http3 = currentState.http3
|
||||||
|
val maxRuntimeSeconds = currentState.maxRuntime.seconds
|
||||||
|
val handler = createHandler()
|
||||||
|
|
||||||
|
if (vpnRunning) {
|
||||||
|
grpcJob = viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
Libbox.newStandaloneCommandClient()
|
||||||
|
.startNetworkQualityTest(
|
||||||
|
configURL,
|
||||||
|
outboundTag,
|
||||||
|
serial,
|
||||||
|
maxRuntimeSeconds,
|
||||||
|
http3,
|
||||||
|
handler,
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (!currentState.isRunning) return@withContext
|
||||||
|
updateState { copy(isRunning = false) }
|
||||||
|
grpcJob = null
|
||||||
|
sendError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val test = Libbox.newNetworkQualityTest()
|
||||||
|
standaloneTest = test
|
||||||
|
launch {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
test.start(configURL, serial, maxRuntimeSeconds, http3, handler)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cancelTest() {
|
||||||
|
grpcJob?.cancel()
|
||||||
|
grpcJob = null
|
||||||
|
standaloneTest?.cancel()
|
||||||
|
standaloneTest = null
|
||||||
|
updateState { copy(isRunning = false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createHandler(): NetworkQualityTestHandler {
|
||||||
|
return object : NetworkQualityTestHandler {
|
||||||
|
override fun onProgress(progress: NetworkQualityProgress?) {
|
||||||
|
progress ?: return
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (!currentState.isRunning) return@launch
|
||||||
|
updateState {
|
||||||
|
copy(
|
||||||
|
phase = progress.phase.toInt(),
|
||||||
|
idleLatencyMs = progress.idleLatencyMs.toInt(),
|
||||||
|
downloadCapacity = progress.downloadCapacity,
|
||||||
|
uploadCapacity = progress.uploadCapacity,
|
||||||
|
downloadRPM = progress.downloadRPM.toInt(),
|
||||||
|
uploadRPM = progress.uploadRPM.toInt(),
|
||||||
|
downloadCapacityAccuracy = progress.downloadCapacityAccuracy.toInt(),
|
||||||
|
uploadCapacityAccuracy = progress.uploadCapacityAccuracy.toInt(),
|
||||||
|
downloadRPMAccuracy = progress.downloadRPMAccuracy.toInt(),
|
||||||
|
uploadRPMAccuracy = progress.uploadRPMAccuracy.toInt(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResult(result: NetworkQualityResult?) {
|
||||||
|
result ?: return
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (!currentState.isRunning) return@launch
|
||||||
|
updateState {
|
||||||
|
copy(
|
||||||
|
phase = Libbox.NetworkQualityPhaseDone.toInt(),
|
||||||
|
idleLatencyMs = result.idleLatencyMs.toInt(),
|
||||||
|
downloadCapacity = result.downloadCapacity,
|
||||||
|
uploadCapacity = result.uploadCapacity,
|
||||||
|
downloadRPM = result.downloadRPM.toInt(),
|
||||||
|
uploadRPM = result.uploadRPM.toInt(),
|
||||||
|
downloadCapacityAccuracy = result.downloadCapacityAccuracy.toInt(),
|
||||||
|
uploadCapacityAccuracy = result.uploadCapacityAccuracy.toInt(),
|
||||||
|
downloadRPMAccuracy = result.downloadRPMAccuracy.toInt(),
|
||||||
|
uploadRPMAccuracy = result.uploadRPMAccuracy.toInt(),
|
||||||
|
isRunning = false,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
standaloneTest = null
|
||||||
|
grpcJob = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(message: String?) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (!currentState.isRunning) return@launch
|
||||||
|
updateState { copy(isRunning = false) }
|
||||||
|
standaloneTest = null
|
||||||
|
grpcJob = null
|
||||||
|
if (message != null) {
|
||||||
|
sendErrorMessage(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,451 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.DataObject
|
||||||
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material.icons.filled.Share
|
||||||
|
import androidx.compose.material.icons.filled.Terminal
|
||||||
|
import androidx.compose.material.icons.outlined.Settings
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.ListItem
|
||||||
|
import androidx.compose.material3.ListItemDefaults
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.bg.OOMReport
|
||||||
|
import io.nekohasekai.sfa.bg.OOMReportFile
|
||||||
|
import io.nekohasekai.sfa.bg.OOMReportManager
|
||||||
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.text.DateFormat
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun OOMReportDetailScreen(navController: NavController, reportId: String) {
|
||||||
|
val reports by OOMReportManager.reports.collectAsState()
|
||||||
|
val report = reports.find { it.id == reportId }
|
||||||
|
var files by remember { mutableStateOf<List<OOMReportFile>>(emptyList()) }
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
var shareMenuExpanded by remember { mutableStateOf(false) }
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
LaunchedEffect(report) {
|
||||||
|
if (report != null) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
files = OOMReportManager.availableFiles(report)
|
||||||
|
}
|
||||||
|
OOMReportManager.markAsRead(report)
|
||||||
|
}
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
val title = if (report != null) {
|
||||||
|
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(report.date)
|
||||||
|
} else {
|
||||||
|
reportId
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasConfig = report != null && OOMReportManager.hasConfigFile(report)
|
||||||
|
|
||||||
|
fun shareReport(includeConfig: Boolean) {
|
||||||
|
val currentReport = report ?: return
|
||||||
|
scope.launch {
|
||||||
|
val zipFile = OOMReportManager.createZipArchive(currentReport, includeConfig)
|
||||||
|
val uri = FileProvider.getUriForFile(context, "${context.packageName}.cache", zipFile)
|
||||||
|
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||||
|
type = "application/zip"
|
||||||
|
putExtra(Intent.EXTRA_STREAM, uri)
|
||||||
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
}
|
||||||
|
context.startActivity(Intent.createChooser(intent, null))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(title) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
if (!isLoading && files.isNotEmpty()) {
|
||||||
|
if (hasConfig) {
|
||||||
|
IconButton(onClick = { shareMenuExpanded = true }) {
|
||||||
|
Icon(Icons.Default.Share, contentDescription = null)
|
||||||
|
}
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = shareMenuExpanded,
|
||||||
|
onDismissRequest = { shareMenuExpanded = false },
|
||||||
|
) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(stringResource(R.string.report_share)) },
|
||||||
|
onClick = {
|
||||||
|
shareMenuExpanded = false
|
||||||
|
shareReport(includeConfig = false)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(stringResource(R.string.report_share_with_config)) },
|
||||||
|
onClick = {
|
||||||
|
shareMenuExpanded = false
|
||||||
|
shareReport(includeConfig = true)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
IconButton(onClick = { shareReport(includeConfig = false) }) {
|
||||||
|
Icon(Icons.Default.Share, contentDescription = null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IconButton(onClick = {
|
||||||
|
scope.launch {
|
||||||
|
if (report != null) {
|
||||||
|
OOMReportManager.delete(report)
|
||||||
|
}
|
||||||
|
navController.navigateUp()
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Delete,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.error,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
} else if (files.isEmpty()) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_empty),
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_section_files),
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
files.forEachIndexed { index, file ->
|
||||||
|
val shape = when {
|
||||||
|
files.size == 1 -> RoundedCornerShape(12.dp)
|
||||||
|
index == 0 -> RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp)
|
||||||
|
index == files.lastIndex -> RoundedCornerShape(
|
||||||
|
bottomStart = 12.dp,
|
||||||
|
bottomEnd = 12.dp,
|
||||||
|
)
|
||||||
|
else -> RoundedCornerShape(0.dp)
|
||||||
|
}
|
||||||
|
val icon = when (file.kind) {
|
||||||
|
OOMReportFile.Kind.METADATA -> Icons.Default.DataObject
|
||||||
|
OOMReportFile.Kind.CONFIG -> Icons.Outlined.Settings
|
||||||
|
OOMReportFile.Kind.PROFILE -> Icons.Default.Terminal
|
||||||
|
}
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
file.displayName,
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(shape)
|
||||||
|
.then(
|
||||||
|
if (file.kind != OOMReportFile.Kind.PROFILE) {
|
||||||
|
Modifier.clickable {
|
||||||
|
if (file.kind == OOMReportFile.Kind.METADATA) {
|
||||||
|
navController.navigate("tools/oom_report/$reportId/metadata")
|
||||||
|
} else {
|
||||||
|
navController.navigate("tools/oom_report/$reportId/file/${file.kind.name}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Modifier
|
||||||
|
},
|
||||||
|
),
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun OOMReportMetadataScreen(navController: NavController, reportId: String) {
|
||||||
|
val reports by OOMReportManager.reports.collectAsState()
|
||||||
|
val report = reports.find { it.id == reportId }
|
||||||
|
var entries by remember { mutableStateOf<List<Pair<String, String>>>(emptyList()) }
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
|
LaunchedEffect(report) {
|
||||||
|
if (report != null) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
entries = loadOOMMetadataEntries(report)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.report_metadata)) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
} else if (entries.isEmpty()) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_empty),
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SelectionContainer {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
entries.forEachIndexed { index, (key, value) ->
|
||||||
|
val shape = when {
|
||||||
|
entries.size == 1 -> RoundedCornerShape(12.dp)
|
||||||
|
index == 0 -> RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp)
|
||||||
|
index == entries.lastIndex -> RoundedCornerShape(
|
||||||
|
bottomStart = 12.dp,
|
||||||
|
bottomEnd = 12.dp,
|
||||||
|
)
|
||||||
|
else -> RoundedCornerShape(0.dp)
|
||||||
|
}
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(key, style = MaterialTheme.typography.bodyLarge)
|
||||||
|
},
|
||||||
|
supportingContent = { Text(value) },
|
||||||
|
modifier = Modifier.clip(shape),
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadOOMMetadataEntries(report: OOMReport): List<Pair<String, String>> {
|
||||||
|
val metadataFile = OOMReportManager.availableFiles(report)
|
||||||
|
.find { it.kind == OOMReportFile.Kind.METADATA } ?: return emptyList()
|
||||||
|
val content = metadataFile.file.readText()
|
||||||
|
val json = runCatching { JSONObject(content) }.getOrNull() ?: return emptyList()
|
||||||
|
return json.keys().asSequence()
|
||||||
|
.mapNotNull { key ->
|
||||||
|
val value = json.optString(key, "")
|
||||||
|
if (value.isNotBlank()) key to value else null
|
||||||
|
}
|
||||||
|
.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun OOMReportFileContentScreen(navController: NavController, reportId: String, fileKind: String) {
|
||||||
|
val reports by OOMReportManager.reports.collectAsState()
|
||||||
|
val report = reports.find { it.id == reportId }
|
||||||
|
var content by remember { mutableStateOf("") }
|
||||||
|
var displayName by remember { mutableStateOf(fileKind) }
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
|
val kind = runCatching { OOMReportFile.Kind.valueOf(fileKind) }.getOrNull()
|
||||||
|
|
||||||
|
LaunchedEffect(report, kind) {
|
||||||
|
if (report != null && kind != null) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
val file = OOMReportManager.availableFiles(report).find { it.kind == kind }
|
||||||
|
if (file != null) {
|
||||||
|
displayName = file.displayName
|
||||||
|
content = OOMReportManager.loadFileContent(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(displayName) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
} else if (content.isEmpty()) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_empty),
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SelectionContainer {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(16.dp),
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = content,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,416 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
|
import androidx.compose.material.icons.outlined.DeleteSweep
|
||||||
|
import androidx.compose.material.icons.outlined.Memory
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Badge
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.DropdownMenu
|
||||||
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.ListItem
|
||||||
|
import androidx.compose.material3.ListItemDefaults
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.RadioButton
|
||||||
|
import androidx.compose.material3.Switch
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.sfa.Application
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.bg.OOMReportManager
|
||||||
|
import io.nekohasekai.sfa.compose.base.UiEvent
|
||||||
|
import io.nekohasekai.sfa.compose.base.rememberApplyServiceChangeNotifier
|
||||||
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.constant.Status
|
||||||
|
import io.nekohasekai.sfa.database.Settings
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.text.DateFormat
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
private val memoryLimitOptions = listOf(50, 100, 200, 300, 500, 750, 1024)
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun OOMReportListScreen(
|
||||||
|
navController: NavController,
|
||||||
|
serviceStatus: Status = Status.Stopped,
|
||||||
|
) {
|
||||||
|
val reports by OOMReportManager.reports.collectAsState()
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
var menuExpanded by remember { mutableStateOf(false) }
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
var errorMessage by remember { mutableStateOf<String?>(null) }
|
||||||
|
val notifyApplyChange = rememberApplyServiceChangeNotifier(serviceStatus)
|
||||||
|
|
||||||
|
var oomKillerEnabled by remember { mutableStateOf(Settings.oomKillerEnabled) }
|
||||||
|
var oomMemoryLimitMB by remember { mutableIntStateOf(Settings.oomMemoryLimitMB) }
|
||||||
|
var oomKillerKillConnections by remember { mutableStateOf(!Settings.oomKillerDisabled) }
|
||||||
|
var showMemoryLimitDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
OOMReportManager.refresh()
|
||||||
|
val storedLimit = Settings.oomMemoryLimitMB
|
||||||
|
if (!memoryLimitOptions.contains(storedLimit)) {
|
||||||
|
oomMemoryLimitMB = memoryLimitOptions.first()
|
||||||
|
Settings.oomMemoryLimitMB = oomMemoryLimitMB
|
||||||
|
}
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.oom_report)) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
IconButton(onClick = { menuExpanded = true }) {
|
||||||
|
Icon(Icons.Default.MoreVert, contentDescription = null)
|
||||||
|
}
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = menuExpanded,
|
||||||
|
onDismissRequest = { menuExpanded = false },
|
||||||
|
) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text(stringResource(R.string.oom_report_fetch)) },
|
||||||
|
leadingIcon = {
|
||||||
|
Icon(Icons.Outlined.Memory, contentDescription = null)
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
menuExpanded = false
|
||||||
|
if (serviceStatus != Status.Started) {
|
||||||
|
errorMessage =
|
||||||
|
Application.application.getString(R.string.service_not_started)
|
||||||
|
} else {
|
||||||
|
scope.launch {
|
||||||
|
val failure =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
runCatching {
|
||||||
|
Libbox.newStandaloneCommandClient().triggerOOMReport()
|
||||||
|
}.exceptionOrNull()
|
||||||
|
}
|
||||||
|
if (failure != null) {
|
||||||
|
errorMessage = failure.message ?: failure.toString()
|
||||||
|
} else {
|
||||||
|
delay(1000)
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
OOMReportManager.refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if (reports.isNotEmpty()) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_delete_all),
|
||||||
|
color = MaterialTheme.colorScheme.error,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingIcon = {
|
||||||
|
Icon(
|
||||||
|
Icons.Outlined.DeleteSweep,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.error,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
menuExpanded = false
|
||||||
|
scope.launch { OOMReportManager.deleteAll() }
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
|
if (isLoading) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
// Reports section
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_section_reports),
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
if (reports.isEmpty()) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.report_empty),
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
reports.forEachIndexed { index, report ->
|
||||||
|
val shape = when {
|
||||||
|
reports.size == 1 -> RoundedCornerShape(12.dp)
|
||||||
|
index == 0 -> RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp)
|
||||||
|
index == reports.lastIndex -> RoundedCornerShape(
|
||||||
|
bottomStart = 12.dp,
|
||||||
|
bottomEnd = 12.dp,
|
||||||
|
)
|
||||||
|
else -> RoundedCornerShape(0.dp)
|
||||||
|
}
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
formatDate(report.date),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
fontWeight = if (report.isRead) FontWeight.Normal else FontWeight.SemiBold,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = if (!report.isRead) {
|
||||||
|
{
|
||||||
|
Badge(
|
||||||
|
containerColor = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(shape)
|
||||||
|
.clickable {
|
||||||
|
navController.navigate("tools/oom_report/${report.id}")
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.oom_report_description),
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Settings section
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.title_settings),
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(start = 32.dp, end = 32.dp, top = 16.dp, bottom = 8.dp),
|
||||||
|
)
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.oom_report_enable_memory_limit),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
supportingContent = {
|
||||||
|
Text(stringResource(R.string.oom_report_enable_memory_limit_description))
|
||||||
|
},
|
||||||
|
trailingContent = {
|
||||||
|
Switch(
|
||||||
|
checked = oomKillerEnabled,
|
||||||
|
onCheckedChange = { checked ->
|
||||||
|
oomKillerEnabled = checked
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
Settings.oomKillerEnabled = checked
|
||||||
|
Application.application.reloadSetupOptions()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Restart)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
AnimatedVisibility(visible = oomKillerEnabled) {
|
||||||
|
Column {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.oom_report_memory_limit),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
supportingContent = {
|
||||||
|
Text(Libbox.formatMemoryBytes(oomMemoryLimitMB.toLong() * 1024L * 1024L))
|
||||||
|
},
|
||||||
|
modifier = Modifier.clickable { showMemoryLimitDialog = true },
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.oom_report_kill_connections),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
supportingContent = {
|
||||||
|
Text(stringResource(R.string.oom_report_kill_connections_description))
|
||||||
|
},
|
||||||
|
trailingContent = {
|
||||||
|
Switch(
|
||||||
|
checked = oomKillerKillConnections,
|
||||||
|
onCheckedChange = { checked ->
|
||||||
|
oomKillerKillConnections = checked
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
Settings.oomKillerDisabled = !checked
|
||||||
|
Application.application.reloadSetupOptions()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Restart)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
errorMessage?.let { message ->
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { errorMessage = null },
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = { errorMessage = null }) {
|
||||||
|
Text(stringResource(android.R.string.ok))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
text = { Text(message) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showMemoryLimitDialog) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { showMemoryLimitDialog = false },
|
||||||
|
title = { Text(stringResource(R.string.oom_report_memory_limit)) },
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
memoryLimitOptions.forEach { value ->
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(Libbox.formatMemoryBytes(value.toLong() * 1024L * 1024L))
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
RadioButton(
|
||||||
|
selected = value == oomMemoryLimitMB,
|
||||||
|
onClick = null,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.clickable {
|
||||||
|
oomMemoryLimitMB = value
|
||||||
|
showMemoryLimitDialog = false
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
Settings.oomMemoryLimitMB = value
|
||||||
|
Application.application.reloadSetupOptions()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
notifyApplyChange(UiEvent.ApplyServiceChange.Mode.Restart)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun formatDate(date: Date): String = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(date)
|
||||||
@@ -0,0 +1,280 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
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.layout.size
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||||
|
import androidx.compose.material.icons.filled.Check
|
||||||
|
import androidx.compose.material.icons.filled.Search
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.compose.model.GroupItem
|
||||||
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.utils.CommandClient
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
|
class OutboundPickerViewModel :
|
||||||
|
ViewModel(),
|
||||||
|
CommandClient.Handler {
|
||||||
|
private val _outbounds = MutableStateFlow<List<GroupItem>>(emptyList())
|
||||||
|
val outbounds: StateFlow<List<GroupItem>> = _outbounds.asStateFlow()
|
||||||
|
|
||||||
|
private var commandClient: CommandClient? = null
|
||||||
|
|
||||||
|
fun connect() {
|
||||||
|
disconnect()
|
||||||
|
commandClient = CommandClient(
|
||||||
|
viewModelScope,
|
||||||
|
CommandClient.ConnectionType.Outbounds,
|
||||||
|
this,
|
||||||
|
)
|
||||||
|
commandClient?.connect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun disconnect() {
|
||||||
|
commandClient?.disconnect()
|
||||||
|
commandClient = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateOutbounds(outbounds: List<io.nekohasekai.libbox.OutboundGroupItem>) {
|
||||||
|
_outbounds.value = outbounds.map { GroupItem(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
disconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun OutboundPickerScreen(
|
||||||
|
navController: NavController,
|
||||||
|
selectedOutbound: String,
|
||||||
|
) {
|
||||||
|
val viewModel: OutboundPickerViewModel = viewModel()
|
||||||
|
val outbounds by viewModel.outbounds.collectAsState()
|
||||||
|
var searchText by rememberSaveable { mutableStateOf("") }
|
||||||
|
|
||||||
|
DisposableEffect(Unit) {
|
||||||
|
viewModel.connect()
|
||||||
|
onDispose {
|
||||||
|
viewModel.disconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val filteredOutbounds = if (searchText.isEmpty()) {
|
||||||
|
outbounds
|
||||||
|
} else {
|
||||||
|
outbounds.filter { it.tag.contains(searchText, ignoreCase = true) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun selectOutbound(tag: String) {
|
||||||
|
navController.previousBackStackEntry?.savedStateHandle?.set("selected_outbound", tag)
|
||||||
|
navController.navigateUp()
|
||||||
|
}
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.tool_outbound)) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
|
contentDescription = null,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize(),
|
||||||
|
) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = searchText,
|
||||||
|
onValueChange = { searchText = it },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||||
|
placeholder = { Text(stringResource(android.R.string.search_go)) },
|
||||||
|
leadingIcon = {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Search,
|
||||||
|
contentDescription = null,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
singleLine = true,
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
)
|
||||||
|
|
||||||
|
LazyColumn(modifier = Modifier.fillMaxSize()) {
|
||||||
|
item {
|
||||||
|
OutboundPickerItem(
|
||||||
|
tag = stringResource(R.string.tool_default_outbound),
|
||||||
|
isSelected = selectedOutbound.isEmpty(),
|
||||||
|
onClick = { selectOutbound("") },
|
||||||
|
)
|
||||||
|
HorizontalDivider(
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp),
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
items(filteredOutbounds, key = { it.tag }) { item ->
|
||||||
|
OutboundPickerItem(
|
||||||
|
tag = item.tag,
|
||||||
|
type = Libbox.proxyDisplayType(item.type),
|
||||||
|
urlTestDelay = item.urlTestDelay,
|
||||||
|
isSelected = selectedOutbound == item.tag,
|
||||||
|
onClick = { selectOutbound(item.tag) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun OutboundPickerItem(
|
||||||
|
tag: String,
|
||||||
|
type: String? = null,
|
||||||
|
urlTestDelay: Int = 0,
|
||||||
|
isSelected: Boolean,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable(onClick = onClick)
|
||||||
|
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
|
Text(
|
||||||
|
text = tag,
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
if (type != null) {
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = type,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
if (urlTestDelay > 0) {
|
||||||
|
Text(
|
||||||
|
text = "${urlTestDelay}ms",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = outboundDelayColor(urlTestDelay),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isSelected) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Check,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun OutboundPickerRow(
|
||||||
|
selectedOutbound: String,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
) {
|
||||||
|
val displayText = if (selectedOutbound.isEmpty()) {
|
||||||
|
stringResource(R.string.tool_default_outbound)
|
||||||
|
} else {
|
||||||
|
selectedOutbound
|
||||||
|
}
|
||||||
|
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clip(RoundedCornerShape(12.dp))
|
||||||
|
.clickable(onClick = onClick),
|
||||||
|
color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f),
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.tool_outbound),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
displayText,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(20.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun outboundDelayColor(delay: Int): Color {
|
||||||
|
val colorScheme = MaterialTheme.colorScheme
|
||||||
|
return when {
|
||||||
|
delay < 100 -> colorScheme.tertiary
|
||||||
|
delay < 300 -> colorScheme.primary
|
||||||
|
delay < 500 -> colorScheme.secondary
|
||||||
|
else -> colorScheme.error
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ResultItem(
|
||||||
|
label: String,
|
||||||
|
value: String?,
|
||||||
|
isActive: Boolean,
|
||||||
|
isRunning: Boolean,
|
||||||
|
accuracy: String? = null,
|
||||||
|
valueColor: Color? = null,
|
||||||
|
accuracyColor: Color? = null,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Text(label, style = MaterialTheme.typography.bodyLarge)
|
||||||
|
when {
|
||||||
|
value != null -> {
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
if (isRunning && isActive) {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(16.dp),
|
||||||
|
strokeWidth = 2.dp,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
value,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
color = valueColor ?: Color.Unspecified,
|
||||||
|
)
|
||||||
|
if (accuracy != null) {
|
||||||
|
Text(
|
||||||
|
accuracy,
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = accuracyColor ?: MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
isRunning && isActive -> {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(16.dp),
|
||||||
|
strokeWidth = 2.dp,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Text(
|
||||||
|
"-",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
fontFamily = FontFamily.Monospace,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,317 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
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.layout.size
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.constant.Status
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun STUNTestScreen(
|
||||||
|
navController: NavController,
|
||||||
|
serviceStatus: Status = Status.Stopped,
|
||||||
|
viewModel: STUNTestViewModel = viewModel(),
|
||||||
|
) {
|
||||||
|
val state by viewModel.uiState.collectAsState()
|
||||||
|
val vpnRunning = serviceStatus == Status.Started
|
||||||
|
|
||||||
|
var showServerDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.stun_test)) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(vpnRunning) {
|
||||||
|
if (!vpnRunning) {
|
||||||
|
viewModel.onVpnDisconnected()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val selectedOutboundResult = navController.currentBackStackEntry
|
||||||
|
?.savedStateHandle
|
||||||
|
?.getStateFlow("selected_outbound", state.selectedOutbound)
|
||||||
|
?.collectAsState()
|
||||||
|
LaunchedEffect(selectedOutboundResult?.value) {
|
||||||
|
selectedOutboundResult?.value?.let { viewModel.selectOutbound(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
DisposableEffect(Unit) {
|
||||||
|
onDispose {
|
||||||
|
if (state.isRunning) {
|
||||||
|
viewModel.cancelTest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showServerDialog) {
|
||||||
|
ServerEditDialog(
|
||||||
|
currentServer = state.server,
|
||||||
|
onServerChanged = { viewModel.updateServer(it) },
|
||||||
|
onDismiss = { showServerDialog = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.3f),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.tool_configuration),
|
||||||
|
style = MaterialTheme.typography.titleSmall,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clip(RoundedCornerShape(12.dp))
|
||||||
|
.clickable { showServerDialog = true },
|
||||||
|
color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f),
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.stun_server),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
state.server,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(20.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vpnRunning) {
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
OutboundPickerRow(
|
||||||
|
selectedOutbound = state.selectedOutbound,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
"tools/outbound_picker/${android.net.Uri.encode(state.selectedOutbound)}",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.isRunning) {
|
||||||
|
Button(
|
||||||
|
onClick = { viewModel.cancelTest() },
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = ButtonDefaults.buttonColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.error,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.stun_cancel))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Button(
|
||||||
|
onClick = { viewModel.startTest(vpnRunning) },
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.stun_start))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.phase >= 0) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.3f),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.tool_results),
|
||||||
|
style = MaterialTheme.typography.titleSmall,
|
||||||
|
color = MaterialTheme.colorScheme.secondary,
|
||||||
|
modifier = Modifier.padding(bottom = 8.dp),
|
||||||
|
)
|
||||||
|
|
||||||
|
ResultItem(
|
||||||
|
label = stringResource(R.string.stun_external_address),
|
||||||
|
value = state.externalAddr.ifEmpty { null },
|
||||||
|
isActive = state.phase == Libbox.STUNPhaseBinding.toInt(),
|
||||||
|
isRunning = state.isRunning,
|
||||||
|
)
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
ResultItem(
|
||||||
|
label = stringResource(R.string.stun_latency),
|
||||||
|
value = if (state.latencyMs > 0) "${state.latencyMs} ms" else null,
|
||||||
|
isActive = state.phase == Libbox.STUNPhaseBinding.toInt(),
|
||||||
|
isRunning = state.isRunning,
|
||||||
|
)
|
||||||
|
if (state.phase == Libbox.STUNPhaseDone.toInt() && !state.natTypeSupported) {
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
ResultItem(
|
||||||
|
label = stringResource(R.string.stun_nat_type_detection),
|
||||||
|
value = stringResource(R.string.stun_nat_not_supported),
|
||||||
|
isActive = false,
|
||||||
|
isRunning = false,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
ResultItem(
|
||||||
|
label = stringResource(R.string.stun_nat_mapping),
|
||||||
|
value = if (state.natMapping > 0) Libbox.formatNATMapping(state.natMapping) else null,
|
||||||
|
isActive = state.phase == Libbox.STUNPhaseNATMapping.toInt(),
|
||||||
|
isRunning = state.isRunning,
|
||||||
|
valueColor = if (state.natMapping > 0) natMappingColor(state.natMapping) else null,
|
||||||
|
)
|
||||||
|
HorizontalDivider(
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
ResultItem(
|
||||||
|
label = stringResource(R.string.stun_nat_filtering),
|
||||||
|
value = if (state.natFiltering > 0) Libbox.formatNATFiltering(state.natFiltering) else null,
|
||||||
|
isActive = state.phase == Libbox.STUNPhaseNATFiltering.toInt(),
|
||||||
|
isRunning = state.isRunning,
|
||||||
|
valueColor = if (state.natFiltering > 0) natFilteringColor(state.natFiltering) else null,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun natMappingColor(value: Int): Color = when (value) {
|
||||||
|
Libbox.NATMappingEndpointIndependent.toInt() -> Color.Green
|
||||||
|
Libbox.NATMappingAddressDependent.toInt() -> Color.Yellow
|
||||||
|
Libbox.NATMappingAddressAndPortDependent.toInt() -> Color.Red
|
||||||
|
else -> Color.Unspecified
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun natFilteringColor(value: Int): Color = when (value) {
|
||||||
|
Libbox.NATFilteringEndpointIndependent.toInt() -> Color.Green
|
||||||
|
Libbox.NATFilteringAddressDependent.toInt() -> Color.Yellow
|
||||||
|
Libbox.NATFilteringAddressAndPortDependent.toInt() -> Color.Red
|
||||||
|
else -> Color.Unspecified
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ServerEditDialog(
|
||||||
|
currentServer: String,
|
||||||
|
onServerChanged: (String) -> Unit,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
) {
|
||||||
|
var text by remember { mutableStateOf(currentServer) }
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = { Text(stringResource(R.string.stun_server)) },
|
||||||
|
text = {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = text,
|
||||||
|
onValueChange = { text = it },
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = {
|
||||||
|
onServerChanged(text)
|
||||||
|
onDismiss()
|
||||||
|
}) {
|
||||||
|
Text(stringResource(android.R.string.ok))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text(stringResource(android.R.string.cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.libbox.STUNTestHandler
|
||||||
|
import io.nekohasekai.libbox.STUNTestProgress
|
||||||
|
import io.nekohasekai.libbox.STUNTestResult
|
||||||
|
import io.nekohasekai.sfa.compose.base.BaseViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
data class STUNTestState(
|
||||||
|
val phase: Int = -1,
|
||||||
|
val externalAddr: String = "",
|
||||||
|
val latencyMs: Int = 0,
|
||||||
|
val natMapping: Int = 0,
|
||||||
|
val natFiltering: Int = 0,
|
||||||
|
val natTypeSupported: Boolean = false,
|
||||||
|
val isRunning: Boolean = false,
|
||||||
|
val server: String = Libbox.STUNDefaultServer,
|
||||||
|
val selectedOutbound: String = "",
|
||||||
|
)
|
||||||
|
|
||||||
|
class STUNTestViewModel : BaseViewModel<STUNTestState, Nothing>() {
|
||||||
|
private var standaloneTest: io.nekohasekai.libbox.STUNTest? = null
|
||||||
|
private var grpcJob: Job? = null
|
||||||
|
|
||||||
|
override fun createInitialState() = STUNTestState()
|
||||||
|
|
||||||
|
fun updateServer(server: String) {
|
||||||
|
updateState { copy(server = server) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun selectOutbound(tag: String) {
|
||||||
|
updateState { copy(selectedOutbound = tag) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onVpnDisconnected() {
|
||||||
|
cancelTest()
|
||||||
|
updateState { copy(selectedOutbound = "") }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startTest(vpnRunning: Boolean) {
|
||||||
|
updateState {
|
||||||
|
copy(
|
||||||
|
phase = -1,
|
||||||
|
externalAddr = "",
|
||||||
|
latencyMs = 0,
|
||||||
|
natMapping = 0,
|
||||||
|
natFiltering = 0,
|
||||||
|
natTypeSupported = false,
|
||||||
|
isRunning = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val server = currentState.server
|
||||||
|
val outboundTag = currentState.selectedOutbound
|
||||||
|
val handler = createHandler()
|
||||||
|
|
||||||
|
if (vpnRunning) {
|
||||||
|
grpcJob = viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
Libbox.newStandaloneCommandClient()
|
||||||
|
.startSTUNTest(server, outboundTag, handler)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (!currentState.isRunning) return@withContext
|
||||||
|
updateState { copy(isRunning = false) }
|
||||||
|
grpcJob = null
|
||||||
|
sendError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val test = Libbox.newSTUNTest()
|
||||||
|
standaloneTest = test
|
||||||
|
launch {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
test.start(server, handler)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cancelTest() {
|
||||||
|
grpcJob?.cancel()
|
||||||
|
grpcJob = null
|
||||||
|
standaloneTest?.cancel()
|
||||||
|
standaloneTest = null
|
||||||
|
updateState { copy(isRunning = false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createHandler(): STUNTestHandler {
|
||||||
|
return object : STUNTestHandler {
|
||||||
|
override fun onProgress(progress: STUNTestProgress?) {
|
||||||
|
progress ?: return
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (!currentState.isRunning) return@launch
|
||||||
|
updateState {
|
||||||
|
copy(
|
||||||
|
phase = progress.phase.toInt(),
|
||||||
|
externalAddr = progress.externalAddr,
|
||||||
|
latencyMs = progress.latencyMs.toInt(),
|
||||||
|
natMapping = progress.natMapping.toInt(),
|
||||||
|
natFiltering = progress.natFiltering.toInt(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResult(result: STUNTestResult?) {
|
||||||
|
result ?: return
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (!currentState.isRunning) return@launch
|
||||||
|
updateState {
|
||||||
|
copy(
|
||||||
|
phase = Libbox.STUNPhaseDone.toInt(),
|
||||||
|
isRunning = false,
|
||||||
|
externalAddr = result.externalAddr,
|
||||||
|
latencyMs = result.latencyMs.toInt(),
|
||||||
|
natMapping = result.natMapping.toInt(),
|
||||||
|
natFiltering = result.natFiltering.toInt(),
|
||||||
|
natTypeSupported = result.natTypeSupported,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
standaloneTest = null
|
||||||
|
grpcJob = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(message: String?) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (!currentState.isRunning) return@launch
|
||||||
|
updateState { copy(isRunning = false) }
|
||||||
|
standaloneTest = null
|
||||||
|
grpcJob = null
|
||||||
|
if (message != null) {
|
||||||
|
sendErrorMessage(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,362 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.automirrored.outlined.OpenInNew
|
||||||
|
import androidx.compose.material.icons.filled.QrCode2
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.ListItem
|
||||||
|
import androidx.compose.material3.ListItemDefaults
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.compose.component.qr.QRCodeDialog
|
||||||
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.compose.util.QRCodeGenerator
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun TailscaleEndpointScreen(
|
||||||
|
navController: NavController,
|
||||||
|
viewModel: TailscaleStatusViewModel,
|
||||||
|
endpointTag: String,
|
||||||
|
) {
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(endpointTag) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(R.string.content_description_back))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val state by viewModel.uiState.collectAsState()
|
||||||
|
val endpoint = state.endpoints.firstOrNull { it.endpointTag == endpointTag }
|
||||||
|
|
||||||
|
if (endpoint == null) {
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
navController.navigateUp()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val context = LocalContext.current
|
||||||
|
var showAuthQRCode by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
val hasNetwork = endpoint.networkName.isNotEmpty()
|
||||||
|
val hasMagicDNS = endpoint.magicDNSSuffix.isNotEmpty()
|
||||||
|
val hasAuth = endpoint.authURL.isNotEmpty()
|
||||||
|
|
||||||
|
// Status section
|
||||||
|
SectionHeader(stringResource(R.string.tailscale_status))
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
val stateIsLast = !hasNetwork && !hasMagicDNS && !hasAuth
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.tailscale_state),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
supportingContent = {
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(8.dp)
|
||||||
|
.clip(CircleShape)
|
||||||
|
.background(stateColor(endpoint.backendState)),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
endpoint.backendState,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = stateColor(endpoint.backendState),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.clip(
|
||||||
|
if (stateIsLast) {
|
||||||
|
RoundedCornerShape(12.dp)
|
||||||
|
} else {
|
||||||
|
RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
if (hasNetwork) {
|
||||||
|
val networkIsLast = !hasMagicDNS && !hasAuth
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.tailscale_network),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
supportingContent = {
|
||||||
|
Text(
|
||||||
|
endpoint.networkName,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = if (networkIsLast) {
|
||||||
|
Modifier.clip(RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp))
|
||||||
|
} else {
|
||||||
|
Modifier
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (hasMagicDNS) {
|
||||||
|
val magicDNSIsLast = !hasAuth
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.tailscale_magic_dns),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
supportingContent = {
|
||||||
|
Text(
|
||||||
|
endpoint.magicDNSSuffix,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = if (magicDNSIsLast) {
|
||||||
|
Modifier.clip(RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp))
|
||||||
|
} else {
|
||||||
|
Modifier
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (hasAuth) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.tailscale_open_auth_url),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.AutoMirrored.Outlined.OpenInNew,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier.clickable {
|
||||||
|
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(endpoint.authURL)))
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.tailscale_open_auth_url_qr_code),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.QrCode2,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp))
|
||||||
|
.clickable { showAuthQRCode = true },
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This Device section
|
||||||
|
if (endpoint.backendState == "Running" && endpoint.selfPeer != null) {
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
SectionHeader(stringResource(R.string.tailscale_this_device))
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
PeerItem(
|
||||||
|
peer = endpoint.selfPeer,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
"tools/tailscale/${Uri.encode(endpointTag)}/peer/${Uri.encode(endpoint.selfPeer.id)}",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier.clip(RoundedCornerShape(12.dp)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// User group sections
|
||||||
|
for (group in endpoint.userGroups) {
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
SectionHeader(group.displayName.ifEmpty { group.loginName })
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
group.peers.forEachIndexed { index, peer ->
|
||||||
|
if (index > 0) {
|
||||||
|
HorizontalDivider(
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp),
|
||||||
|
color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.5f),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
PeerItem(
|
||||||
|
peer = peer,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate(
|
||||||
|
"tools/tailscale/${Uri.encode(endpointTag)}/peer/${Uri.encode(peer.id)}",
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = when {
|
||||||
|
group.peers.size == 1 -> Modifier.clip(RoundedCornerShape(12.dp))
|
||||||
|
index == 0 -> Modifier.clip(RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp))
|
||||||
|
index == group.peers.lastIndex -> Modifier.clip(RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp))
|
||||||
|
else -> Modifier
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showAuthQRCode && endpoint.authURL.isNotEmpty()) {
|
||||||
|
val qrBitmap = QRCodeGenerator.rememberBitmap(endpoint.authURL)
|
||||||
|
QRCodeDialog(
|
||||||
|
bitmap = qrBitmap,
|
||||||
|
onDismiss = { showAuthQRCode = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SectionHeader(title: String) {
|
||||||
|
Text(
|
||||||
|
text = title,
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun PeerItem(
|
||||||
|
peer: TailscalePeerData,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
peer.hostName,
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
supportingContent = if (peer.tailscaleIPs.isNotEmpty()) {
|
||||||
|
{
|
||||||
|
Text(
|
||||||
|
peer.tailscaleIPs.first(),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(8.dp)
|
||||||
|
.clip(CircleShape)
|
||||||
|
.background(if (peer.online) Color(0xFF4CAF50) else Color.Gray),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = modifier.clickable(onClick = onClick),
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stateColor(state: String): Color = when (state) {
|
||||||
|
"Running" -> Color(0xFF4CAF50)
|
||||||
|
"NeedsLogin", "NeedsMachineAuth" -> Color(0xFFFF9800)
|
||||||
|
"Starting" -> Color(0xFFFFEB3B)
|
||||||
|
else -> Color.Gray
|
||||||
|
}
|
||||||
@@ -0,0 +1,460 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import android.text.format.DateUtils
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.Check
|
||||||
|
import androidx.compose.material.icons.filled.PlayArrow
|
||||||
|
import androidx.compose.material.icons.filled.Stop
|
||||||
|
import androidx.compose.material.icons.outlined.ContentCopy
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.lerp
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.compose.LineChart
|
||||||
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.ktx.clipboardText
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun TailscalePeerScreen(
|
||||||
|
navController: NavController,
|
||||||
|
viewModel: TailscaleStatusViewModel,
|
||||||
|
endpointTag: String,
|
||||||
|
peerId: String,
|
||||||
|
) {
|
||||||
|
val state by viewModel.uiState.collectAsState()
|
||||||
|
val peer = viewModel.peer(endpointTag, peerId)
|
||||||
|
val isSelf = viewModel.endpoint(endpointTag)?.selfPeer?.id == peerId
|
||||||
|
val pingViewModel: TailscalePingViewModel = viewModel()
|
||||||
|
val pingState by pingViewModel.uiState.collectAsState()
|
||||||
|
|
||||||
|
DisposableEffect(Unit) {
|
||||||
|
onDispose {
|
||||||
|
if (pingState.isRunning) {
|
||||||
|
pingViewModel.stopPing()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = {
|
||||||
|
Column {
|
||||||
|
Text(
|
||||||
|
peer?.hostName ?: "",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
)
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(6.dp)
|
||||||
|
.clip(CircleShape)
|
||||||
|
.background(
|
||||||
|
if (peer?.online == true) Color(0xFF4CAF50) else Color.Gray,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
if (peer?.online == true) {
|
||||||
|
stringResource(R.string.tailscale_connected)
|
||||||
|
} else {
|
||||||
|
stringResource(R.string.tailscale_not_connected)
|
||||||
|
},
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(R.string.content_description_back))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (peer == null) {
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
navController.navigateUp()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var copiedAddress by remember { mutableStateOf<String?>(null) }
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
// Tailscale Addresses section
|
||||||
|
SectionHeader(stringResource(R.string.tailscale_addresses))
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.3f),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
if (peer.dnsName.isNotEmpty()) {
|
||||||
|
AddressRow(
|
||||||
|
address = Libbox.formatFQDN(peer.dnsName),
|
||||||
|
label = stringResource(R.string.tailscale_magic_dns),
|
||||||
|
copied = copiedAddress,
|
||||||
|
onCopy = { copiedAddress = it },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
for (ip in peer.tailscaleIPs) {
|
||||||
|
AddressRow(
|
||||||
|
address = ip,
|
||||||
|
label = if (ip.contains(":")) {
|
||||||
|
stringResource(R.string.tailscale_ipv6)
|
||||||
|
} else {
|
||||||
|
stringResource(R.string.tailscale_ipv4)
|
||||||
|
},
|
||||||
|
copied = copiedAddress,
|
||||||
|
onCopy = { copiedAddress = it },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ping section (not for self peer)
|
||||||
|
if (!isSelf && peer.online && peer.tailscaleIPs.isNotEmpty()) {
|
||||||
|
val peerIP = peer.tailscaleIPs.first()
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.tailscale_ping),
|
||||||
|
style = MaterialTheme.typography.titleSmall,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
Surface(
|
||||||
|
onClick = {
|
||||||
|
if (pingState.isRunning) {
|
||||||
|
pingViewModel.stopPing()
|
||||||
|
} else {
|
||||||
|
pingViewModel.startPing(endpointTag, peerIP)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = if (isSystemInDarkTheme()) {
|
||||||
|
lerp(
|
||||||
|
MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||||
|
MaterialTheme.colorScheme.surfaceContainerHigh,
|
||||||
|
0.5f,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
MaterialTheme.colorScheme.surfaceDim
|
||||||
|
},
|
||||||
|
modifier = Modifier.size(width = 44.dp, height = 32.dp),
|
||||||
|
) {
|
||||||
|
Box(contentAlignment = Alignment.Center) {
|
||||||
|
Icon(
|
||||||
|
imageVector = if (pingState.isRunning) Icons.Default.Stop else Icons.Default.PlayArrow,
|
||||||
|
contentDescription = if (pingState.isRunning) {
|
||||||
|
stringResource(R.string.tailscale_ping_stop)
|
||||||
|
} else {
|
||||||
|
stringResource(R.string.tailscale_ping_start)
|
||||||
|
},
|
||||||
|
modifier = Modifier.size(20.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.3f),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(16.dp),
|
||||||
|
) {
|
||||||
|
if (pingState.hasResult) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
if (pingState.isDirect) {
|
||||||
|
Text(
|
||||||
|
text = "\u2192 ",
|
||||||
|
color = Color(0xFF4CAF50),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.tailscale_ping_direct),
|
||||||
|
color = Color(0xFF4CAF50),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Text(
|
||||||
|
text = "\u21BB ",
|
||||||
|
color = Color(0xFFFF9800),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.tailscale_ping_derp),
|
||||||
|
color = Color(0xFFFF9800),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
Text(
|
||||||
|
text = "${pingState.latencyMs.toInt()} ms",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (pingState.isRunning && pingState.latencyHistory.size > 1) {
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
LineChart(
|
||||||
|
data = pingState.latencyHistory,
|
||||||
|
lineColor = if (pingState.isDirect) {
|
||||||
|
Color(0xFF4CAF50)
|
||||||
|
} else {
|
||||||
|
Color(0xFF2196F3)
|
||||||
|
},
|
||||||
|
animate = false,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
val maxMs = (
|
||||||
|
(
|
||||||
|
pingState.latencyHistory.maxOrNull()
|
||||||
|
?: 1f
|
||||||
|
) * 1.2f
|
||||||
|
).toInt().coerceAtLeast(1)
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.height(80.dp),
|
||||||
|
verticalArrangement = Arrangement.SpaceBetween,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "${maxMs}ms",
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "${maxMs * 2 / 3}ms",
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "${maxMs / 3}ms",
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "0ms",
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Text(
|
||||||
|
text = "No data",
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Details section
|
||||||
|
val showDetails = peer.keyExpiry > 0 || peer.os.isNotEmpty() || peer.exitNode
|
||||||
|
if (showDetails) {
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
SectionHeader(stringResource(R.string.tailscale_details))
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.3f),
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
if (peer.keyExpiry > 0) {
|
||||||
|
val expiryText = DateUtils.getRelativeTimeSpanString(
|
||||||
|
peer.keyExpiry * 1000,
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
DateUtils.MINUTE_IN_MILLIS,
|
||||||
|
).toString()
|
||||||
|
DetailRow(
|
||||||
|
label = stringResource(R.string.tailscale_key_expiry),
|
||||||
|
value = expiryText,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (peer.os.isNotEmpty()) {
|
||||||
|
DetailRow(
|
||||||
|
label = stringResource(R.string.tailscale_os),
|
||||||
|
value = peer.os,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (peer.exitNode) {
|
||||||
|
DetailRow(
|
||||||
|
label = stringResource(R.string.tailscale_exit_node),
|
||||||
|
value = stringResource(R.string.tailscale_active),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(copiedAddress) {
|
||||||
|
if (copiedAddress != null) {
|
||||||
|
delay(2000)
|
||||||
|
copiedAddress = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SectionHeader(title: String) {
|
||||||
|
Text(
|
||||||
|
text = title,
|
||||||
|
style = MaterialTheme.typography.titleSmall,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun DetailRow(label: String, value: String) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = label,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
modifier = Modifier.padding(end = 16.dp),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = value,
|
||||||
|
style = MaterialTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace),
|
||||||
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
textAlign = TextAlign.End,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun AddressRow(
|
||||||
|
address: String,
|
||||||
|
label: String,
|
||||||
|
copied: String?,
|
||||||
|
onCopy: (String) -> Unit,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
|
Text(
|
||||||
|
address,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
IconButton(onClick = {
|
||||||
|
clipboardText = address
|
||||||
|
onCopy(address)
|
||||||
|
}) {
|
||||||
|
if (copied == address) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Check,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Icon(
|
||||||
|
Icons.Outlined.ContentCopy,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import io.nekohasekai.libbox.CommandClient
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.libbox.TailscalePingHandler
|
||||||
|
import io.nekohasekai.libbox.TailscalePingResult
|
||||||
|
import io.nekohasekai.sfa.compose.base.BaseViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
data class TailscalePingState(
|
||||||
|
val isRunning: Boolean = false,
|
||||||
|
val hasResult: Boolean = false,
|
||||||
|
val latencyMs: Double = 0.0,
|
||||||
|
val isDirect: Boolean = false,
|
||||||
|
val derpRegionCode: String = "",
|
||||||
|
val endpoint: String = "",
|
||||||
|
val latencyHistory: List<Float> = emptyList(),
|
||||||
|
)
|
||||||
|
|
||||||
|
class TailscalePingViewModel : BaseViewModel<TailscalePingState, Nothing>() {
|
||||||
|
private val maxHistorySize = 30
|
||||||
|
private var commandClient: CommandClient? = null
|
||||||
|
private var grpcJob: Job? = null
|
||||||
|
|
||||||
|
override fun createInitialState() = TailscalePingState()
|
||||||
|
|
||||||
|
fun startPing(endpointTag: String, peerIP: String) {
|
||||||
|
updateState {
|
||||||
|
copy(
|
||||||
|
isRunning = true,
|
||||||
|
hasResult = false,
|
||||||
|
latencyHistory = emptyList(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val client = Libbox.newStandaloneCommandClient()
|
||||||
|
commandClient = client
|
||||||
|
|
||||||
|
grpcJob = viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
client.startTailscalePing(
|
||||||
|
endpointTag,
|
||||||
|
peerIP,
|
||||||
|
object : TailscalePingHandler {
|
||||||
|
override fun onPingResult(result: TailscalePingResult?) {
|
||||||
|
result ?: return
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (!currentState.isRunning) return@launch
|
||||||
|
if (result.error.isNotEmpty()) return@launch
|
||||||
|
val newHistory = currentState.latencyHistory.toMutableList()
|
||||||
|
newHistory.add(result.latencyMs.toFloat())
|
||||||
|
if (newHistory.size > maxHistorySize) {
|
||||||
|
newHistory.removeFirst()
|
||||||
|
}
|
||||||
|
updateState {
|
||||||
|
copy(
|
||||||
|
hasResult = true,
|
||||||
|
latencyMs = result.latencyMs,
|
||||||
|
isDirect = result.isDirect,
|
||||||
|
derpRegionCode = result.derpRegionCode,
|
||||||
|
endpoint = result.endpoint,
|
||||||
|
latencyHistory = newHistory,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(message: String?) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (!currentState.isRunning) return@launch
|
||||||
|
updateState { copy(isRunning = false) }
|
||||||
|
commandClient = null
|
||||||
|
grpcJob = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (!currentState.isRunning) return@withContext
|
||||||
|
updateState { copy(isRunning = false) }
|
||||||
|
commandClient = null
|
||||||
|
grpcJob = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopPing() {
|
||||||
|
grpcJob?.cancel()
|
||||||
|
grpcJob = null
|
||||||
|
try {
|
||||||
|
commandClient?.disconnect()
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
commandClient = null
|
||||||
|
updateState { copy(isRunning = false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
super.onCleared()
|
||||||
|
stopPing()
|
||||||
|
}
|
||||||
|
}
|
||||||
+180
@@ -0,0 +1,180 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import io.nekohasekai.libbox.Libbox
|
||||||
|
import io.nekohasekai.libbox.TailscaleStatusHandler
|
||||||
|
import io.nekohasekai.libbox.TailscaleStatusUpdate
|
||||||
|
import io.nekohasekai.sfa.compose.base.BaseViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
data class TailscalePeerData(
|
||||||
|
val id: String,
|
||||||
|
val hostName: String,
|
||||||
|
val dnsName: String,
|
||||||
|
val os: String,
|
||||||
|
val tailscaleIPs: List<String>,
|
||||||
|
val online: Boolean,
|
||||||
|
val exitNode: Boolean,
|
||||||
|
val exitNodeOption: Boolean,
|
||||||
|
val active: Boolean,
|
||||||
|
val rxBytes: Long,
|
||||||
|
val txBytes: Long,
|
||||||
|
val keyExpiry: Long,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class TailscaleUserGroupData(
|
||||||
|
val id: Long,
|
||||||
|
val loginName: String,
|
||||||
|
val displayName: String,
|
||||||
|
val profilePicURL: String,
|
||||||
|
val peers: List<TailscalePeerData>,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class TailscaleEndpointData(
|
||||||
|
val endpointTag: String,
|
||||||
|
val backendState: String,
|
||||||
|
val authURL: String,
|
||||||
|
val networkName: String,
|
||||||
|
val magicDNSSuffix: String,
|
||||||
|
val selfPeer: TailscalePeerData?,
|
||||||
|
val userGroups: List<TailscaleUserGroupData>,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class TailscaleStatusState(
|
||||||
|
val endpoints: List<TailscaleEndpointData> = emptyList(),
|
||||||
|
val isSubscribed: Boolean = false,
|
||||||
|
)
|
||||||
|
|
||||||
|
class TailscaleStatusViewModel : BaseViewModel<TailscaleStatusState, Nothing>() {
|
||||||
|
private var grpcJob: Job? = null
|
||||||
|
|
||||||
|
override fun createInitialState() = TailscaleStatusState()
|
||||||
|
|
||||||
|
fun subscribe() {
|
||||||
|
if (currentState.isSubscribed) return
|
||||||
|
updateState { copy(isSubscribed = true) }
|
||||||
|
|
||||||
|
grpcJob = viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
Libbox.newStandaloneCommandClient()
|
||||||
|
.subscribeTailscaleStatus(object : TailscaleStatusHandler {
|
||||||
|
override fun onStatusUpdate(status: TailscaleStatusUpdate) {
|
||||||
|
val endpoints = convertUpdate(status)
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (!currentState.isSubscribed) return@launch
|
||||||
|
updateState { copy(endpoints = endpoints) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(message: String) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (!currentState.isSubscribed) return@launch
|
||||||
|
updateState { copy(endpoints = emptyList(), isSubscribed = false) }
|
||||||
|
grpcJob = null
|
||||||
|
sendErrorMessage(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (_: Exception) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
updateState { copy(endpoints = emptyList(), isSubscribed = false) }
|
||||||
|
grpcJob = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cancel() {
|
||||||
|
grpcJob?.cancel()
|
||||||
|
grpcJob = null
|
||||||
|
updateState { copy(endpoints = emptyList(), isSubscribed = false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun endpoint(tag: String): TailscaleEndpointData? = currentState.endpoints.firstOrNull { it.endpointTag == tag }
|
||||||
|
|
||||||
|
fun peer(endpointTag: String, peerId: String): TailscalePeerData? {
|
||||||
|
val ep = endpoint(endpointTag) ?: return null
|
||||||
|
if (ep.selfPeer?.id == peerId) return ep.selfPeer
|
||||||
|
for (group in ep.userGroups) {
|
||||||
|
val found = group.peers.firstOrNull { it.id == peerId }
|
||||||
|
if (found != null) return found
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
cancel()
|
||||||
|
super.onCleared()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun convertUpdate(status: TailscaleStatusUpdate): List<TailscaleEndpointData> {
|
||||||
|
val endpoints = mutableListOf<TailscaleEndpointData>()
|
||||||
|
val iterator = status.endpoints()
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
endpoints.add(convertEndpoint(iterator.next()))
|
||||||
|
}
|
||||||
|
return endpoints
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun convertEndpoint(
|
||||||
|
endpoint: io.nekohasekai.libbox.TailscaleEndpointStatus,
|
||||||
|
): TailscaleEndpointData {
|
||||||
|
val userGroups = mutableListOf<TailscaleUserGroupData>()
|
||||||
|
val groupIterator = endpoint.userGroups()
|
||||||
|
while (groupIterator.hasNext()) {
|
||||||
|
userGroups.add(convertUserGroup(groupIterator.next()))
|
||||||
|
}
|
||||||
|
val self = endpoint.getSelf()
|
||||||
|
return TailscaleEndpointData(
|
||||||
|
endpointTag = endpoint.endpointTag,
|
||||||
|
backendState = endpoint.backendState,
|
||||||
|
authURL = endpoint.authURL,
|
||||||
|
networkName = endpoint.networkName,
|
||||||
|
magicDNSSuffix = endpoint.magicDNSSuffix,
|
||||||
|
selfPeer = if (self != null) convertPeer(self) else null,
|
||||||
|
userGroups = userGroups,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun convertUserGroup(
|
||||||
|
group: io.nekohasekai.libbox.TailscaleUserGroup,
|
||||||
|
): TailscaleUserGroupData {
|
||||||
|
val peers = mutableListOf<TailscalePeerData>()
|
||||||
|
val peerIterator = group.peers()
|
||||||
|
while (peerIterator.hasNext()) {
|
||||||
|
peers.add(convertPeer(peerIterator.next()))
|
||||||
|
}
|
||||||
|
return TailscaleUserGroupData(
|
||||||
|
id = group.userID,
|
||||||
|
loginName = group.loginName,
|
||||||
|
displayName = group.displayName,
|
||||||
|
profilePicURL = group.profilePicURL,
|
||||||
|
peers = peers,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun convertPeer(peer: io.nekohasekai.libbox.TailscalePeer): TailscalePeerData {
|
||||||
|
val ips = mutableListOf<String>()
|
||||||
|
val ipIterator = peer.tailscaleIPs()
|
||||||
|
while (ipIterator.hasNext()) {
|
||||||
|
ips.add(ipIterator.next())
|
||||||
|
}
|
||||||
|
val dnsName = peer.getDNSName()
|
||||||
|
return TailscalePeerData(
|
||||||
|
id = if (dnsName.isNotEmpty()) dnsName else peer.hostName,
|
||||||
|
hostName = peer.hostName,
|
||||||
|
dnsName = dnsName,
|
||||||
|
os = peer.getOS(),
|
||||||
|
tailscaleIPs = ips,
|
||||||
|
online = peer.online,
|
||||||
|
exitNode = peer.exitNode,
|
||||||
|
exitNodeOption = peer.exitNodeOption,
|
||||||
|
active = peer.active,
|
||||||
|
rxBytes = peer.rxBytes,
|
||||||
|
txBytes = peer.txBytes,
|
||||||
|
keyExpiry = peer.keyExpiry,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
package io.nekohasekai.sfa.compose.screen.tools
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.BugReport
|
||||||
|
import androidx.compose.material.icons.outlined.Hub
|
||||||
|
import androidx.compose.material.icons.outlined.Memory
|
||||||
|
import androidx.compose.material.icons.outlined.NetworkCheck
|
||||||
|
import androidx.compose.material3.Badge
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.ListItem
|
||||||
|
import androidx.compose.material3.ListItemDefaults
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import io.nekohasekai.sfa.R
|
||||||
|
import io.nekohasekai.sfa.bg.CrashReportManager
|
||||||
|
import io.nekohasekai.sfa.bg.OOMReportManager
|
||||||
|
import io.nekohasekai.sfa.compose.topbar.OverrideTopBar
|
||||||
|
import io.nekohasekai.sfa.constant.Status
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun ToolsScreen(
|
||||||
|
navController: NavController,
|
||||||
|
serviceStatus: Status = Status.Stopped,
|
||||||
|
tailscaleViewModel: TailscaleStatusViewModel,
|
||||||
|
) {
|
||||||
|
OverrideTopBar {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.title_tools)) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val crashUnreadCount by CrashReportManager.unreadCount.collectAsState()
|
||||||
|
val oomUnreadCount by OOMReportManager.unreadCount.collectAsState()
|
||||||
|
val tailscaleState by tailscaleViewModel.uiState.collectAsState()
|
||||||
|
|
||||||
|
LaunchedEffect(serviceStatus) {
|
||||||
|
if (serviceStatus == Status.Started) {
|
||||||
|
tailscaleViewModel.subscribe()
|
||||||
|
} else {
|
||||||
|
tailscaleViewModel.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(vertical = 8.dp),
|
||||||
|
) {
|
||||||
|
if (tailscaleState.endpoints.isNotEmpty()) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.tailscale_endpoints),
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
val endpoints = tailscaleState.endpoints
|
||||||
|
endpoints.forEachIndexed { index, endpoint ->
|
||||||
|
val shape = when {
|
||||||
|
endpoints.size == 1 -> RoundedCornerShape(12.dp)
|
||||||
|
index == 0 -> RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp)
|
||||||
|
index == endpoints.size - 1 -> RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp)
|
||||||
|
else -> RoundedCornerShape(0.dp)
|
||||||
|
}
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
if (endpoints.size == 1) {
|
||||||
|
stringResource(R.string.tailscale)
|
||||||
|
} else {
|
||||||
|
stringResource(R.string.tailscale_with_tag, endpoint.endpointTag)
|
||||||
|
},
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.Hub,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(shape)
|
||||||
|
.clickable {
|
||||||
|
navController.navigate("tools/tailscale/${Uri.encode(endpoint.endpointTag)}")
|
||||||
|
},
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.title_network),
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.network_quality),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.NetworkCheck,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp))
|
||||||
|
.clickable { navController.navigate("tools/network_quality") },
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.stun_test),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.NetworkCheck,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp))
|
||||||
|
.clickable { navController.navigate("tools/stun_test") },
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.title_debug),
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.padding(horizontal = 32.dp, vertical = 8.dp),
|
||||||
|
)
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.crash_report),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.BugReport,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
trailingContent = {
|
||||||
|
if (crashUnreadCount > 0) {
|
||||||
|
Badge(containerColor = MaterialTheme.colorScheme.primary) {
|
||||||
|
Text("$crashUnreadCount")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp))
|
||||||
|
.clickable { navController.navigate("tools/crash_report") },
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
ListItem(
|
||||||
|
headlineContent = {
|
||||||
|
Text(
|
||||||
|
stringResource(R.string.oom_report),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Outlined.Memory,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
trailingContent = {
|
||||||
|
if (oomUnreadCount > 0) {
|
||||||
|
Badge(containerColor = MaterialTheme.colorScheme.primary) {
|
||||||
|
Text("$oomUnreadCount")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp))
|
||||||
|
.clickable { navController.navigate("tools/oom_report") },
|
||||||
|
colors = ListItemDefaults.colors(containerColor = Color.Transparent),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,6 +31,11 @@ object SettingsKey {
|
|||||||
const val PRIVILEGE_SETTINGS_INTERFACE_RENAME_ENABLED = "hide_settings_interface_rename_enabled"
|
const val PRIVILEGE_SETTINGS_INTERFACE_RENAME_ENABLED = "hide_settings_interface_rename_enabled"
|
||||||
const val PRIVILEGE_SETTINGS_INTERFACE_PREFIX = "hide_settings_interface_prefix"
|
const val PRIVILEGE_SETTINGS_INTERFACE_PREFIX = "hide_settings_interface_prefix"
|
||||||
|
|
||||||
|
// OOM killer
|
||||||
|
const val OOM_KILLER_ENABLED = "oom_killer_enabled"
|
||||||
|
const val OOM_KILLER_DISABLED = "oom_killer_disabled"
|
||||||
|
const val OOM_MEMORY_LIMIT_MB = "oom_memory_limit_mb"
|
||||||
|
|
||||||
// dashboard
|
// dashboard
|
||||||
const val DASHBOARD_ITEM_ORDER = "dashboard_item_order"
|
const val DASHBOARD_ITEM_ORDER = "dashboard_item_order"
|
||||||
const val DASHBOARD_DISABLED_ITEMS = "dashboard_disabled_items"
|
const val DASHBOARD_DISABLED_ITEMS = "dashboard_disabled_items"
|
||||||
|
|||||||
@@ -106,6 +106,10 @@ object Settings {
|
|||||||
) { false }
|
) { false }
|
||||||
var privilegeSettingsInterfacePrefix by dataStore.string(SettingsKey.PRIVILEGE_SETTINGS_INTERFACE_PREFIX) { "wlan" }
|
var privilegeSettingsInterfacePrefix by dataStore.string(SettingsKey.PRIVILEGE_SETTINGS_INTERFACE_PREFIX) { "wlan" }
|
||||||
|
|
||||||
|
var oomKillerEnabled by dataStore.boolean(SettingsKey.OOM_KILLER_ENABLED) { false }
|
||||||
|
var oomKillerDisabled by dataStore.boolean(SettingsKey.OOM_KILLER_DISABLED) { true }
|
||||||
|
var oomMemoryLimitMB by dataStore.int(SettingsKey.OOM_MEMORY_LIMIT_MB) { 50 }
|
||||||
|
|
||||||
var dashboardItemOrder by dataStore.string(SettingsKey.DASHBOARD_ITEM_ORDER) { "" }
|
var dashboardItemOrder by dataStore.string(SettingsKey.DASHBOARD_ITEM_ORDER) { "" }
|
||||||
var dashboardDisabledItems by dataStore.stringSet(SettingsKey.DASHBOARD_DISABLED_ITEMS) { emptySet() }
|
var dashboardDisabledItems by dataStore.stringSet(SettingsKey.DASHBOARD_DISABLED_ITEMS) { emptySet() }
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import io.nekohasekai.libbox.Libbox
|
|||||||
import io.nekohasekai.libbox.LogEntry
|
import io.nekohasekai.libbox.LogEntry
|
||||||
import io.nekohasekai.libbox.LogIterator
|
import io.nekohasekai.libbox.LogIterator
|
||||||
import io.nekohasekai.libbox.OutboundGroup
|
import io.nekohasekai.libbox.OutboundGroup
|
||||||
|
import io.nekohasekai.libbox.OutboundGroupItemIterator
|
||||||
import io.nekohasekai.libbox.OutboundGroupIterator
|
import io.nekohasekai.libbox.OutboundGroupIterator
|
||||||
import io.nekohasekai.libbox.StatusMessage
|
import io.nekohasekai.libbox.StatusMessage
|
||||||
import io.nekohasekai.libbox.StringIterator
|
import io.nekohasekai.libbox.StringIterator
|
||||||
@@ -29,6 +30,7 @@ open class CommandClient(
|
|||||||
|
|
||||||
private val additionalHandlers = mutableListOf<Handler>()
|
private val additionalHandlers = mutableListOf<Handler>()
|
||||||
private var cachedGroups: MutableList<OutboundGroup>? = null
|
private var cachedGroups: MutableList<OutboundGroup>? = null
|
||||||
|
private var cachedOutbounds: List<io.nekohasekai.libbox.OutboundGroupItem>? = null
|
||||||
|
|
||||||
fun addHandler(handler: Handler) {
|
fun addHandler(handler: Handler) {
|
||||||
synchronized(additionalHandlers) {
|
synchronized(additionalHandlers) {
|
||||||
@@ -37,6 +39,9 @@ open class CommandClient(
|
|||||||
cachedGroups?.let { groups ->
|
cachedGroups?.let { groups ->
|
||||||
handler.updateGroups(groups)
|
handler.updateGroups(groups)
|
||||||
}
|
}
|
||||||
|
cachedOutbounds?.let { outbounds ->
|
||||||
|
handler.updateOutbounds(outbounds)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,6 +62,7 @@ open class CommandClient(
|
|||||||
Log,
|
Log,
|
||||||
ClashMode,
|
ClashMode,
|
||||||
Connections,
|
Connections,
|
||||||
|
Outbounds,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Handler {
|
interface Handler {
|
||||||
@@ -74,6 +80,8 @@ open class CommandClient(
|
|||||||
|
|
||||||
fun updateGroups(newGroups: MutableList<OutboundGroup>) {}
|
fun updateGroups(newGroups: MutableList<OutboundGroup>) {}
|
||||||
|
|
||||||
|
fun updateOutbounds(outbounds: List<io.nekohasekai.libbox.OutboundGroupItem>) {}
|
||||||
|
|
||||||
fun initializeClashMode(modeList: List<String>, currentMode: String) {}
|
fun initializeClashMode(modeList: List<String>, currentMode: String) {}
|
||||||
|
|
||||||
fun updateClashMode(newMode: String) {}
|
fun updateClashMode(newMode: String) {}
|
||||||
@@ -95,6 +103,7 @@ open class CommandClient(
|
|||||||
ConnectionType.Log -> Libbox.CommandLog
|
ConnectionType.Log -> Libbox.CommandLog
|
||||||
ConnectionType.ClashMode -> Libbox.CommandClashMode
|
ConnectionType.ClashMode -> Libbox.CommandClashMode
|
||||||
ConnectionType.Connections -> Libbox.CommandConnections
|
ConnectionType.Connections -> Libbox.CommandConnections
|
||||||
|
ConnectionType.Outbounds -> Libbox.CommandOutbounds
|
||||||
}
|
}
|
||||||
options.addCommand(command)
|
options.addCommand(command)
|
||||||
}
|
}
|
||||||
@@ -142,6 +151,18 @@ open class CommandClient(
|
|||||||
getAllHandlers().forEach { it.updateGroups(groups) }
|
getAllHandlers().forEach { it.updateGroups(groups) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun writeOutbounds(message: OutboundGroupItemIterator?) {
|
||||||
|
if (message == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val outbounds = mutableListOf<io.nekohasekai.libbox.OutboundGroupItem>()
|
||||||
|
while (message.hasNext()) {
|
||||||
|
outbounds.add(message.next())
|
||||||
|
}
|
||||||
|
cachedOutbounds = outbounds
|
||||||
|
getAllHandlers().forEach { it.updateOutbounds(outbounds) }
|
||||||
|
}
|
||||||
|
|
||||||
override fun setDefaultLogLevel(level: Int) {
|
override fun setDefaultLogLevel(level: Int) {
|
||||||
getAllHandlers().forEach { it.setDefaultLogLevel(level) }
|
getAllHandlers().forEach { it.setDefaultLogLevel(level) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
<string name="action">اقدام</string>
|
<string name="action">اقدام</string>
|
||||||
<string name="action_start">شروع</string>
|
<string name="action_start">شروع</string>
|
||||||
<string name="action_deselect">لغو انتخاب</string>
|
<string name="action_deselect">لغو انتخاب</string>
|
||||||
|
<string name="action_reload">بارگذاری مجدد</string>
|
||||||
|
<string name="action_restart">راهاندازی مجدد</string>
|
||||||
<string name="expand">باز کردن</string>
|
<string name="expand">باز کردن</string>
|
||||||
<string name="collapse">جمع کردن</string>
|
<string name="collapse">جمع کردن</string>
|
||||||
<string name="expand_all">باز کردن همه</string>
|
<string name="expand_all">باز کردن همه</string>
|
||||||
@@ -200,6 +202,8 @@
|
|||||||
<string name="working_directory">پوشه کاری</string>
|
<string name="working_directory">پوشه کاری</string>
|
||||||
<string name="beta_settings">تنظیمات بتا</string>
|
<string name="beta_settings">تنظیمات بتا</string>
|
||||||
<string name="disable_deprecated_warnings">غیرفعالکردن هشدارهای منسوخ</string>
|
<string name="disable_deprecated_warnings">غیرفعالکردن هشدارهای منسوخ</string>
|
||||||
|
<string name="cache_size">اندازه حافظه پنهان</string>
|
||||||
|
<string name="clear_cache">پاکسازی حافظه پنهان</string>
|
||||||
<string name="notification_settings">اعلانها</string>
|
<string name="notification_settings">اعلانها</string>
|
||||||
<string name="enable_notification">فعالکردن اعلان</string>
|
<string name="enable_notification">فعالکردن اعلان</string>
|
||||||
<string name="dynamic_notification">نمایش سرعت بلادرنگ در اعلان</string>
|
<string name="dynamic_notification">نمایش سرعت بلادرنگ در اعلان</string>
|
||||||
@@ -279,6 +283,22 @@
|
|||||||
<string name="new_version_available">نسخه جدید موجود است: %s</string>
|
<string name="new_version_available">نسخه جدید موجود است: %s</string>
|
||||||
<string name="auto_update">بهروزرسانی خودکار</string>
|
<string name="auto_update">بهروزرسانی خودکار</string>
|
||||||
<string name="auto_update_description">دانلود و نصب خودکار بهروزرسانیها در پسزمینه</string>
|
<string name="auto_update_description">دانلود و نصب خودکار بهروزرسانیها در پسزمینه</string>
|
||||||
|
<string name="update_source">منبع بهروزرسانی</string>
|
||||||
|
<string name="update_source_github">GitHub</string>
|
||||||
|
<string name="update_source_fdroid">F-Droid</string>
|
||||||
|
<string name="fdroid_mirror">آینه F-Droid</string>
|
||||||
|
<string name="fdroid_mirror_test_all">انتخاب خودکار بر اساس تأخیر</string>
|
||||||
|
<string name="fdroid_mirror_testing">در حال تست…</string>
|
||||||
|
<string name="fdroid_mirror_latency">%d ms</string>
|
||||||
|
<string name="fdroid_mirror_failed">ناموفق</string>
|
||||||
|
<string name="fdroid_mirror_untested">—</string>
|
||||||
|
<string name="fdroid_mirror_add">افزودن آینه</string>
|
||||||
|
<string name="fdroid_mirror_name_hint">نام</string>
|
||||||
|
<string name="fdroid_mirror_url_hint">URL</string>
|
||||||
|
<string name="fdroid_mirror_custom">سفارشی</string>
|
||||||
|
<string name="fdroid_mirror_invalid_url">URL نامعتبر</string>
|
||||||
|
<string name="fdroid_mirror_add_action">افزودن</string>
|
||||||
|
<string name="fdroid_mirror_delete">حذف</string>
|
||||||
|
|
||||||
<!-- Silent Install -->
|
<!-- Silent Install -->
|
||||||
<string name="silent_install">نصب بیصدا</string>
|
<string name="silent_install">نصب بیصدا</string>
|
||||||
@@ -406,6 +426,94 @@
|
|||||||
<string name="content_description_collapse_search">جمع کردن جستجو</string>
|
<string name="content_description_collapse_search">جمع کردن جستجو</string>
|
||||||
<string name="content_description_search_logs">جستجوی لاگها</string>
|
<string name="content_description_search_logs">جستجوی لاگها</string>
|
||||||
|
|
||||||
|
<!-- Tools -->
|
||||||
|
<string name="title_tools">ابزارها</string>
|
||||||
|
<string name="title_network">شبکه</string>
|
||||||
|
<string name="network_quality">کیفیت شبکه</string>
|
||||||
|
<string name="network_quality_url">URL</string>
|
||||||
|
<string name="network_quality_serial">ترتیبی</string>
|
||||||
|
<string name="network_quality_http3">HTTP/3</string>
|
||||||
|
<string name="network_quality_max_runtime">حداکثر زمان اجرا</string>
|
||||||
|
<string name="network_quality_max_runtime_30s">30s</string>
|
||||||
|
<string name="network_quality_max_runtime_60s">60s</string>
|
||||||
|
<string name="network_quality_start">شروع تست</string>
|
||||||
|
<string name="network_quality_cancel">لغو تست</string>
|
||||||
|
<string name="network_quality_idle_latency">تأخیر بیکاری</string>
|
||||||
|
<string name="network_quality_download">دانلود</string>
|
||||||
|
<string name="network_quality_upload">آپلود</string>
|
||||||
|
<string name="network_quality_download_rpm">RPM دانلود</string>
|
||||||
|
<string name="network_quality_upload_rpm">RPM آپلود</string>
|
||||||
|
<string name="network_quality_confidence_high">اطمینان بالا</string>
|
||||||
|
<string name="network_quality_confidence_medium">اطمینان متوسط</string>
|
||||||
|
<string name="network_quality_confidence_low">اطمینان پایین</string>
|
||||||
|
<string name="network_quality_metered_title">اتصال محدود</string>
|
||||||
|
<string name="network_quality_metered_message">شما از اتصال محدود استفاده میکنید. این تست حجم قابل توجهی داده مصرف خواهد کرد.</string>
|
||||||
|
<string name="network_quality_metered_continue">ادامه</string>
|
||||||
|
<string name="tool_configuration">پیکربندی</string>
|
||||||
|
<string name="tool_results">نتایج</string>
|
||||||
|
<string name="tool_outbound">خروجی</string>
|
||||||
|
<string name="tool_default_outbound">پیشفرض</string>
|
||||||
|
|
||||||
|
<!-- STUN Test -->
|
||||||
|
<!-- Tailscale -->
|
||||||
|
<string name="tailscale_endpoints">نقاط اتصال</string>
|
||||||
|
|
||||||
|
<string name="tailscale_status">وضعیت</string>
|
||||||
|
<string name="tailscale_state">وضعیت</string>
|
||||||
|
<string name="tailscale_network">شبکه</string>
|
||||||
|
<string name="tailscale_open_auth_url">باز کردن لینک احراز هویت</string>
|
||||||
|
<string name="tailscale_open_auth_url_qr_code">نمایش QR کد لینک احراز هویت</string>
|
||||||
|
<string name="tailscale_this_device">این دستگاه</string>
|
||||||
|
<string name="tailscale_connected">متصل</string>
|
||||||
|
<string name="tailscale_not_connected">متصل نیست</string>
|
||||||
|
<string name="tailscale_addresses">آدرسهای Tailscale</string>
|
||||||
|
<string name="tailscale_details">جزئیات</string>
|
||||||
|
<string name="tailscale_key_expiry">انقضای کلید</string>
|
||||||
|
<string name="tailscale_exit_node">گره خروجی</string>
|
||||||
|
<string name="tailscale_active">فعال</string>
|
||||||
|
|
||||||
|
<string name="stun_test">تست STUN</string>
|
||||||
|
<string name="stun_server">سرور</string>
|
||||||
|
<string name="stun_start">شروع تست</string>
|
||||||
|
<string name="stun_cancel">لغو تست</string>
|
||||||
|
<string name="stun_external_address">آدرس خارجی</string>
|
||||||
|
<string name="stun_latency">تأخیر</string>
|
||||||
|
<string name="stun_nat_mapping">نگاشت NAT</string>
|
||||||
|
<string name="stun_nat_filtering">فیلتر NAT</string>
|
||||||
|
<string name="stun_nat_type_detection">تشخیص نوع NAT</string>
|
||||||
|
<string name="stun_nat_not_supported">پشتیبانی نمیشود توسط سرور</string>
|
||||||
|
|
||||||
|
<!-- Shared Report -->
|
||||||
|
<string name="report_empty">خالی</string>
|
||||||
|
<string name="report_section_reports">گزارشها</string>
|
||||||
|
<string name="report_section_files">فایلها</string>
|
||||||
|
<string name="report_delete_all">حذف همه</string>
|
||||||
|
<string name="report_delete">حذف</string>
|
||||||
|
<string name="report_share">اشتراکگذاری</string>
|
||||||
|
<string name="report_share_with_config">اشتراکگذاری با پیکربندی</string>
|
||||||
|
<string name="report_metadata">فراداده</string>
|
||||||
|
<string name="report_configuration">پیکربندی</string>
|
||||||
|
<string name="report_origin_local">محلی</string>
|
||||||
|
<string name="service_not_started">سرویس شروع نشده است</string>
|
||||||
|
<string name="service_reload_required">برای اعمال تغییرات، بارگذاری مجدد سرویس لازم است</string>
|
||||||
|
<string name="service_restart_required">برای اعمال تغییرات، راهاندازی مجدد سرویس لازم است</string>
|
||||||
|
|
||||||
|
<!-- Crash Report -->
|
||||||
|
<string name="crash_report">گزارش خرابی</string>
|
||||||
|
<string name="crash_report_go_log">Go Crash Log</string>
|
||||||
|
<string name="crash_report_jvm_log">JVM Crash Log</string>
|
||||||
|
<string name="crash_report_description">هنگام بروز خرابی گزارشی دریافت خواهید کرد.</string>
|
||||||
|
|
||||||
|
<!-- OOM Report -->
|
||||||
|
<string name="oom_report">گزارش کمبود حافظه</string>
|
||||||
|
<string name="oom_report_description">هنگامی که محدودیت حافظه فعال است، در صورت تجاوز حافظه سرویس از حد مجاز، گزارشی دریافت خواهید کرد. همچنین میتوانید جمعآوری گزارش را به صورت دستی فعال کنید.</string>
|
||||||
|
<string name="oom_report_fetch">دریافت گزارش حافظه</string>
|
||||||
|
<string name="oom_report_enable_memory_limit">فعالسازی محدودیت حافظه</string>
|
||||||
|
<string name="oom_report_enable_memory_limit_description">یک محدودیت نرم حافظه برای سرویس تعیین کنید. سرویس چندین فرآیند را انجام خواهد داد تا سعی کند در محدوده این محدودیت حافظه باقی بماند.</string>
|
||||||
|
<string name="oom_report_memory_limit">محدودیت حافظه</string>
|
||||||
|
<string name="oom_report_kill_connections">قطع اتصالات</string>
|
||||||
|
<string name="oom_report_kill_connections_description">هنگام تجاوز حافظه سرویس از حد مجاز، تمام اتصالات را برای آزادسازی حافظه قطع کنید.</string>
|
||||||
|
|
||||||
<!-- Xposed Module -->
|
<!-- Xposed Module -->
|
||||||
<string name="xposed_description">بهبود دسترسی ویژه برای sing-box</string>
|
<string name="xposed_description">بهبود دسترسی ویژه برای sing-box</string>
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
<string name="action">Действие</string>
|
<string name="action">Действие</string>
|
||||||
<string name="action_start">Начать</string>
|
<string name="action_start">Начать</string>
|
||||||
<string name="action_deselect">Отменить выбор</string>
|
<string name="action_deselect">Отменить выбор</string>
|
||||||
|
<string name="action_reload">Перезагрузить</string>
|
||||||
|
<string name="action_restart">Перезапустить</string>
|
||||||
<string name="expand">Развернуть</string>
|
<string name="expand">Развернуть</string>
|
||||||
<string name="collapse">Свернуть</string>
|
<string name="collapse">Свернуть</string>
|
||||||
<string name="expand_all">Развернуть все</string>
|
<string name="expand_all">Развернуть все</string>
|
||||||
@@ -200,6 +202,8 @@
|
|||||||
<string name="working_directory">Рабочая директория</string>
|
<string name="working_directory">Рабочая директория</string>
|
||||||
<string name="beta_settings">Бета-настройки</string>
|
<string name="beta_settings">Бета-настройки</string>
|
||||||
<string name="disable_deprecated_warnings">Отключить предупреждения об устаревании</string>
|
<string name="disable_deprecated_warnings">Отключить предупреждения об устаревании</string>
|
||||||
|
<string name="cache_size">Размер кэша</string>
|
||||||
|
<string name="clear_cache">Очистить кэш</string>
|
||||||
<string name="notification_settings">Уведомления</string>
|
<string name="notification_settings">Уведомления</string>
|
||||||
<string name="enable_notification">Включить уведомления</string>
|
<string name="enable_notification">Включить уведомления</string>
|
||||||
<string name="dynamic_notification">Отображать скорость в реальном времени в уведомлении</string>
|
<string name="dynamic_notification">Отображать скорость в реальном времени в уведомлении</string>
|
||||||
@@ -279,6 +283,22 @@
|
|||||||
<string name="new_version_available">Доступна новая версия: %s</string>
|
<string name="new_version_available">Доступна новая версия: %s</string>
|
||||||
<string name="auto_update">Автообновление</string>
|
<string name="auto_update">Автообновление</string>
|
||||||
<string name="auto_update_description">Автоматически загружать и устанавливать обновления в фоне</string>
|
<string name="auto_update_description">Автоматически загружать и устанавливать обновления в фоне</string>
|
||||||
|
<string name="update_source">Источник обновлений</string>
|
||||||
|
<string name="update_source_github">GitHub</string>
|
||||||
|
<string name="update_source_fdroid">F-Droid</string>
|
||||||
|
<string name="fdroid_mirror">Зеркало F-Droid</string>
|
||||||
|
<string name="fdroid_mirror_test_all">Автовыбор по задержке</string>
|
||||||
|
<string name="fdroid_mirror_testing">Тестирование…</string>
|
||||||
|
<string name="fdroid_mirror_latency">%d мс</string>
|
||||||
|
<string name="fdroid_mirror_failed">Ошибка</string>
|
||||||
|
<string name="fdroid_mirror_untested">—</string>
|
||||||
|
<string name="fdroid_mirror_add">Добавить зеркало</string>
|
||||||
|
<string name="fdroid_mirror_name_hint">Имя</string>
|
||||||
|
<string name="fdroid_mirror_url_hint">URL</string>
|
||||||
|
<string name="fdroid_mirror_custom">Пользовательское</string>
|
||||||
|
<string name="fdroid_mirror_invalid_url">Недопустимый URL</string>
|
||||||
|
<string name="fdroid_mirror_add_action">Добавить</string>
|
||||||
|
<string name="fdroid_mirror_delete">Удалить</string>
|
||||||
|
|
||||||
<!-- Silent Install -->
|
<!-- Silent Install -->
|
||||||
<string name="silent_install">Тихая установка</string>
|
<string name="silent_install">Тихая установка</string>
|
||||||
@@ -412,6 +432,94 @@
|
|||||||
<string name="content_description_collapse_search">Свернуть поиск</string>
|
<string name="content_description_collapse_search">Свернуть поиск</string>
|
||||||
<string name="content_description_search_logs">Поиск в логе</string>
|
<string name="content_description_search_logs">Поиск в логе</string>
|
||||||
|
|
||||||
|
<!-- Tools -->
|
||||||
|
<string name="title_tools">Инструменты</string>
|
||||||
|
<string name="title_network">Сеть</string>
|
||||||
|
<string name="network_quality">Качество сети</string>
|
||||||
|
<string name="network_quality_url">URL</string>
|
||||||
|
<string name="network_quality_serial">Последовательно</string>
|
||||||
|
<string name="network_quality_http3">HTTP/3</string>
|
||||||
|
<string name="network_quality_max_runtime">Макс. время</string>
|
||||||
|
<string name="network_quality_max_runtime_30s">30s</string>
|
||||||
|
<string name="network_quality_max_runtime_60s">60s</string>
|
||||||
|
<string name="network_quality_start">Начать тест</string>
|
||||||
|
<string name="network_quality_cancel">Остановить тест</string>
|
||||||
|
<string name="network_quality_idle_latency">Задержка в простое</string>
|
||||||
|
<string name="network_quality_download">Загрузка</string>
|
||||||
|
<string name="network_quality_upload">Отправка</string>
|
||||||
|
<string name="network_quality_download_rpm">Загрузка RPM</string>
|
||||||
|
<string name="network_quality_upload_rpm">Отправка RPM</string>
|
||||||
|
<string name="network_quality_confidence_high">Высокая уверенность</string>
|
||||||
|
<string name="network_quality_confidence_medium">Средняя уверенность</string>
|
||||||
|
<string name="network_quality_confidence_low">Низкая уверенность</string>
|
||||||
|
<string name="network_quality_metered_title">Лимитное подключение</string>
|
||||||
|
<string name="network_quality_metered_message">Вы используете лимитное подключение. Этот тест потребует значительного объёма трафика.</string>
|
||||||
|
<string name="network_quality_metered_continue">Продолжить</string>
|
||||||
|
<string name="tool_configuration">Конфигурация</string>
|
||||||
|
<string name="tool_results">Результаты</string>
|
||||||
|
<string name="tool_outbound">Исходящий</string>
|
||||||
|
<string name="tool_default_outbound">По умолчанию</string>
|
||||||
|
|
||||||
|
<!-- STUN Test -->
|
||||||
|
<!-- Tailscale -->
|
||||||
|
<string name="tailscale_endpoints">Точки подключения</string>
|
||||||
|
|
||||||
|
<string name="tailscale_status">Статус</string>
|
||||||
|
<string name="tailscale_state">Состояние</string>
|
||||||
|
<string name="tailscale_network">Сеть</string>
|
||||||
|
<string name="tailscale_open_auth_url">Открыть URL авторизации</string>
|
||||||
|
<string name="tailscale_open_auth_url_qr_code">Показать QR-код авторизации</string>
|
||||||
|
<string name="tailscale_this_device">Это устройство</string>
|
||||||
|
<string name="tailscale_connected">Подключено</string>
|
||||||
|
<string name="tailscale_not_connected">Не подключено</string>
|
||||||
|
<string name="tailscale_addresses">Адреса Tailscale</string>
|
||||||
|
<string name="tailscale_details">Подробности</string>
|
||||||
|
<string name="tailscale_key_expiry">Срок действия ключа</string>
|
||||||
|
<string name="tailscale_exit_node">Выходной узел</string>
|
||||||
|
<string name="tailscale_active">Активен</string>
|
||||||
|
|
||||||
|
<string name="stun_test">STUN-тест</string>
|
||||||
|
<string name="stun_server">Сервер</string>
|
||||||
|
<string name="stun_start">Начать тест</string>
|
||||||
|
<string name="stun_cancel">Остановить тест</string>
|
||||||
|
<string name="stun_external_address">Внешний адрес</string>
|
||||||
|
<string name="stun_latency">Задержка</string>
|
||||||
|
<string name="stun_nat_mapping">NAT-отображение</string>
|
||||||
|
<string name="stun_nat_filtering">NAT-фильтрация</string>
|
||||||
|
<string name="stun_nat_type_detection">Определение типа NAT</string>
|
||||||
|
<string name="stun_nat_not_supported">Не поддерживается сервером</string>
|
||||||
|
|
||||||
|
<!-- Shared Report -->
|
||||||
|
<string name="report_empty">Пусто</string>
|
||||||
|
<string name="report_section_reports">Отчёты</string>
|
||||||
|
<string name="report_section_files">Файлы</string>
|
||||||
|
<string name="report_delete_all">Удалить все</string>
|
||||||
|
<string name="report_delete">Удалить</string>
|
||||||
|
<string name="report_share">Поделиться</string>
|
||||||
|
<string name="report_share_with_config">Поделиться с конфигурацией</string>
|
||||||
|
<string name="report_metadata">Метаданные</string>
|
||||||
|
<string name="report_configuration">Конфигурация</string>
|
||||||
|
<string name="report_origin_local">Локальный</string>
|
||||||
|
<string name="service_not_started">Служба не запущена</string>
|
||||||
|
<string name="service_reload_required">Для применения изменений необходимо перезагрузить сервис</string>
|
||||||
|
<string name="service_restart_required">Для применения изменений необходимо перезапустить сервис</string>
|
||||||
|
|
||||||
|
<!-- Crash Report -->
|
||||||
|
<string name="crash_report">Отчёт о сбое</string>
|
||||||
|
<string name="crash_report_go_log">Go Crash Log</string>
|
||||||
|
<string name="crash_report_jvm_log">JVM Crash Log</string>
|
||||||
|
<string name="crash_report_description">Вы получите отчёт при возникновении сбоя.</string>
|
||||||
|
|
||||||
|
<!-- OOM Report -->
|
||||||
|
<string name="oom_report">Отчёт о нехватке памяти</string>
|
||||||
|
<string name="oom_report_description">При включённом ограничении памяти вы получите отчёт, если память сервиса превысит лимит. Вы также можете вручную запросить сбор отчёта.</string>
|
||||||
|
<string name="oom_report_fetch">Получить отчёт о памяти</string>
|
||||||
|
<string name="oom_report_enable_memory_limit">Включить ограничение памяти</string>
|
||||||
|
<string name="oom_report_enable_memory_limit_description">Задайте мягкое ограничение памяти для сервиса. Сервис будет выполнять различные процессы, чтобы оставаться в пределах этого ограничения.</string>
|
||||||
|
<string name="oom_report_memory_limit">Ограничение памяти</string>
|
||||||
|
<string name="oom_report_kill_connections">Завершить соединения</string>
|
||||||
|
<string name="oom_report_kill_connections_description">Завершить все соединения для освобождения памяти при превышении лимита памяти сервиса.</string>
|
||||||
|
|
||||||
<!-- Xposed Module -->
|
<!-- Xposed Module -->
|
||||||
<string name="xposed_description">Привилегированное расширение для sing-box</string>
|
<string name="xposed_description">Привилегированное расширение для sing-box</string>
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
<string name="action">操作</string>
|
<string name="action">操作</string>
|
||||||
<string name="action_start">启动</string>
|
<string name="action_start">启动</string>
|
||||||
<string name="action_deselect">取消选择</string>
|
<string name="action_deselect">取消选择</string>
|
||||||
|
<string name="action_reload">重载</string>
|
||||||
|
<string name="action_restart">重启</string>
|
||||||
<string name="expand">展开</string>
|
<string name="expand">展开</string>
|
||||||
<string name="collapse">收起</string>
|
<string name="collapse">收起</string>
|
||||||
<string name="expand_all">全部展开</string>
|
<string name="expand_all">全部展开</string>
|
||||||
@@ -66,7 +68,7 @@
|
|||||||
<string name="status_started">已启动</string>
|
<string name="status_started">已启动</string>
|
||||||
|
|
||||||
<!-- Dashboard -->
|
<!-- Dashboard -->
|
||||||
<string name="dashboard_items">仪表项目</string>
|
<string name="dashboard_items">仪表项</string>
|
||||||
<string name="memory">内存</string>
|
<string name="memory">内存</string>
|
||||||
<string name="goroutines">协程</string>
|
<string name="goroutines">协程</string>
|
||||||
<string name="upload">上传</string>
|
<string name="upload">上传</string>
|
||||||
@@ -86,7 +88,7 @@
|
|||||||
<string name="search_connections">搜索连接…</string>
|
<string name="search_connections">搜索连接…</string>
|
||||||
<string name="close_connections_confirm">关闭所有连接?</string>
|
<string name="close_connections_confirm">关闭所有连接?</string>
|
||||||
<string name="connection_state_all">全部</string>
|
<string name="connection_state_all">全部</string>
|
||||||
<string name="connection_state_active">活跃</string>
|
<string name="connection_state_active">活动</string>
|
||||||
<string name="connection_state_closed">已关闭</string>
|
<string name="connection_state_closed">已关闭</string>
|
||||||
<string name="connection_sort_date">日期</string>
|
<string name="connection_sort_date">日期</string>
|
||||||
<string name="connection_sort_traffic">流量</string>
|
<string name="connection_sort_traffic">流量</string>
|
||||||
@@ -421,6 +423,94 @@
|
|||||||
<string name="content_description_collapse_search">折叠搜索</string>
|
<string name="content_description_collapse_search">折叠搜索</string>
|
||||||
<string name="content_description_search_logs">搜索日志</string>
|
<string name="content_description_search_logs">搜索日志</string>
|
||||||
|
|
||||||
|
<!-- Tools -->
|
||||||
|
<string name="title_tools">工具</string>
|
||||||
|
<string name="title_network">网络</string>
|
||||||
|
<string name="network_quality">网络质量</string>
|
||||||
|
<string name="network_quality_url">URL</string>
|
||||||
|
<string name="network_quality_serial">串行</string>
|
||||||
|
<string name="network_quality_http3">HTTP/3</string>
|
||||||
|
<string name="network_quality_max_runtime">最大运行时间</string>
|
||||||
|
<string name="network_quality_max_runtime_30s">30s</string>
|
||||||
|
<string name="network_quality_max_runtime_60s">60s</string>
|
||||||
|
<string name="network_quality_start">开始测试</string>
|
||||||
|
<string name="network_quality_cancel">取消测试</string>
|
||||||
|
<string name="network_quality_idle_latency">空闲延迟</string>
|
||||||
|
<string name="network_quality_download">下载</string>
|
||||||
|
<string name="network_quality_upload">上传</string>
|
||||||
|
<string name="network_quality_download_rpm">下载 RPM</string>
|
||||||
|
<string name="network_quality_upload_rpm">上传 RPM</string>
|
||||||
|
<string name="network_quality_confidence_high">置信度高</string>
|
||||||
|
<string name="network_quality_confidence_medium">置信度中</string>
|
||||||
|
<string name="network_quality_confidence_low">置信度低</string>
|
||||||
|
<string name="network_quality_metered_title">按流量计费连接</string>
|
||||||
|
<string name="network_quality_metered_message">您正在使用按流量计费的连接。此测试将消耗大量数据。</string>
|
||||||
|
<string name="network_quality_metered_continue">继续</string>
|
||||||
|
<string name="tool_configuration">配置</string>
|
||||||
|
<string name="tool_results">结果</string>
|
||||||
|
<string name="tool_outbound">出站</string>
|
||||||
|
<string name="tool_default_outbound">默认</string>
|
||||||
|
|
||||||
|
<!-- STUN Test -->
|
||||||
|
<!-- Tailscale -->
|
||||||
|
<string name="tailscale_endpoints">端点</string>
|
||||||
|
|
||||||
|
<string name="tailscale_status">状态</string>
|
||||||
|
<string name="tailscale_state">状态</string>
|
||||||
|
<string name="tailscale_network">网络</string>
|
||||||
|
<string name="tailscale_open_auth_url">打开认证链接</string>
|
||||||
|
<string name="tailscale_open_auth_url_qr_code">显示认证链接二维码</string>
|
||||||
|
<string name="tailscale_this_device">此设备</string>
|
||||||
|
<string name="tailscale_connected">已连接</string>
|
||||||
|
<string name="tailscale_not_connected">未连接</string>
|
||||||
|
<string name="tailscale_addresses">Tailscale 地址</string>
|
||||||
|
<string name="tailscale_details">详情</string>
|
||||||
|
<string name="tailscale_key_expiry">密钥过期</string>
|
||||||
|
<string name="tailscale_exit_node">出口节点</string>
|
||||||
|
<string name="tailscale_active">活跃</string>
|
||||||
|
|
||||||
|
<string name="stun_test">STUN 测试</string>
|
||||||
|
<string name="stun_server">服务器</string>
|
||||||
|
<string name="stun_start">开始测试</string>
|
||||||
|
<string name="stun_cancel">取消测试</string>
|
||||||
|
<string name="stun_external_address">外部地址</string>
|
||||||
|
<string name="stun_latency">延迟</string>
|
||||||
|
<string name="stun_nat_mapping">NAT 映射</string>
|
||||||
|
<string name="stun_nat_filtering">NAT 过滤</string>
|
||||||
|
<string name="stun_nat_type_detection">NAT 类型检测</string>
|
||||||
|
<string name="stun_nat_not_supported">服务器不支持</string>
|
||||||
|
|
||||||
|
<!-- Shared Report -->
|
||||||
|
<string name="report_empty">空</string>
|
||||||
|
<string name="report_section_reports">报告</string>
|
||||||
|
<string name="report_section_files">文件</string>
|
||||||
|
<string name="report_delete_all">全部删除</string>
|
||||||
|
<string name="report_delete">删除</string>
|
||||||
|
<string name="report_share">分享</string>
|
||||||
|
<string name="report_share_with_config">附带配置分享</string>
|
||||||
|
<string name="report_metadata">元数据</string>
|
||||||
|
<string name="report_configuration">配置</string>
|
||||||
|
<string name="report_origin_local">本地</string>
|
||||||
|
<string name="service_not_started">服务未启动</string>
|
||||||
|
<string name="service_reload_required">需要重载服务以应用更改</string>
|
||||||
|
<string name="service_restart_required">需要重启服务以应用更改</string>
|
||||||
|
|
||||||
|
<!-- Crash Report -->
|
||||||
|
<string name="crash_report">崩溃报告</string>
|
||||||
|
<string name="crash_report_go_log">Go Crash Log</string>
|
||||||
|
<string name="crash_report_jvm_log">JVM Crash Log</string>
|
||||||
|
<string name="crash_report_description">当遇到崩溃时,您将会收到报告。</string>
|
||||||
|
|
||||||
|
<!-- OOM Report -->
|
||||||
|
<string name="oom_report">内存不足报告</string>
|
||||||
|
<string name="oom_report_description">启用内存限制后,当服务内存超出限制时,您将会收到报告。您也可以手动触发收集报告。</string>
|
||||||
|
<string name="oom_report_fetch">获取内存报告</string>
|
||||||
|
<string name="oom_report_enable_memory_limit">启用内存限制</string>
|
||||||
|
<string name="oom_report_enable_memory_limit_description">为服务提供软内存限制。服务将执行多个进程以尝试保持在此内存限制范围内。</string>
|
||||||
|
<string name="oom_report_memory_limit">内存限制</string>
|
||||||
|
<string name="oom_report_kill_connections">终止连接</string>
|
||||||
|
<string name="oom_report_kill_connections_description">当服务内存超出限制时,终止所有连接以释放内存。</string>
|
||||||
|
|
||||||
<!-- Xposed Module -->
|
<!-- Xposed Module -->
|
||||||
<string name="xposed_description">sing-box 的特权增强</string>
|
<string name="xposed_description">sing-box 的特权增强</string>
|
||||||
<!-- Privileged Enhancement -->
|
<!-- Privileged Enhancement -->
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
<string name="action">操作</string>
|
<string name="action">操作</string>
|
||||||
<string name="action_start">啟動</string>
|
<string name="action_start">啟動</string>
|
||||||
<string name="action_deselect">取消選擇</string>
|
<string name="action_deselect">取消選擇</string>
|
||||||
|
<string name="action_reload">重新載入</string>
|
||||||
|
<string name="action_restart">重新啟動</string>
|
||||||
<string name="expand">展開</string>
|
<string name="expand">展開</string>
|
||||||
<string name="collapse">收合</string>
|
<string name="collapse">收合</string>
|
||||||
<string name="expand_all">全部展開</string>
|
<string name="expand_all">全部展開</string>
|
||||||
@@ -45,7 +47,7 @@
|
|||||||
<string name="default_text">預設</string>
|
<string name="default_text">預設</string>
|
||||||
|
|
||||||
<!-- Navigation Titles -->
|
<!-- Navigation Titles -->
|
||||||
<string name="title_dashboard">儀表板</string>
|
<string name="title_dashboard">儀表</string>
|
||||||
<string name="title_configuration">設定檔</string>
|
<string name="title_configuration">設定檔</string>
|
||||||
<string name="title_log">日誌</string>
|
<string name="title_log">日誌</string>
|
||||||
<string name="title_settings">設定</string>
|
<string name="title_settings">設定</string>
|
||||||
@@ -66,7 +68,7 @@
|
|||||||
<string name="status_started">已啟動</string>
|
<string name="status_started">已啟動</string>
|
||||||
|
|
||||||
<!-- Dashboard -->
|
<!-- Dashboard -->
|
||||||
<string name="dashboard_items">儀表板項目</string>
|
<string name="dashboard_items">儀表項</string>
|
||||||
<string name="memory">記憶體</string>
|
<string name="memory">記憶體</string>
|
||||||
<string name="goroutines">協程</string>
|
<string name="goroutines">協程</string>
|
||||||
<string name="upload">上傳</string>
|
<string name="upload">上傳</string>
|
||||||
@@ -86,7 +88,7 @@
|
|||||||
<string name="search_connections">搜尋連線…</string>
|
<string name="search_connections">搜尋連線…</string>
|
||||||
<string name="close_connections_confirm">關閉所有連線?</string>
|
<string name="close_connections_confirm">關閉所有連線?</string>
|
||||||
<string name="connection_state_all">全部</string>
|
<string name="connection_state_all">全部</string>
|
||||||
<string name="connection_state_active">活躍</string>
|
<string name="connection_state_active">活動</string>
|
||||||
<string name="connection_state_closed">已關閉</string>
|
<string name="connection_state_closed">已關閉</string>
|
||||||
<string name="connection_sort_date">日期</string>
|
<string name="connection_sort_date">日期</string>
|
||||||
<string name="connection_sort_traffic">流量</string>
|
<string name="connection_sort_traffic">流量</string>
|
||||||
@@ -424,6 +426,94 @@
|
|||||||
<string name="content_description_collapse_search">收合搜尋</string>
|
<string name="content_description_collapse_search">收合搜尋</string>
|
||||||
<string name="content_description_search_logs">搜尋日誌</string>
|
<string name="content_description_search_logs">搜尋日誌</string>
|
||||||
|
|
||||||
|
<!-- Tools -->
|
||||||
|
<string name="title_tools">工具</string>
|
||||||
|
<string name="title_network">網路</string>
|
||||||
|
<string name="network_quality">網路品質</string>
|
||||||
|
<string name="network_quality_url">URL</string>
|
||||||
|
<string name="network_quality_serial">序列</string>
|
||||||
|
<string name="network_quality_http3">HTTP/3</string>
|
||||||
|
<string name="network_quality_max_runtime">最大執行時間</string>
|
||||||
|
<string name="network_quality_max_runtime_30s">30s</string>
|
||||||
|
<string name="network_quality_max_runtime_60s">60s</string>
|
||||||
|
<string name="network_quality_start">開始測試</string>
|
||||||
|
<string name="network_quality_cancel">取消測試</string>
|
||||||
|
<string name="network_quality_idle_latency">閒置延遲</string>
|
||||||
|
<string name="network_quality_download">下載</string>
|
||||||
|
<string name="network_quality_upload">上傳</string>
|
||||||
|
<string name="network_quality_download_rpm">下載 RPM</string>
|
||||||
|
<string name="network_quality_upload_rpm">上傳 RPM</string>
|
||||||
|
<string name="network_quality_confidence_high">置信度高</string>
|
||||||
|
<string name="network_quality_confidence_medium">置信度中</string>
|
||||||
|
<string name="network_quality_confidence_low">置信度低</string>
|
||||||
|
<string name="network_quality_metered_title">按流量計費連線</string>
|
||||||
|
<string name="network_quality_metered_message">您正在使用按流量計費的連線。此測試將消耗大量數據。</string>
|
||||||
|
<string name="network_quality_metered_continue">繼續</string>
|
||||||
|
<string name="tool_configuration">配置</string>
|
||||||
|
<string name="tool_results">結果</string>
|
||||||
|
<string name="tool_outbound">出站</string>
|
||||||
|
<string name="tool_default_outbound">默認</string>
|
||||||
|
|
||||||
|
<!-- STUN Test -->
|
||||||
|
<!-- Tailscale -->
|
||||||
|
<string name="tailscale_endpoints">端點</string>
|
||||||
|
|
||||||
|
<string name="tailscale_status">狀態</string>
|
||||||
|
<string name="tailscale_state">狀態</string>
|
||||||
|
<string name="tailscale_network">網路</string>
|
||||||
|
<string name="tailscale_open_auth_url">開啟認證連結</string>
|
||||||
|
<string name="tailscale_open_auth_url_qr_code">顯示認證連結 QR 碼</string>
|
||||||
|
<string name="tailscale_this_device">此裝置</string>
|
||||||
|
<string name="tailscale_connected">已連線</string>
|
||||||
|
<string name="tailscale_not_connected">未連線</string>
|
||||||
|
<string name="tailscale_addresses">Tailscale 位址</string>
|
||||||
|
<string name="tailscale_details">詳情</string>
|
||||||
|
<string name="tailscale_key_expiry">金鑰到期</string>
|
||||||
|
<string name="tailscale_exit_node">出口節點</string>
|
||||||
|
<string name="tailscale_active">活躍</string>
|
||||||
|
|
||||||
|
<string name="stun_test">STUN 測試</string>
|
||||||
|
<string name="stun_server">伺服器</string>
|
||||||
|
<string name="stun_start">開始測試</string>
|
||||||
|
<string name="stun_cancel">取消測試</string>
|
||||||
|
<string name="stun_external_address">外部地址</string>
|
||||||
|
<string name="stun_latency">延遲</string>
|
||||||
|
<string name="stun_nat_mapping">NAT 映射</string>
|
||||||
|
<string name="stun_nat_filtering">NAT 過濾</string>
|
||||||
|
<string name="stun_nat_type_detection">NAT 類型偵測</string>
|
||||||
|
<string name="stun_nat_not_supported">伺服器不支援</string>
|
||||||
|
|
||||||
|
<!-- Shared Report -->
|
||||||
|
<string name="report_empty">空</string>
|
||||||
|
<string name="report_section_reports">報告</string>
|
||||||
|
<string name="report_section_files">檔案</string>
|
||||||
|
<string name="report_delete_all">全部刪除</string>
|
||||||
|
<string name="report_delete">刪除</string>
|
||||||
|
<string name="report_share">分享</string>
|
||||||
|
<string name="report_share_with_config">附帶配置分享</string>
|
||||||
|
<string name="report_metadata">元數據</string>
|
||||||
|
<string name="report_configuration">配置</string>
|
||||||
|
<string name="report_origin_local">本地</string>
|
||||||
|
<string name="service_not_started">服務未啟動</string>
|
||||||
|
<string name="service_reload_required">需要重新載入服務以套用變更</string>
|
||||||
|
<string name="service_restart_required">需要重新啟動服務以套用變更</string>
|
||||||
|
|
||||||
|
<!-- Crash Report -->
|
||||||
|
<string name="crash_report">當機報告</string>
|
||||||
|
<string name="crash_report_go_log">Go Crash Log</string>
|
||||||
|
<string name="crash_report_jvm_log">JVM Crash Log</string>
|
||||||
|
<string name="crash_report_description">當發生當機時,您將會收到報告。</string>
|
||||||
|
|
||||||
|
<!-- OOM Report -->
|
||||||
|
<string name="oom_report">記憶體不足報告</string>
|
||||||
|
<string name="oom_report_description">啟用記憶體限制後,當服務記憶體超出限制時,您將會收到報告。您也可以手動觸發收集報告。</string>
|
||||||
|
<string name="oom_report_fetch">取得記憶體報告</string>
|
||||||
|
<string name="oom_report_enable_memory_limit">啟用記憶體限制</string>
|
||||||
|
<string name="oom_report_enable_memory_limit_description">為服務提供軟記憶體限制。服務將執行多個程序以嘗試保持在此記憶體限制範圍內。</string>
|
||||||
|
<string name="oom_report_memory_limit">記憶體限制</string>
|
||||||
|
<string name="oom_report_kill_connections">終止連線</string>
|
||||||
|
<string name="oom_report_kill_connections_description">當服務記憶體超出限制時,終止所有連線以釋放記憶體。</string>
|
||||||
|
|
||||||
<!-- Xposed Module -->
|
<!-- Xposed Module -->
|
||||||
<string name="xposed_description">sing-box 的特權強化</string>
|
<string name="xposed_description">sing-box 的特權強化</string>
|
||||||
<!-- Privileged Enhancement -->
|
<!-- Privileged Enhancement -->
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
<string name="action">Action</string>
|
<string name="action">Action</string>
|
||||||
<string name="action_start">Start</string>
|
<string name="action_start">Start</string>
|
||||||
<string name="action_deselect">Deselect</string>
|
<string name="action_deselect">Deselect</string>
|
||||||
|
<string name="action_reload">Reload</string>
|
||||||
|
<string name="action_restart">Restart</string>
|
||||||
<string name="expand">Expand</string>
|
<string name="expand">Expand</string>
|
||||||
<string name="collapse">Collapse</string>
|
<string name="collapse">Collapse</string>
|
||||||
<string name="expand_all">Expand All</string>
|
<string name="expand_all">Expand All</string>
|
||||||
@@ -424,6 +426,105 @@
|
|||||||
<string name="content_description_collapse_search">Collapse search</string>
|
<string name="content_description_collapse_search">Collapse search</string>
|
||||||
<string name="content_description_search_logs">Search logs</string>
|
<string name="content_description_search_logs">Search logs</string>
|
||||||
|
|
||||||
|
<!-- Tools -->
|
||||||
|
<string name="title_tools">Tools</string>
|
||||||
|
<string name="title_network">Network</string>
|
||||||
|
<string name="network_quality">Network Quality</string>
|
||||||
|
<string name="network_quality_url">URL</string>
|
||||||
|
<string name="network_quality_serial">Serial</string>
|
||||||
|
<string name="network_quality_http3">HTTP/3</string>
|
||||||
|
<string name="network_quality_max_runtime">Max Runtime</string>
|
||||||
|
<string name="network_quality_max_runtime_30s">30s</string>
|
||||||
|
<string name="network_quality_max_runtime_60s">60s</string>
|
||||||
|
<string name="network_quality_start">Start Test</string>
|
||||||
|
<string name="network_quality_cancel">Cancel Test</string>
|
||||||
|
<string name="network_quality_idle_latency">Idle Latency</string>
|
||||||
|
<string name="network_quality_download">Download</string>
|
||||||
|
<string name="network_quality_upload">Upload</string>
|
||||||
|
<string name="network_quality_download_rpm">Download RPM</string>
|
||||||
|
<string name="network_quality_upload_rpm">Upload RPM</string>
|
||||||
|
<string name="network_quality_confidence_high">Confidence High</string>
|
||||||
|
<string name="network_quality_confidence_medium">Confidence Medium</string>
|
||||||
|
<string name="network_quality_confidence_low">Confidence Low</string>
|
||||||
|
<string name="network_quality_metered_title">Metered Connection</string>
|
||||||
|
<string name="network_quality_metered_message">You\'re on a metered connection. This test will use a significant amount of data.</string>
|
||||||
|
<string name="network_quality_metered_continue">Continue</string>
|
||||||
|
<string name="tool_configuration">Configuration</string>
|
||||||
|
<string name="tool_results">Results</string>
|
||||||
|
<string name="tool_outbound">Outbound</string>
|
||||||
|
<string name="tool_default_outbound">Default</string>
|
||||||
|
|
||||||
|
<!-- Tailscale -->
|
||||||
|
<string name="tailscale" translatable="false">Tailscale</string>
|
||||||
|
<string name="tailscale_with_tag" translatable="false">Tailscale: %s</string>
|
||||||
|
<string name="tailscale_endpoints">Endpoints</string>
|
||||||
|
|
||||||
|
<string name="tailscale_status">Status</string>
|
||||||
|
<string name="tailscale_state">State</string>
|
||||||
|
<string name="tailscale_network">Network</string>
|
||||||
|
<string name="tailscale_magic_dns" translatable="false">MagicDNS</string>
|
||||||
|
<string name="tailscale_open_auth_url">Open Auth URL</string>
|
||||||
|
<string name="tailscale_open_auth_url_qr_code">Show Auth URL QR Code</string>
|
||||||
|
<string name="tailscale_this_device">This Device</string>
|
||||||
|
<string name="tailscale_connected">Connected</string>
|
||||||
|
<string name="tailscale_not_connected">Not Connected</string>
|
||||||
|
<string name="tailscale_addresses">Tailscale Addresses</string>
|
||||||
|
<string name="tailscale_details">Details</string>
|
||||||
|
<string name="tailscale_key_expiry">Key Expiry</string>
|
||||||
|
<string name="tailscale_os" translatable="false">OS</string>
|
||||||
|
<string name="tailscale_exit_node">Exit Node</string>
|
||||||
|
<string name="tailscale_active">Active</string>
|
||||||
|
<string name="tailscale_ipv4" translatable="false">IPv4</string>
|
||||||
|
<string name="tailscale_ipv6" translatable="false">IPv6</string>
|
||||||
|
<string name="tailscale_ping">Ping</string>
|
||||||
|
<string name="tailscale_ping_start">Start</string>
|
||||||
|
<string name="tailscale_ping_stop">Stop</string>
|
||||||
|
<string name="tailscale_ping_direct">Direct connection</string>
|
||||||
|
<string name="tailscale_ping_derp">DERP-relayed connection</string>
|
||||||
|
|
||||||
|
<!-- STUN Test -->
|
||||||
|
<string name="stun_test">STUN Test</string>
|
||||||
|
<string name="stun_server">Server</string>
|
||||||
|
<string name="stun_start">Start Test</string>
|
||||||
|
<string name="stun_cancel">Cancel Test</string>
|
||||||
|
<string name="stun_external_address">External Address</string>
|
||||||
|
<string name="stun_latency">Latency</string>
|
||||||
|
<string name="stun_nat_mapping">NAT Mapping</string>
|
||||||
|
<string name="stun_nat_filtering">NAT Filtering</string>
|
||||||
|
<string name="stun_nat_type_detection">NAT Type Detection</string>
|
||||||
|
<string name="stun_nat_not_supported">Not supported by server</string>
|
||||||
|
|
||||||
|
<!-- Shared Report -->
|
||||||
|
<string name="report_empty">Empty</string>
|
||||||
|
<string name="report_section_reports">Reports</string>
|
||||||
|
<string name="report_section_files">Files</string>
|
||||||
|
<string name="report_delete_all">Delete All</string>
|
||||||
|
<string name="report_delete">Delete</string>
|
||||||
|
<string name="report_share">Share</string>
|
||||||
|
<string name="report_share_with_config">Share With Configuration</string>
|
||||||
|
<string name="report_metadata">Metadata</string>
|
||||||
|
<string name="report_configuration">Configuration</string>
|
||||||
|
<string name="report_origin_local">Local</string>
|
||||||
|
<string name="service_not_started">Service not started</string>
|
||||||
|
<string name="service_reload_required">Reload service to apply changes</string>
|
||||||
|
<string name="service_restart_required">Restart service to apply changes</string>
|
||||||
|
|
||||||
|
<!-- Crash Report -->
|
||||||
|
<string name="crash_report">Crash Report</string>
|
||||||
|
<string name="crash_report_go_log">Go Crash Log</string>
|
||||||
|
<string name="crash_report_jvm_log">JVM Crash Log</string>
|
||||||
|
<string name="crash_report_description">You will receive a report when a crash occurs.</string>
|
||||||
|
|
||||||
|
<!-- OOM Report -->
|
||||||
|
<string name="oom_report">OOM Report</string>
|
||||||
|
<string name="oom_report_description">When memory limit is enabled, you will receive a report if the service memory exceeds the limit. You can also manually trigger report collection.</string>
|
||||||
|
<string name="oom_report_fetch">Fetch Memory Report</string>
|
||||||
|
<string name="oom_report_enable_memory_limit">Enable Memory Limit</string>
|
||||||
|
<string name="oom_report_enable_memory_limit_description">Provide a soft memory limit for the service. The service will perform multiple processes to try to stay within this memory limit.</string>
|
||||||
|
<string name="oom_report_memory_limit">Memory Limit</string>
|
||||||
|
<string name="oom_report_kill_connections">Kill Connections</string>
|
||||||
|
<string name="oom_report_kill_connections_description">Kill all connections to free memory when the service memory exceeds the limit.</string>
|
||||||
|
|
||||||
<!-- Xposed Module -->
|
<!-- Xposed Module -->
|
||||||
<string name="xposed_description">Privileged Enhancement for sing-box</string>
|
<string name="xposed_description">Privileged Enhancement for sing-box</string>
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -1,5 +1,4 @@
|
|||||||
VERSION_CODE=662
|
VERSION_CODE=627
|
||||||
VERSION_NAME=1.13.11
|
VERSION_NAME=1.13.0-rc.7
|
||||||
GO_VERSION=go1.25.9
|
GO_VERSION=go1.25.7
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user