细化+上游代理+1.1
This commit is contained in:
+28
-7
@@ -6,7 +6,7 @@ plugins {
|
||||
id("org.jetbrains.kotlin.plugin.compose")
|
||||
}
|
||||
|
||||
val minSdk = 28
|
||||
val appMinSdk = 28
|
||||
|
||||
android {
|
||||
namespace = "net.bluemangoo.indpjsk"
|
||||
@@ -16,7 +16,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "net.bluemangoo.indpjsk"
|
||||
minSdk = minSdk
|
||||
minSdk = appMinSdk
|
||||
targetSdk = 37
|
||||
versionCode = 1
|
||||
versionName = "1.1"
|
||||
@@ -35,7 +35,29 @@ android {
|
||||
}
|
||||
buildFeatures {
|
||||
compose = true
|
||||
buildConfig = true
|
||||
}
|
||||
|
||||
sourceSets.getByName("main").assets.directories.add(
|
||||
layout.buildDirectory.dir("generated/readme").get().asFile.absolutePath
|
||||
)
|
||||
}
|
||||
|
||||
val copyReadmeToAssets = tasks.register<Copy>("copyReadmeToAssets") {
|
||||
group = "build"
|
||||
description = "Pack README.md"
|
||||
from(rootProject.file("README.md"))
|
||||
into(layout.buildDirectory.dir("generated/readme").get().asFile)
|
||||
rename { "README.md" }
|
||||
inputs.file(rootProject.file("README.md")).withPropertyName("readme")
|
||||
outputs.dir(layout.buildDirectory.dir("generated/readme")).withPropertyName("readmeAssets")
|
||||
}
|
||||
|
||||
tasks.named("preBuild") {
|
||||
dependsOn(copyReadmeToAssets)
|
||||
}
|
||||
tasks.matching { it.name.startsWith("merge") && it.name.contains("Assets") }.configureEach {
|
||||
dependsOn(copyReadmeToAssets)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -87,7 +109,6 @@ fun resolveNdkDirectory(project: Project): File {
|
||||
throw GradleException("Failed to find any installed NDK versions in ${ndkParentDir.absolutePath}")
|
||||
}
|
||||
|
||||
// 取最新安装的版本
|
||||
return installedVersions.last()
|
||||
}
|
||||
|
||||
@@ -117,19 +138,19 @@ val cargoBuildVpnCore = tasks.register<Exec>("cargoBuildVpnCore") {
|
||||
val execExt = if (OperatingSystem.current().isWindows) ".exe" else ""
|
||||
|
||||
environment("NDK_HOME", ndkHomePath)
|
||||
environment("PATH", "$ndkHomePath:${System.getenv("PATH")}")
|
||||
environment("PATH", "${ndkBin.absolutePath}${File.pathSeparator}${System.getenv("PATH")}")
|
||||
environment(
|
||||
"CC_aarch64-linux-android",
|
||||
ndkBin.resolve("aarch64-linux-android$minSdk-clang$scriptExt").absolutePath
|
||||
ndkBin.resolve("aarch64-linux-android$appMinSdk-clang$scriptExt").absolutePath
|
||||
)
|
||||
environment(
|
||||
"CXX_aarch64-linux-android",
|
||||
ndkBin.resolve("aarch64-linux-android$minSdk-clang++$scriptExt").absolutePath
|
||||
ndkBin.resolve("aarch64-linux-android$appMinSdk-clang++$scriptExt").absolutePath
|
||||
)
|
||||
environment("AR_aarch64-linux-android", ndkBin.resolve("llvm-ar$execExt").absolutePath)
|
||||
environment(
|
||||
"CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER",
|
||||
ndkBin.resolve("aarch64-linux-android$minSdk-clang$scriptExt").absolutePath
|
||||
ndkBin.resolve("aarch64-linux-android$appMinSdk-clang$scriptExt").absolutePath
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
logger.warn("[cargoBuildVpnCore] resolveNdkDirectory failed: ${e.message}")
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission
|
||||
android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||
tools:ignore="PackageVisibilityPolicy,QueryAllPackagesPermission" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
||||
@@ -6,15 +6,30 @@ import android.net.Uri
|
||||
import android.net.VpnService
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.core.content.FileProvider
|
||||
import net.bluemangoo.indpjsk.data.PredefinedProfiles
|
||||
import net.bluemangoo.indpjsk.data.SettingsStore
|
||||
import net.bluemangoo.indpjsk.state.CaptureStateHolder
|
||||
import net.bluemangoo.indpjsk.ui.AboutScreen
|
||||
import net.bluemangoo.indpjsk.ui.AppSelectionScreen
|
||||
import net.bluemangoo.indpjsk.ui.CaptureScreen
|
||||
import net.bluemangoo.indpjsk.ui.CaptureViewModel
|
||||
import net.bluemangoo.indpjsk.ui.CapturedFilesScreen
|
||||
import net.bluemangoo.indpjsk.ui.ProxySettingsScreen
|
||||
import net.bluemangoo.indpjsk.ui.theme.IndPjskTheme
|
||||
import java.io.File
|
||||
|
||||
enum class AppScreen { MAIN, PROXY, APP_SELECTION, FILES, ABOUT }
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
private val viewModel: CaptureViewModel by viewModels()
|
||||
@@ -28,15 +43,73 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
SettingsStore.loadSelectedProfileId(this)
|
||||
?.let { PredefinedProfiles.byId(it) }
|
||||
?.let { CaptureStateHolder.selectProfile(it) }
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
IndPjskTheme {
|
||||
CaptureScreen(
|
||||
viewModel = viewModel,
|
||||
onStartCapture = { requestVpnAndStart() },
|
||||
onStopCapture = { viewModel.stopCapture(this) },
|
||||
onOpenFile = { openCapturedFile(it) }
|
||||
)
|
||||
var screen by rememberSaveable { mutableStateOf(AppScreen.MAIN) }
|
||||
var bypassPackages by remember {
|
||||
mutableStateOf(SettingsStore.loadBypassPackages(this))
|
||||
}
|
||||
val readme = remember {
|
||||
runCatching {
|
||||
assets.open("README.md").bufferedReader().use { it.readText() }
|
||||
}.getOrDefault("(README 未打包)")
|
||||
}
|
||||
|
||||
BackHandler(enabled = screen != AppScreen.MAIN) {
|
||||
screen = when (screen) {
|
||||
AppScreen.APP_SELECTION -> AppScreen.PROXY
|
||||
else -> AppScreen.MAIN
|
||||
}
|
||||
}
|
||||
|
||||
when (screen) {
|
||||
AppScreen.MAIN -> CaptureScreen(
|
||||
viewModel = viewModel,
|
||||
onStartCapture = { requestVpnAndStart() },
|
||||
onStopCapture = { viewModel.stopCapture(this) },
|
||||
onOpenProxySettings = { screen = AppScreen.PROXY },
|
||||
onOpenFiles = { screen = AppScreen.FILES },
|
||||
onOpenAbout = { screen = AppScreen.ABOUT },
|
||||
)
|
||||
|
||||
AppScreen.PROXY -> ProxySettingsScreen(
|
||||
bypassPackages = bypassPackages,
|
||||
onBypassChange = { newSet ->
|
||||
bypassPackages = newSet
|
||||
SettingsStore.saveBypassPackages(this, newSet)
|
||||
},
|
||||
onSelectApps = { screen = AppScreen.APP_SELECTION },
|
||||
onBack = { screen = AppScreen.MAIN },
|
||||
)
|
||||
|
||||
AppScreen.APP_SELECTION -> AppSelectionScreen(
|
||||
selected = bypassPackages,
|
||||
onToggle = { entry ->
|
||||
bypassPackages = if (entry.packageName in bypassPackages) {
|
||||
bypassPackages - entry.packageName
|
||||
} else {
|
||||
bypassPackages + entry.packageName
|
||||
}
|
||||
SettingsStore.saveBypassPackages(this, bypassPackages)
|
||||
},
|
||||
onBack = { screen = AppScreen.PROXY },
|
||||
)
|
||||
|
||||
AppScreen.FILES -> CapturedFilesScreen(
|
||||
onOpenFile = { openCapturedFile(it) },
|
||||
onBack = { screen = AppScreen.MAIN },
|
||||
)
|
||||
|
||||
AppScreen.ABOUT -> AboutScreen(
|
||||
readme = readme,
|
||||
onBack = { screen = AppScreen.MAIN },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,4 +153,4 @@ class MainActivity : ComponentActivity() {
|
||||
"html", "htm" -> "text/html"
|
||||
else -> "application/octet-stream"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.bluemangoo.indpjsk.data
|
||||
|
||||
import android.content.Context
|
||||
import java.io.File
|
||||
|
||||
object CaptureFiles {
|
||||
|
||||
fun dir(context: Context): File = File(context.filesDir, "captures")
|
||||
|
||||
fun list(context: Context): List<File> {
|
||||
val root = dir(context)
|
||||
if (!root.exists()) return emptyList()
|
||||
return root.walkTopDown()
|
||||
.filter { it.isFile }
|
||||
.sortedByDescending { it.lastModified() }
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun clear(context: Context) {
|
||||
val root = dir(context)
|
||||
root.deleteRecursively()
|
||||
root.mkdirs()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.bluemangoo.indpjsk.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
data class AppEntry(
|
||||
val packageName: String,
|
||||
val label: String,
|
||||
val icon: Drawable,
|
||||
)
|
||||
|
||||
object InstalledApps {
|
||||
|
||||
fun list(context: Context): List<AppEntry> {
|
||||
val pm = context.packageManager
|
||||
return pm.getInstalledApplications(0)
|
||||
.asSequence()
|
||||
.filter { info ->
|
||||
(info.flags and ApplicationInfo.FLAG_SYSTEM) == 0 ||
|
||||
(info.flags and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0
|
||||
}
|
||||
.mapNotNull { info ->
|
||||
runCatching {
|
||||
AppEntry(
|
||||
packageName = info.packageName,
|
||||
label = pm.getApplicationLabel(info).toString(),
|
||||
icon = pm.getApplicationIcon(info),
|
||||
)
|
||||
}.getOrNull()
|
||||
}
|
||||
.distinctBy { it.packageName }
|
||||
.sortedBy { it.label.lowercase() }
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun get(context: Context, packageName: String): AppEntry? = runCatching {
|
||||
val pm = context.packageManager
|
||||
val info = pm.getApplicationInfo(packageName, 0)
|
||||
AppEntry(
|
||||
packageName = packageName,
|
||||
label = pm.getApplicationLabel(info).toString(),
|
||||
icon = pm.getApplicationIcon(info),
|
||||
)
|
||||
}.getOrNull()
|
||||
}
|
||||
@@ -3,21 +3,47 @@ package net.bluemangoo.indpjsk.data
|
||||
import android.content.Context
|
||||
import androidx.core.content.edit
|
||||
|
||||
/** 一些零碎的全局设置,暂时只有上传码 */
|
||||
/** 全局配置持久化:上传码、上游代理、忽略的应用、选中的配置 */
|
||||
object SettingsStore {
|
||||
|
||||
private const val PREFS = "settings"
|
||||
private const val KEY_UPLOAD_CODE = "upload_code"
|
||||
private const val KEY_PROXY = "upstream_proxy"
|
||||
private const val KEY_BYPASS = "bypass_packages"
|
||||
private const val KEY_PROFILE = "selected_profile"
|
||||
|
||||
fun loadUploadCode(context: Context): String =
|
||||
private fun prefs(context: Context) =
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
.getString(KEY_UPLOAD_CODE, "")
|
||||
.orEmpty()
|
||||
|
||||
// ---- 上传码 ----
|
||||
fun loadUploadCode(context: Context): String =
|
||||
prefs(context).getString(KEY_UPLOAD_CODE, "").orEmpty()
|
||||
|
||||
fun saveUploadCode(context: Context, code: String) {
|
||||
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
.edit {
|
||||
putString(KEY_UPLOAD_CODE, code)
|
||||
}
|
||||
prefs(context).edit { putString(KEY_UPLOAD_CODE, code) }
|
||||
}
|
||||
|
||||
// ---- 上游代理(空 = 直连) ----
|
||||
fun loadProxy(context: Context): String =
|
||||
prefs(context).getString(KEY_PROXY, "").orEmpty()
|
||||
|
||||
fun saveProxy(context: Context, proxy: String) {
|
||||
prefs(context).edit { putString(KEY_PROXY, proxy.trim()) }
|
||||
}
|
||||
|
||||
// ---- 不走 VPN 的应用(包名) ----
|
||||
fun loadBypassPackages(context: Context): Set<String> =
|
||||
prefs(context).getStringSet(KEY_BYPASS, emptySet())?.toSet() ?: emptySet()
|
||||
|
||||
fun saveBypassPackages(context: Context, packages: Set<String>) {
|
||||
prefs(context).edit { putStringSet(KEY_BYPASS, packages) }
|
||||
}
|
||||
|
||||
// ---- 当前选中的配置 ----
|
||||
fun loadSelectedProfileId(context: Context): String? =
|
||||
prefs(context).getString(KEY_PROFILE, null)
|
||||
|
||||
fun saveSelectedProfileId(context: Context, id: String) {
|
||||
prefs(context).edit { putString(KEY_PROFILE, id) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package net.bluemangoo.indpjsk.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
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.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.bluemangoo.indpjsk.BuildConfig
|
||||
import net.bluemangoo.indpjsk.R
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AboutScreen(
|
||||
readme: String,
|
||||
onBack: () -> Unit,
|
||||
) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text("关于") },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.arrow_back_24px),
|
||||
contentDescription = "返回"
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(padding)
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "Version ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})",
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
HorizontalDivider()
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(
|
||||
text = readme,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
softWrap = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.bluemangoo.indpjsk.ui
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
|
||||
@Composable
|
||||
fun AppIcon(icon: Drawable, label: String?, size: Dp = 40.dp) {
|
||||
val image = remember(icon) {
|
||||
runCatching { icon.toBitmap(96, 96) }.getOrNull()?.asImageBitmap()
|
||||
}
|
||||
if (image != null) {
|
||||
Image(bitmap = image, contentDescription = label, modifier = Modifier.size(size))
|
||||
} else {
|
||||
Box(modifier = Modifier.size(size))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package net.bluemangoo.indpjsk.ui
|
||||
|
||||
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.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
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.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import net.bluemangoo.indpjsk.R
|
||||
import net.bluemangoo.indpjsk.data.AppEntry
|
||||
import net.bluemangoo.indpjsk.data.InstalledApps
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AppSelectionScreen(
|
||||
selected: Set<String>,
|
||||
onToggle: (AppEntry) -> Unit,
|
||||
onBack: () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var allApps by remember { mutableStateOf<List<AppEntry>>(emptyList()) }
|
||||
var loading by remember { mutableStateOf(true) }
|
||||
var query by remember { mutableStateOf("") }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
val list = withContext(Dispatchers.IO) { InstalledApps.list(context) }
|
||||
allApps = list
|
||||
loading = false
|
||||
}
|
||||
|
||||
val filtered = remember(query, allApps) {
|
||||
if (query.isBlank()) {
|
||||
allApps
|
||||
} else {
|
||||
allApps.filter {
|
||||
it.label.contains(query, ignoreCase = true) ||
|
||||
it.packageName.contains(query, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text("选择忽略的应用") },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.arrow_back_24px),
|
||||
contentDescription = "返回"
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(padding)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = query,
|
||||
onValueChange = { query = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
placeholder = { Text("搜索应用名称或包名…") },
|
||||
singleLine = true
|
||||
)
|
||||
|
||||
if (loading) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxWidth(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
} else if (filtered.isEmpty()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxWidth(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
"没有找到相关的应用",
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
items(filtered, key = { it.packageName }) { app ->
|
||||
val checked = app.packageName in selected
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { onToggle(app) }
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
AppIcon(icon = app.icon, label = app.label)
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
Text(
|
||||
text = app.label,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text(
|
||||
text = app.packageName,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
Checkbox(
|
||||
checked = checked,
|
||||
onCheckedChange = { onToggle(app) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,13 @@
|
||||
package net.bluemangoo.indpjsk.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
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.width
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
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.OutlinedButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
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.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
@@ -58,7 +28,6 @@ import net.bluemangoo.indpjsk.state.CaptureStatus
|
||||
import net.bluemangoo.indpjsk.vpn.LogEntry
|
||||
import net.bluemangoo.indpjsk.vpn.LogLevel
|
||||
import net.bluemangoo.indpjsk.vpn.VpnLog
|
||||
import java.io.File
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -66,15 +35,18 @@ fun CaptureScreen(
|
||||
viewModel: CaptureViewModel,
|
||||
onStartCapture: () -> Unit,
|
||||
onStopCapture: () -> Unit,
|
||||
onOpenFile: (File) -> Unit
|
||||
onOpenProxySettings: () -> Unit,
|
||||
onOpenFiles: () -> Unit,
|
||||
onOpenAbout: () -> Unit,
|
||||
) {
|
||||
val state by viewModel.uiState.collectAsState()
|
||||
val logs by VpnLog.logs.collectAsState()
|
||||
var dropdownExpanded by remember { mutableStateOf(false) }
|
||||
|
||||
val context = LocalContext.current
|
||||
var enabledMap by remember { mutableStateOf(StepSelectionStore.loadAll(context) as Map<String, Boolean>) }
|
||||
var uploadCode by remember { mutableStateOf(SettingsStore.loadUploadCode(context)) }
|
||||
var menuExpanded by remember { mutableStateOf(false) }
|
||||
var profileExpanded by remember { mutableStateOf(false) }
|
||||
var showUploadCodeDialog by remember { mutableStateOf(false) }
|
||||
|
||||
val isRunning = state.status == CaptureStatus.RUNNING
|
||||
val isCaptured = state.status == CaptureStatus.CAPTURED
|
||||
@@ -85,40 +57,52 @@ fun CaptureScreen(
|
||||
TopAppBar(
|
||||
title = { Text("咖喱烧烤无ROOT抓包") },
|
||||
actions = {
|
||||
IconButton(onClick = { VpnLog.clear() }) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.delete_24px),
|
||||
contentDescription = "清空日志"
|
||||
)
|
||||
}
|
||||
Box {
|
||||
TextButton(
|
||||
onClick = { dropdownExpanded = true },
|
||||
enabled = !isRunning
|
||||
) {
|
||||
Text(
|
||||
text = selected?.name ?: "无配置",
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
IconButton(onClick = { menuExpanded = true }) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.arrow_drop_down_24px),
|
||||
contentDescription = null
|
||||
painter = painterResource(id = R.drawable.more_vert_24px),
|
||||
contentDescription = "菜单"
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = dropdownExpanded,
|
||||
onDismissRequest = { dropdownExpanded = false }
|
||||
expanded = menuExpanded,
|
||||
onDismissRequest = { menuExpanded = false }
|
||||
) {
|
||||
state.profiles.forEach { profile ->
|
||||
DropdownMenuItem(
|
||||
text = { Text(profile.name) },
|
||||
onClick = {
|
||||
viewModel.selectProfile(profile)
|
||||
dropdownExpanded = false
|
||||
}
|
||||
)
|
||||
}
|
||||
DropdownMenuItem(
|
||||
text = { Text("上传码") },
|
||||
onClick = {
|
||||
menuExpanded = false
|
||||
showUploadCodeDialog = true
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text("代理设置") },
|
||||
onClick = {
|
||||
menuExpanded = false
|
||||
onOpenProxySettings()
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text("已抓文件") },
|
||||
onClick = {
|
||||
menuExpanded = false
|
||||
onOpenFiles()
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text("清空日志") },
|
||||
onClick = {
|
||||
menuExpanded = false
|
||||
VpnLog.clear()
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text("关于") },
|
||||
onClick = {
|
||||
menuExpanded = false
|
||||
onOpenAbout()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,19 +116,40 @@ fun CaptureScreen(
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = uploadCode,
|
||||
onValueChange = {
|
||||
uploadCode = it.trim()
|
||||
SettingsStore.saveUploadCode(context, uploadCode)
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
enabled = !isRunning,
|
||||
singleLine = true,
|
||||
label = { Text("上传码(从 Haruki 工具箱 - 数据上传 - iOS 获取)") },
|
||||
textStyle = MaterialTheme.typography.bodyMedium,
|
||||
visualTransformation = PasswordVisualTransformation()
|
||||
)
|
||||
Box(modifier = Modifier.fillMaxWidth()) {
|
||||
OutlinedButton(
|
||||
onClick = { profileExpanded = true },
|
||||
enabled = !isRunning,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(48.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "配置:${selected?.name ?: "未选择"}",
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.arrow_drop_down_24px),
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = profileExpanded,
|
||||
onDismissRequest = { profileExpanded = false }
|
||||
) {
|
||||
state.profiles.forEach { profile ->
|
||||
DropdownMenuItem(
|
||||
text = { Text(profile.name) },
|
||||
onClick = {
|
||||
viewModel.selectProfile(context, profile)
|
||||
profileExpanded = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selected != null) {
|
||||
StepSelector(
|
||||
@@ -191,7 +196,11 @@ fun CaptureScreen(
|
||||
}
|
||||
|
||||
OutlinedButton(
|
||||
onClick = { state.lastCapturedFile?.let(onOpenFile) },
|
||||
onClick = {
|
||||
if (state.lastCapturedFile != null) {
|
||||
onOpenFiles()
|
||||
}
|
||||
},
|
||||
enabled = isCaptured && state.lastCapturedFile != null,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -206,6 +215,48 @@ fun CaptureScreen(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showUploadCodeDialog) {
|
||||
UploadCodeDialog(onDismiss = { showUploadCodeDialog = false })
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun UploadCodeDialog(onDismiss: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
var text by remember { mutableStateOf(SettingsStore.loadUploadCode(context)) }
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text("上传码") },
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
OutlinedTextField(
|
||||
value = text,
|
||||
onValueChange = { text = it.trim() },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
singleLine = true,
|
||||
label = { Text("Haruki 上传码") },
|
||||
visualTransformation = PasswordVisualTransformation(),
|
||||
textStyle = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
Text(
|
||||
text = "从 Haruki 工具箱 - 数据上传 - iOS 获取。",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
SettingsStore.saveUploadCode(context, text)
|
||||
onDismiss()
|
||||
}) { Text("保存") }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) { Text("取消") }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -328,4 +379,4 @@ private fun StatusLine(status: CaptureStatus, error: String?) {
|
||||
fontWeight = FontWeight.Medium
|
||||
)
|
||||
HorizontalDivider()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import net.bluemangoo.indpjsk.data.CaptureProfile
|
||||
import net.bluemangoo.indpjsk.data.PredefinedProfiles
|
||||
import net.bluemangoo.indpjsk.data.SettingsStore
|
||||
import net.bluemangoo.indpjsk.state.CaptureStateHolder
|
||||
import net.bluemangoo.indpjsk.state.CaptureStatus
|
||||
import net.bluemangoo.indpjsk.vpn.CaptureVpnService
|
||||
@@ -45,8 +46,9 @@ class CaptureViewModel : ViewModel() {
|
||||
)
|
||||
)
|
||||
|
||||
fun selectProfile(profile: CaptureProfile) {
|
||||
fun selectProfile(context: Context, profile: CaptureProfile) {
|
||||
CaptureStateHolder.selectProfile(profile)
|
||||
SettingsStore.saveSelectedProfileId(context, profile.id)
|
||||
}
|
||||
|
||||
fun startCapture(context: Context) {
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
package net.bluemangoo.indpjsk.ui
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
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.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
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.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.bluemangoo.indpjsk.R
|
||||
import net.bluemangoo.indpjsk.data.CaptureFiles
|
||||
import java.io.File
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun CapturedFilesScreen(
|
||||
onOpenFile: (File) -> Unit,
|
||||
onBack: () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var version by remember { mutableIntStateOf(0) }
|
||||
val files = remember(version) { CaptureFiles.list(context) }
|
||||
var confirmClear by remember { mutableStateOf(false) }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text("获取到的文件") },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.arrow_back_24px),
|
||||
contentDescription = "返回"
|
||||
)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(
|
||||
onClick = { confirmClear = true },
|
||||
enabled = files.isNotEmpty()
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.delete_24px),
|
||||
contentDescription = "清空"
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
if (files.isEmpty()) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(padding)
|
||||
.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
"还没有获取到文件",
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.padding(padding)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
items(files, key = { it.absolutePath }) { file ->
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { onOpenFile(file) }
|
||||
.padding(horizontal = 16.dp, vertical = 14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.file_open_24px),
|
||||
contentDescription = null
|
||||
)
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
Text(
|
||||
text = file.name,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (confirmClear) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { confirmClear = false },
|
||||
title = { Text("清空文件") },
|
||||
text = { Text("删除全部已获取的文件?") },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
CaptureFiles.clear(context)
|
||||
version++
|
||||
confirmClear = false
|
||||
}) { Text("删除") }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { confirmClear = false }) { Text("取消") }
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package net.bluemangoo.indpjsk.ui
|
||||
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.RectangleShape
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.bluemangoo.indpjsk.R
|
||||
import net.bluemangoo.indpjsk.data.AppEntry
|
||||
import net.bluemangoo.indpjsk.data.InstalledApps
|
||||
import net.bluemangoo.indpjsk.data.SettingsStore
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ProxySettingsScreen(
|
||||
bypassPackages: Set<String>,
|
||||
onBypassChange: (Set<String>) -> Unit,
|
||||
onSelectApps: () -> Unit,
|
||||
onBack: () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var proxy by remember { mutableStateOf(SettingsStore.loadProxy(context)) }
|
||||
var pendingRemove by remember { mutableStateOf<AppEntry?>(null) }
|
||||
|
||||
val entries = remember(bypassPackages) {
|
||||
bypassPackages.sorted().mapNotNull { InstalledApps.get(context, it) }
|
||||
}
|
||||
|
||||
val looksValid = proxy.isBlank() ||
|
||||
((proxy.startsWith("http://") || proxy.startsWith("https://")) && proxy.contains(":"))
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text("代理设置") },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.arrow_back_24px),
|
||||
contentDescription = "返回"
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(padding)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(horizontal = 0.dp, vertical = 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
|
||||
Text("上游代理", style = MaterialTheme.typography.labelLarge)
|
||||
OutlinedTextField(
|
||||
value = proxy,
|
||||
onValueChange = {
|
||||
proxy = it
|
||||
SettingsStore.saveProxy(context, it)
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
singleLine = true,
|
||||
label = { Text("上游代理地址") },
|
||||
placeholder = { Text("http://127.0.0.1:7890") },
|
||||
isError = !looksValid,
|
||||
supportingText = {
|
||||
Text(
|
||||
text = if (looksValid) {
|
||||
"留空以忽略;只支持 http / https 代理"
|
||||
} else {
|
||||
"格式示例:http://127.0.0.1:7890"
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
Text("绕过本应用代理的应用", style = MaterialTheme.typography.labelLarge)
|
||||
}
|
||||
|
||||
Card(
|
||||
onClick = onSelectApps,
|
||||
shape = RectangleShape,
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = Color.Transparent
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
text = "选择应用(${bypassPackages.size})",
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp)
|
||||
)
|
||||
}
|
||||
|
||||
if (entries.isEmpty()) {
|
||||
Text(
|
||||
text = "列表为空",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 16.dp, vertical = 0.dp)
|
||||
)
|
||||
} else {
|
||||
entries.forEach { entry ->
|
||||
BypassAppRow(entry = entry, onLongPress = { pendingRemove = entry })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pendingRemove?.let { entry ->
|
||||
AlertDialog(
|
||||
onDismissRequest = { pendingRemove = null },
|
||||
title = { Text("移除应用") },
|
||||
text = { Text("从应用列表移除「${entry.label}」?") },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
onBypassChange(bypassPackages - entry.packageName)
|
||||
pendingRemove = null
|
||||
}) { Text("移除") }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { pendingRemove = null }) { Text("取消") }
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BypassAppRow(entry: AppEntry, onLongPress: () -> Unit) {
|
||||
Card(
|
||||
shape = RectangleShape,
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = Color.Transparent
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.combinedClickable(
|
||||
onClick = {},
|
||||
onLongClick = onLongPress
|
||||
)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
|
||||
AppIcon(icon = entry.icon, label = entry.label, size = 32.dp)
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = entry.label,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text(
|
||||
text = entry.packageName,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,20 +19,6 @@ import net.bluemangoo.indpjsk.state.CaptureStateHolder
|
||||
import net.bluemangoo.indpjsk.upload.Uploader
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* 多步骤抓包:
|
||||
* establish() 只做一次,同一个 tun fd 按顺序喂给每一步,中间不拆 VPN。
|
||||
* 每一步抓到后异步跑它的 postAction(不阻塞下一步的监听)。
|
||||
*
|
||||
* 停止机制:
|
||||
* ACTION_STOP → requestStop() + close(activePfd),当前步骤的 runCapture 返回 null,
|
||||
* 循环发现 stopRequested 后终止后续步骤。
|
||||
*
|
||||
* fd 所有权:
|
||||
* 全生命周期在 Android 侧持有。传给 Rust 的是 pfd.fd(int 缓存值),
|
||||
* Rust 内部用 BorrowedAsyncDevice 借用,不做任何 close。
|
||||
* Android 在 finally 里统一 close(activePfd)。
|
||||
*/
|
||||
@SuppressLint("VpnServicePolicy")
|
||||
class CaptureVpnService : VpnService() {
|
||||
|
||||
@@ -44,14 +30,8 @@ class CaptureVpnService : VpnService() {
|
||||
|
||||
private const val VPN_ADDRESS = "10.7.0.2"
|
||||
private const val VPN_PREFIX = 32
|
||||
|
||||
/**
|
||||
* 后处理(上传)用的 scope:进程级,故意不随 Service 销毁取消。
|
||||
* 否则 stopSelf() → onDestroy 会把还在上传的分片掐掉(Job was cancelled)。
|
||||
*/
|
||||
private val postScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
|
||||
/** 捕获文件统一放在 filesDir/captures/<profileId>/ 下(file_paths.xml 的 FileProvider 路径) */
|
||||
fun captureFile(
|
||||
filesDir: File,
|
||||
profile: CaptureProfile,
|
||||
@@ -59,14 +39,12 @@ class CaptureVpnService : VpnService() {
|
||||
): File = File(File(File(filesDir, "captures"), profile.id), step.fileName)
|
||||
}
|
||||
|
||||
/** 工作线程持有;供 ACTION_STOP 从主线程关闭以中断 Rust */
|
||||
@Volatile
|
||||
private var activePfd: ParcelFileDescriptor? = null
|
||||
|
||||
@Volatile
|
||||
private var captureThread: Thread? = null
|
||||
|
||||
/** 区分"用户主动停止"与"抓到包后自然结束/失败" */
|
||||
@Volatile
|
||||
private var stopRequested = false
|
||||
|
||||
@@ -84,7 +62,6 @@ class CaptureVpnService : VpnService() {
|
||||
VpnLog.warn("手动停止…")
|
||||
VpnBridge.requestStop()
|
||||
closeActivePfd()
|
||||
// 立即把 UI 从 RUNNING 拉回来;capture 线程退出时还会再写一次
|
||||
CaptureStateHolder.setIdle()
|
||||
stopSelf()
|
||||
}
|
||||
@@ -111,7 +88,6 @@ class CaptureVpnService : VpnService() {
|
||||
return
|
||||
}
|
||||
|
||||
// 按 profile 里的顺序,过滤掉没勾选的步骤(默认全勾)
|
||||
val savedSelection = StepSelectionStore.loadAll(this)
|
||||
val enabledSteps = profile.steps.filter { step ->
|
||||
StepSelectionStore.isEnabled(savedSelection, profile.id, step.id)
|
||||
@@ -122,12 +98,18 @@ class CaptureVpnService : VpnService() {
|
||||
return
|
||||
}
|
||||
|
||||
// 上传码在开始时快照,运行中改 UI 不影响本次
|
||||
val uploadCode = SettingsStore.loadUploadCode(this).trim()
|
||||
if (uploadCode.isNotEmpty() && uploadCode.length != 32) {
|
||||
VpnLog.warn("上传码长度不是 32 位(当前 ${uploadCode.length} 位),上传大概率会失败")
|
||||
}
|
||||
|
||||
val proxy = SettingsStore.loadProxy(this).trim()
|
||||
val bypassPackages = SettingsStore.loadBypassPackages(this)
|
||||
if (proxy.isNotEmpty()) VpnLog.info("上游代理: $proxy")
|
||||
if (bypassPackages.isNotEmpty()) {
|
||||
VpnLog.info("忽略的应用: ${bypassPackages.joinToString(", ")}")
|
||||
}
|
||||
|
||||
stopRequested = false
|
||||
VpnLog.info("==== 开始抓包 ====")
|
||||
VpnLog.info("配置: ${profile.name}")
|
||||
@@ -144,11 +126,10 @@ class CaptureVpnService : VpnService() {
|
||||
throw IllegalStateException("Rust 动态库 core_vpn 未加载")
|
||||
}
|
||||
|
||||
// 2) 建立 VPN:仅 /32 目标路由 + 排除自身(防止 Rust 转发流量回环)
|
||||
val builder = Builder()
|
||||
.setSession("Capture-${profile.id}")
|
||||
.addAddress(VPN_ADDRESS, VPN_PREFIX)
|
||||
.addDisallowedApplication(packageName)// 1.0.0.0/8 (排除 0.0.0.0/8 本地识别地址)
|
||||
.addDisallowedApplication(packageName)
|
||||
.addRoute("1.0.0.0", 8)
|
||||
|
||||
.addRoute("2.0.0.0", 7)
|
||||
@@ -207,6 +188,12 @@ class CaptureVpnService : VpnService() {
|
||||
.addDnsServer("8.8.8.8")
|
||||
.addDnsServer("114.114.114.114")
|
||||
|
||||
for (pkg in bypassPackages) {
|
||||
if (pkg == packageName) continue
|
||||
runCatching { builder.addDisallowedApplication(pkg) }
|
||||
.onFailure { VpnLog.warn("忽略应用 $pkg 失败: ${it.message}") }
|
||||
}
|
||||
|
||||
pfd = builder.establish()
|
||||
?: throw IllegalStateException("VpnService.establish() 返回 null")
|
||||
activePfd = pfd
|
||||
@@ -224,12 +211,12 @@ class CaptureVpnService : VpnService() {
|
||||
target.parentFile?.mkdirs()
|
||||
if (target.exists()) target.delete()
|
||||
|
||||
// 阻塞调用 Rust,直到抓到本步骤的目标请求(或停止 / 出错)
|
||||
val capturedUrl = VpnBridge.runCapture(
|
||||
fd,
|
||||
step.hosts.joinToString(","),
|
||||
step.path,
|
||||
target.absolutePath
|
||||
target.absolutePath,
|
||||
proxy
|
||||
)
|
||||
|
||||
if (capturedUrl == null) {
|
||||
@@ -251,7 +238,6 @@ class CaptureVpnService : VpnService() {
|
||||
completed++
|
||||
VpnLog.success("$label 抓取成功")
|
||||
|
||||
// 抓到后异步做后处理(上传 / 该步骤自己的 postAction),不阻塞下一步监听
|
||||
val result = CaptureResult(profile, step, capturedUrl, target)
|
||||
postScope.launch {
|
||||
try {
|
||||
@@ -274,7 +260,6 @@ class CaptureVpnService : VpnService() {
|
||||
errorMsg = t.message ?: "抓包异常"
|
||||
VpnLog.error("抓包异常: ${t.message}")
|
||||
} finally {
|
||||
// 关闭 fd(若 ACTION_STOP 已关,这次 close 是幂等的/会抛可忽略异常)
|
||||
closeActivePfd()
|
||||
VpnLog.info("==== 抓包结束($completed/${enabledSteps.size} 步完成)====")
|
||||
|
||||
|
||||
@@ -6,10 +6,11 @@ import android.util.Log
|
||||
* Rust core_vpn 的 JNI 桥。
|
||||
*
|
||||
* 契约(由 Rust lib.rs 实现):
|
||||
* runCapture(jint tunFd, jstring targetHosts, jstring path, jstring savePath) -> String?
|
||||
* runCapture(jint tunFd, jstring targetHosts, jstring path, jstring savePath, jstring proxy) -> String?
|
||||
* - 阻塞直到抓包结束
|
||||
* - tunFd 的所有权【仍在 Kotlin 侧】,Rust 内部用 BorrowedAsyncDevice 借用,不得 close()
|
||||
* - targetHosts 是逗号分隔的域名白名单(一个步骤可能对应多个上游域名)
|
||||
* - proxy 可为 null / 空串(直连),否则必须是 http(s)://host:port 形式,Rust 侧会再校验一次
|
||||
* - 返回非 null = 抓到目标请求,值是命中的原始完整 URL(https://host/path?query),文件已写入 savePath
|
||||
* - 返回 null = 失败 / 被 requestStop 打断 / 未匹配
|
||||
*
|
||||
@@ -42,7 +43,8 @@ object VpnBridge {
|
||||
tunFd: Int,
|
||||
targetHosts: String,
|
||||
targetPath: String,
|
||||
savePath: String
|
||||
savePath: String,
|
||||
proxy: String?
|
||||
): String?
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:autoMirrored="true">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M313,520L537,744L480,800L160,480L480,160L537,216L313,440L800,440L800,520L313,520Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M480,800Q447,800 423.5,776.5Q400,753 400,720Q400,687 423.5,663.5Q447,640 480,640Q513,640 536.5,663.5Q560,687 560,720Q560,753 536.5,776.5Q513,800 480,800ZM480,560Q447,560 423.5,536.5Q400,513 400,480Q400,447 423.5,423.5Q447,400 480,400Q513,400 536.5,423.5Q560,447 560,480Q560,513 536.5,536.5Q513,560 480,560ZM480,320Q447,320 423.5,296.5Q400,273 400,240Q400,207 423.5,183.5Q447,160 480,160Q513,160 536.5,183.5Q560,207 560,240Q560,273 536.5,296.5Q513,320 480,320Z"/>
|
||||
</vector>
|
||||
Reference in New Issue
Block a user