Use reflection instead of parcel magic to get around networkName check

This commit is contained in:
Mygod
2021-05-27 12:22:47 -04:00
parent ea076d9602
commit b6bdf8cfb7
3 changed files with 20 additions and 41 deletions

View File

@@ -1,13 +1,16 @@
package be.mygod.vpnhotspot.util
import android.annotation.SuppressLint
import android.net.wifi.p2p.WifiP2pConfig
import androidx.annotation.RequiresApi
import timber.log.Timber
/**
* The central object for accessing all the useful blocked APIs. Thanks Google!
*
* Lazy cannot be used directly as it will create inner classes.
*/
@SuppressLint("DiscouragedPrivateApi")
@SuppressLint("BlockedPrivateApi", "DiscouragedPrivateApi")
@Suppress("FunctionName")
object UnblockCentral {
/**
@@ -27,4 +30,9 @@ object UnblockCentral {
@RequiresApi(31)
fun getApInstanceIdentifier(clazz: Class<*>) = init.let { clazz.getDeclaredMethod("getApInstanceIdentifier") }
@get:RequiresApi(29)
val WifiP2pConfig_Builder_mNetworkName get() = init.let {
WifiP2pConfig.Builder::class.java.getDeclaredField("mNetworkName").apply { isAccessible = true }
}
}