This commit is contained in:
Mygod
2020-05-29 06:34:20 +08:00
parent 86c847d12e
commit 89a02bde69
3 changed files with 5 additions and 16 deletions

View File

@@ -15,12 +15,12 @@ android {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
compileSdkVersion(29)
compileSdkVersion("android-R")
kotlinOptions.jvmTarget = javaVersion.toString()
defaultConfig {
applicationId = "be.mygod.vpnhotspot"
minSdkVersion(21)
targetSdkVersion(29)
targetSdkVersion("R")
resConfigs(listOf("it", "ru", "zh-rCN", "zh-rTW"))
versionCode = 224
versionName = "2.9.1"

View File

@@ -20,7 +20,6 @@ import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.net.monitor.TetherTimeoutMonitor
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.deletePersistentGroup
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.netId
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.requestPersistentGroupInfo
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.setWifiP2pChannels
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.startWps
@@ -235,11 +234,11 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
p2pManager.requestPersistentGroupInfo(channel) {
if (it.isNotEmpty()) persistentSupported = true
val ownedGroups = it.filter { it.isGroupOwner && it.owner.deviceAddress == device.deviceAddress }
val main = ownedGroups.minBy { it.netId }
val main = ownedGroups.minBy { it.networkId }
// do not replace current group if it's better
if (binder.group?.passphrase == null) binder.group = main
if (main != null) ownedGroups.filter { it.netId != main.netId }.forEach {
p2pManager.deletePersistentGroup(channel, it.netId, object : WifiP2pManager.ActionListener {
if (main != null) ownedGroups.filter { it.networkId != main.networkId }.forEach {
p2pManager.deletePersistentGroup(channel, it.networkId, object : WifiP2pManager.ActionListener {
override fun onSuccess() = Timber.i("Removed redundant owned group: $it")
override fun onFailure(reason: Int) = SmartSnackbar.make(
formatReason(R.string.repeater_clean_pog_failure, reason)).show()

View File

@@ -102,14 +102,4 @@ object WifiP2pManagerHelper {
}
requestPersistentGroupInfo.invoke(this, c, proxy)
}
/**
* Available since Android 4.2.
*
* Source: https://android.googlesource.com/platform/frameworks/base/+/android-4.2_r1/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java#253
*/
private val getNetworkId by lazy @SuppressLint("DiscouragedPrivateApi") {
WifiP2pGroup::class.java.getDeclaredMethod("getNetworkId")
}
val WifiP2pGroup.netId get() = getNetworkId.invoke(this) as Int
}