Fix VPN internet connectivity and simplify client setup
Initialize Android physical interfaces and preserve macOS scoped routes. Add redacted diagnostics, default DNS, ordered auto-save, simplified controls, scanner rotation settings, and native regression coverage. Restore vendored build sources and document validation and stability checks.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<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.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
@@ -8,6 +9,10 @@
|
||||
android:label="MeshPort"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<!-- Override ZXing's sensorLandscape default and respect user rotation. -->
|
||||
<activity android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||
android:screenOrientation="fullUser"
|
||||
tools:replace="android:screenOrientation" />
|
||||
<service android:name=".MeshVpnService" android:exported="false"
|
||||
android:permission="android.permission.BIND_VPN_SERVICE" android:foregroundServiceType="specialUse">
|
||||
<intent-filter><action android:name="android.net.VpnService" /></intent-filter>
|
||||
|
||||
@@ -33,6 +33,13 @@ class MainActivity : FlutterActivity() {
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "meshport/system_vpn").setMethodCallHandler { call, result ->
|
||||
if (call.method == "runtime_log") {
|
||||
// Flutter redacts credentials before sending these bounded events.
|
||||
val text = call.arguments as? String ?: ""
|
||||
Log.i("MeshPortRuntime", text.take(4096))
|
||||
result.success(null)
|
||||
return@setMethodCallHandler
|
||||
}
|
||||
if (call.method in listOf("import_file", "import_qr_image", "scan_qr")) {
|
||||
if (importResult != null) { result.error("IMPORT_BUSY", "Import already open", null); return@setMethodCallHandler }
|
||||
importResult = result
|
||||
|
||||
+6
-1
@@ -40,7 +40,7 @@ class MeshVpnService : VpnService() {
|
||||
manager.createNotificationChannel(NotificationChannel("meshport_vpn", "MeshPort 组网", NotificationManager.IMPORTANCE_LOW))
|
||||
val open = PendingIntent.getActivity(this, 0, Intent(this, MainActivity::class.java), PendingIntent.FLAG_IMMUTABLE)
|
||||
startForeground(77, Notification.Builder(this, "meshport_vpn")
|
||||
.setContentTitle("MeshPort").setContentText("虚拟组网服务正在运行")
|
||||
.setContentTitle("MeshPort").setContentText("VPN 服务正在运行")
|
||||
.setSmallIcon(R.drawable.ic_stat_meshport).setContentIntent(open).setOngoing(true).build())
|
||||
worker.scheduleWithFixedDelay({
|
||||
if (running) try {
|
||||
@@ -177,6 +177,7 @@ class MeshVpnService : VpnService() {
|
||||
private fun startUnified(config: String) {
|
||||
val manager = getSystemService(ConnectivityManager::class.java)
|
||||
physical = physicalNetwork(); setUnderlyingNetworks(arrayOf(physical!!))
|
||||
Log.i("MeshPortVPN", "Unified VPN: physical network selected; mesh enabled=$meshEnabled")
|
||||
if (meshEnabled) {
|
||||
val validated = native(JSONObject().put("op","validate").put("toml",config)).getJSONObject("data")
|
||||
check(validated.getString("runtime_mode") == "application") { "Unified VPN requires application-mode MeshPort" }
|
||||
@@ -204,11 +205,13 @@ class MeshVpnService : VpnService() {
|
||||
builder.allowFamily(OsConstants.AF_INET6)
|
||||
}
|
||||
tun = builder.establish() ?: error("VPN authorization revoked")
|
||||
Log.i("MeshPortVPN", "Unified VPN: TUN established; internet routes=$internet")
|
||||
proxyHandle = NativeBridge.newProxyContext()
|
||||
check(proxyHandle != 0L)
|
||||
proxyCall(JSONObject().put("op","configure_cache").put("directory",cacheDir.absolutePath))
|
||||
restartProxy(routes)
|
||||
running = true
|
||||
Log.i("MeshPortVPN", "Unified VPN: proxy engine ready")
|
||||
networkCallback = object: ConnectivityManager.NetworkCallback() {
|
||||
override fun onAvailable(network: android.net.Network) { worker.execute { updatePhysical() } }
|
||||
override fun onLost(network: android.net.Network) { worker.execute { updatePhysical() } }
|
||||
@@ -250,6 +253,7 @@ class MeshVpnService : VpnService() {
|
||||
.put("tun",JSONObject().put("fd",tun!!.fd).put("name",NativeBridge.tunName(tun!!.fd) ?: error("TUN name unavailable"))
|
||||
.put("physical_interface",iface).put("physical_index",index))
|
||||
proxyCall(JSONObject().put("op","start").put("config",config))
|
||||
Log.i("MeshPortVPN", "Unified VPN: protected physical sockets; learned routes=${routes.size}")
|
||||
installed = routes
|
||||
}
|
||||
private fun unifiedStatus(): JSONObject {
|
||||
@@ -262,6 +266,7 @@ class MeshVpnService : VpnService() {
|
||||
return JSONObject().put("ok",true).put("data",data)
|
||||
}
|
||||
private fun shutdown() {
|
||||
if (running || handle != 0L || proxyHandle != 0L || tun != null) Log.i("MeshPortVPN", "Stopping VPN and releasing TUN")
|
||||
running = false
|
||||
if (proxyHandle != 0L) { NativeBridge.freeProxyContext(proxyHandle); proxyHandle = 0L }
|
||||
val connectivity = getSystemService(ConnectivityManager::class.java)
|
||||
|
||||
Reference in New Issue
Block a user