Add report name to header

This commit is contained in:
wanghongenpin
2025-10-28 14:32:11 +08:00
parent 63cc69e471
commit f6f2f99535
4 changed files with 23 additions and 10 deletions

View File

@@ -104,8 +104,8 @@ class ProxyVpnService : VpnService(), ProtectSocket {
disconnect()
}
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
return if (intent.action == ACTION_DISCONNECT) {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return if (intent?.action == ACTION_DISCONNECT) {
disconnect()
START_NOT_STICKY
} else {

View File

@@ -53,10 +53,14 @@ class ProcessInfoManager private constructor() {
val uid = getProcessInfoUid(sourceAddress, destinationAddress)
val channel = connection.channel
if (uid != null && uid != Process.INVALID_UID && channel is SocketChannel && channel.isOpen) {
val localAddress = channel.localAddress as InetSocketAddress
val networkInfo =
NetworkInfo(uid, destinationAddress.hostString, destinationAddress.port)
localPortCache.put(localAddress.port, networkInfo)
try {
val localAddress = channel.localAddress as InetSocketAddress
val networkInfo =
NetworkInfo(uid, destinationAddress.hostString, destinationAddress.port)
localPortCache.put(localAddress.port, networkInfo)
} catch (e: java.nio.channels.ClosedChannelException) {
Log.w("ProcessInfoManager", "setConnectionOwnerUid", e)
}
}
}
}
@@ -68,8 +72,12 @@ class ProcessInfoManager private constructor() {
val channel = connection.channel
if (channel is SocketChannel && channel.isOpen) {
val localAddress = channel.localAddress as InetSocketAddress
localPortCache.remove(localAddress.port)
try {
val localAddress = channel.localAddress as InetSocketAddress
localPortCache.remove(localAddress.port)
} catch (e: java.nio.channels.ClosedChannelException) {
Log.w("ProcessInfoManager", "removeConnection", e)
}
}
}
@@ -206,4 +214,4 @@ class ProcessInfoManager private constructor() {
return null
}
}
}

View File

@@ -92,6 +92,11 @@ class ReportServerInterceptor extends Interceptor {
final ioReq = await httpClient.postUrl(uri).timeout(const Duration(seconds: 5));
// Set headers
final matchedRule = server.name;
if (matchedRule.isNotEmpty) {
ioReq.headers.set('X-Report-Name', matchedRule);
}
ioReq.headers.set(HttpHeaders.contentTypeHeader, 'application/json; charset=utf-8');
if (compression == 'gzip') {
ioReq.headers.set(HttpHeaders.contentEncodingHeader, 'gzip');

View File

@@ -503,7 +503,7 @@ class _MobileAppBar extends StatelessWidget implements PreferredSizeWidget {
actions: [
IconButton(
tooltip: localizations.clear,
icon: const Icon(Icons.cleaning_services_outlined),
icon: const Icon(Icons.delete_outline),
onPressed: () => MobileApp.requestStateKey.currentState?.clean()),
const SizedBox(width: 2),
MoreMenu(proxyServer: proxyServer, remoteDevice: remoteDevice),