diff --git a/README.md b/README.md index 0e4dc89e..7758771c 100644 --- a/README.md +++ b/README.md @@ -167,9 +167,10 @@ Greylisted/blacklisted APIs or internal constants: (some constants are hardcoded * (prior to API 30) [`Lcom/android/internal/R$array;->config_tether_bluetooth_regexs:I,greylist-max-q`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#272546) * (prior to API 30) [`Lcom/android/internal/R$array;->config_tether_usb_regexs:I,greylist-max-q`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#272549) * (prior to API 30) [`Lcom/android/internal/R$array;->config_tether_wifi_regexs:I,greylist-max-q`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#272551) -* (since API 28) [`Lcom/android/internal/R$integer;->config_wifi_framework_soft_ap_timeout_delay:I,greylist-max-o`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#245007) +* (since API 28, prior to API 30) [`Lcom/android/internal/R$integer;->config_wifi_framework_soft_ap_timeout_delay:I,greylist-max-o`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#245007) * [`Lcom/android/internal/R$string;->config_ethernet_iface_regex:I,greylist-max-o`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#276573) * (since API 27) `Lcom/android/server/connectivity/tethering/OffloadHardwareInterface;->DEFAULT_TETHER_OFFLOAD_DISABLED:I` +* (since API 30) `Lcom/android/server/wifi/WifiContext;->ACTION_RESOURCES_APK:Ljava/lang/String;` * (since API 29) `Lcom/android/server/wifi/p2p/WifiP2pServiceImpl;->ANONYMIZED_DEVICE_ADDRESS:Ljava/lang/String;` * (since API 30) `Lcom/android/server/SystemServer;->TETHERING_CONNECTOR_CLASS:Ljava/lang/String;` * (since API 26) [`Ljava/lang/invoke/MethodHandles$Lookup;->(Ljava/lang/Class;I)V,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#370415) @@ -264,6 +265,7 @@ Nonexported system resources: * (since API 30) `@com.android.networkstack.tethering:array/config_tether_wifi_p2p_regexs` * (since API 30) `@com.android.networkstack.tethering:array/config_tether_wifi_regexs` * (since API 30) `@com.android.networkstack.tethering:array/config_tether_wigig_regexs` +* (since API 30) `@com.android.wifi.resources:integer/config_wifiFrameworkSoftApShutDownTimeoutMilliseconds` Other: diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt index 5cf3e3d1..b6b88953 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt @@ -171,10 +171,8 @@ object TetheringManager { service } @get:RequiresApi(30) - val resolvedService by lazy @TargetApi(30) { - app.packageManager.queryIntentServices(Intent(TETHERING_CONNECTOR_CLASS), - PackageManager.MATCH_SYSTEM_ONLY).single() - } + val resolvedService get() = app.packageManager.queryIntentServices(Intent(TETHERING_CONNECTOR_CLASS), + PackageManager.MATCH_SYSTEM_ONLY).single() @get:RequiresApi(24) private val classOnStartTetheringCallback by lazy { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TetherTimeoutMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TetherTimeoutMonitor.kt index 99a2436f..46eba248 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TetherTimeoutMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/TetherTimeoutMonitor.kt @@ -5,12 +5,14 @@ import android.content.Intent import android.content.res.Resources import android.database.ContentObserver import android.os.BatteryManager +import android.os.Build import android.os.Handler import android.os.Looper import android.provider.Settings import androidx.annotation.RequiresApi import androidx.core.os.postDelayed import be.mygod.vpnhotspot.App.Companion.app +import be.mygod.vpnhotspot.net.wifi.WifiApManager import be.mygod.vpnhotspot.util.broadcastReceiver import be.mygod.vpnhotspot.util.ensureReceiverUnregistered import be.mygod.vpnhotspot.util.intentFilter @@ -45,16 +47,20 @@ class TetherTimeoutMonitor(private val context: Context, private val onTimeout: // TODO: WRITE_SECURE_SETTINGS permission check(Settings.Global.putInt(app.contentResolver, SOFT_AP_TIMEOUT_ENABLED, if (value) 1 else 0)) } - @Deprecated("Use SoftApConfigurationCompat instead") val timeout by lazy { val delay = try { - app.resources.getInteger(Resources.getSystem().getIdentifier( - "config_wifi_framework_soft_ap_timeout_delay", "integer", "android")) + if (Build.VERSION.SDK_INT < 30) Resources.getSystem().run { + getInteger(getIdentifier("config_wifi_framework_soft_ap_timeout_delay", "integer", "android")) + } else app.packageManager.getResourcesForApplication(WifiApManager.resolvedActivity.activityInfo + .applicationInfo).run { + getInteger(getIdentifier("config_wifiFrameworkSoftApShutDownTimeoutMilliseconds", "integer", + "com.android.wifi.resources")) + } } catch (e: Resources.NotFoundException) { Timber.w(e) MIN_SOFT_AP_TIMEOUT_DELAY_MS } - if (delay < MIN_SOFT_AP_TIMEOUT_DELAY_MS) { + if (Build.VERSION.SDK_INT < 30 && delay < MIN_SOFT_AP_TIMEOUT_DELAY_MS) { Timber.w("Overriding timeout delay with minimum limit value: $delay < $MIN_SOFT_AP_TIMEOUT_DELAY_MS") MIN_SOFT_AP_TIMEOUT_DELAY_MS } else delay diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt index 07ba35b5..a1a2c29e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApManager.kt @@ -1,14 +1,31 @@ package be.mygod.vpnhotspot.net.wifi import android.annotation.TargetApi +import android.content.Intent +import android.content.pm.PackageManager import android.net.wifi.SoftApConfiguration import android.net.wifi.WifiManager import android.os.Build import androidx.annotation.RequiresApi +import be.mygod.vpnhotspot.App +import be.mygod.vpnhotspot.App.Companion.app +import be.mygod.vpnhotspot.net.TetheringManager import be.mygod.vpnhotspot.net.wifi.SoftApConfigurationCompat.Companion.toCompat import be.mygod.vpnhotspot.util.Services object WifiApManager { + /** + * TODO [com.android.server.wifi.WifiContext.ACTION_RESOURCES_APK] + */ + @RequiresApi(30) + private const val ACTION_RESOURCES_APK = "com.android.server.wifi.intent.action.SERVICE_WIFI_RESOURCES_APK" + /** + * Based on: TODO [com.android.server.wifi.WifiContext.getWifiOverlayApkPkgName] + */ + @get:RequiresApi(30) + val resolvedActivity get() = app.packageManager.queryIntentActivities(Intent(ACTION_RESOURCES_APK), + PackageManager.MATCH_SYSTEM_ONLY).single() + private val getWifiApConfiguration by lazy { WifiManager::class.java.getDeclaredMethod("getWifiApConfiguration") } @Suppress("DEPRECATION") private val setWifiApConfiguration by lazy {