From 1b803efb0718f3ac87677cc1fc98c4b868b2176c Mon Sep 17 00:00:00 2001 From: Mygod Date: Sat, 4 May 2024 22:35:11 -0400 Subject: [PATCH] Better support VPN lockdown mode on Android 13+ Fixes #565. --- README.md | 2 ++ .../net/RemoveUidInterfaceRuleCommand.kt | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cfa5b291..91b977fc 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,7 @@ Greylisted/blacklisted APIs or internal constants: (some constants are hardcoded * (since API 30) `Landroid/net/TetheringManager$TetheringEventCallback;->onTetherableInterfaceRegexpsChanged(Landroid/net/TetheringManager$TetheringInterfaceRegexps;)V,blocked` * (since API 31) `Landroid/net/TetheringManager$TetheringEventCallback;->onSupportedTetheringTypes(Ljava/util/Set;)V,blocked` * (since API 33) `Landroid/net/connectivity/android/net/BpfNetMapsConstants;->IIF_MATCH:J,blocked` +* (since API 33) `Landroid/net/connectivity/android/net/BpfNetMapsConstants;->LOCKDOWN_VPN_MATCH:J,blocked` * (since API 33) `Landroid/net/connectivity/android/net/UidOwnerValue;->(IJ)V,blocked` * (since API 33) `Landroid/net/connectivity/android/net/UidOwnerValue;->rule:J,blocked` * (since API 33) `Landroid/net/connectivity/com/android/net/module/util/BpfMap;->(Ljava/lang/String;ILjava/lang/Class;Ljava/lang/Class;)V,blocked` @@ -205,6 +206,7 @@ Greylisted/blacklisted APIs or internal constants: (some constants are hardcoded * (since API 33) `Lcom/android/server/BpfNetMaps;->native_init()V` * (since API 33) `Lcom/android/server/BpfNetMaps;->native_init(Z)V` * (since API 33) `Lcom/android/server/BpfNetMaps;->native_removeUidInterfaceRules([I)I` +* (since API 33) `Lcom/android/server/BpfNetMaps;->native_updateUidLockdownRule(IZ)I` * (since API 33) `Lcom/android/server/BpfNetMaps;->sInitialized:Z` * (since API 30) `Lcom/android/server/SystemServer;->TETHERING_CONNECTOR_CLASS:Ljava/lang/String;` * `Ljava/lang/invoke/MethodHandles$Lookup;->(Ljava/lang/Class;I)V,unsupported` diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/RemoveUidInterfaceRuleCommand.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/RemoveUidInterfaceRuleCommand.kt index 4170fc97..7b038961 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/RemoveUidInterfaceRuleCommand.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/RemoveUidInterfaceRuleCommand.kt @@ -71,8 +71,16 @@ data class RemoveUidInterfaceRuleCommand(private val uid: Int) : RootCommand false - oldRule == iifMatch -> deleteEntry(uidOwnerMap, uidS32) as Boolean + oldRule and matches == 0L -> false + oldRule == matches -> deleteEntry(uidOwnerMap, uidS32) as Boolean else -> true.also { - updateEntry(uidOwnerMap, uidS32, newUidOwnerValue.newInstance(0, oldRule and iifMatch.inv())) + updateEntry(uidOwnerMap, uidS32, newUidOwnerValue.newInstance(0, oldRule and matches.inv())) } } } @@ -131,9 +139,15 @@ data class RemoveUidInterfaceRuleCommand(private val uid: Int) : RootCommand