Support reading default shut down timeout mills from wifi resources apex

This commit is contained in:
Mygod
2020-07-02 08:26:07 +08:00
parent 59337cfcf0
commit 71e0ab6ed1
4 changed files with 32 additions and 9 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -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 {