Fix timeout new default

This commit is contained in:
Mygod
2022-07-12 20:41:57 -04:00
parent f14fb92984
commit bf856d77d5
2 changed files with 6 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import android.os.Build
import android.os.Parcelable import android.os.Parcelable
import android.util.SparseIntArray import android.util.SparseIntArray
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import be.mygod.vpnhotspot.BuildConfig
import be.mygod.vpnhotspot.net.MacAddressCompat import be.mygod.vpnhotspot.net.MacAddressCompat
import be.mygod.vpnhotspot.net.MacAddressCompat.Companion.toCompat import be.mygod.vpnhotspot.net.MacAddressCompat.Companion.toCompat
import be.mygod.vpnhotspot.net.monitor.TetherTimeoutMonitor import be.mygod.vpnhotspot.net.monitor.TetherTimeoutMonitor
@@ -95,6 +96,7 @@ data class SoftApConfigurationCompat(
"WPA3-OWE Transition", "WPA3-OWE Transition",
"WPA3-OWE", "WPA3-OWE",
) )
val TIMEOUT_DEFAULT = if (BuildConfig.TARGET_SDK >= 33 && Build.VERSION.SDK_INT >= 33) -1L else 0L
private val qrSanitizer = Regex("([\\\\\":;,])") private val qrSanitizer = Regex("([\\\\\":;,])")

View File

@@ -131,7 +131,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
if (full) @TargetApi(28) { if (full) @TargetApi(28) {
isAutoShutdownEnabled = dialogView.autoShutdown.isChecked isAutoShutdownEnabled = dialogView.autoShutdown.isChecked
shutdownTimeoutMillis = dialogView.timeout.text.let { text -> shutdownTimeoutMillis = dialogView.timeout.text.let { text ->
if (text.isNullOrEmpty()) 0 else text.toString().toLong() if (text.isNullOrEmpty()) defaultTimeout else text.toString().toLong()
} }
if (Build.VERSION.SDK_INT >= 23 || arg.p2pMode) channels = generateChannels() if (Build.VERSION.SDK_INT >= 23 || arg.p2pMode) channels = generateChannels()
bssid = if (dialogView.bssid.length() != 0) { bssid = if (dialogView.bssid.length() != 0) {
@@ -229,6 +229,8 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
populateFromConfiguration() populateFromConfiguration()
} }
private val defaultTimeout get() = if (arg.p2pMode) 0L else SoftApConfigurationCompat.TIMEOUT_DEFAULT
private fun locate(i: Int): Int { private fun locate(i: Int): Int {
val band = base.channels.keyAt(i) val band = base.channels.keyAt(i)
val channel = base.channels.valueAt(i) val channel = base.channels.valueAt(i)
@@ -244,7 +246,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
if (!arg.p2pMode) dialogView.security.setSelection(base.securityType) if (!arg.p2pMode) dialogView.security.setSelection(base.securityType)
dialogView.password.setText(base.passphrase) dialogView.password.setText(base.passphrase)
dialogView.autoShutdown.isChecked = base.isAutoShutdownEnabled dialogView.autoShutdown.isChecked = base.isAutoShutdownEnabled
dialogView.timeout.setText(base.shutdownTimeoutMillis.let { if (it == 0L) "" else it.toString() }) dialogView.timeout.setText(base.shutdownTimeoutMillis.let { if (it == defaultTimeout) "" else it.toString() })
if (Build.VERSION.SDK_INT >= 23 || arg.p2pMode) { if (Build.VERSION.SDK_INT >= 23 || arg.p2pMode) {
dialogView.bandPrimary.setSelection(locate(0)) dialogView.bandPrimary.setSelection(locate(0))
if (Build.VERSION.SDK_INT >= 31 && !arg.p2pMode) { if (Build.VERSION.SDK_INT >= 31 && !arg.p2pMode) {