Target API 31 on Google variant

This commit is contained in:
Mygod
2021-10-23 17:02:52 -04:00
parent 79bade2fe9
commit c1ae7857eb
7 changed files with 40 additions and 26 deletions

View File

@@ -320,12 +320,11 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
onTetheringStarted() // force flush
}
override fun onResume(owner: LifecycleOwner) {
if (Build.VERSION.SDK_INT < 31 || parent.requireContext().checkSelfPermission(
Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT < 31) return
if (parent.requireContext().checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) ==
PackageManager.PERMISSION_GRANTED) {
tethering.ensureInit(parent.requireContext())
} else if (parent.shouldShowRequestPermissionRationale(Manifest.permission.BLUETOOTH_CONNECT)) {
parent.requestBluetooth.launch(Manifest.permission.BLUETOOTH_CONNECT)
}
} else parent.requestBluetooth.launch(Manifest.permission.BLUETOOTH_CONNECT)
}
override fun onDestroy(owner: LifecycleOwner) = tethering.close()

View File

@@ -3,31 +3,22 @@ package be.mygod.vpnhotspot.util
import android.annotation.SuppressLint
import android.net.wifi.SoftApConfiguration
import android.net.wifi.p2p.WifiP2pConfig
import android.os.Build
import androidx.annotation.RequiresApi
import java.lang.reflect.Method
import be.mygod.vpnhotspot.App.Companion.app
/**
* The central object for accessing all the useful blocked APIs. Thanks Google!
*
* Lazy cannot be used directly as it will create inner classes.
*/
@RequiresApi(28)
@SuppressLint("BlockedPrivateApi", "DiscouragedPrivateApi")
@Suppress("FunctionName")
object UnblockCentral {
/**
* Retrieve this property before doing dangerous shit.
*/
private val init by lazy {
if (Build.VERSION.SDK_INT < 28) return@lazy
// TODO: fix this not working when targeting API 30+
val getDeclaredMethod = Class::class.java.getDeclaredMethod("getDeclaredMethod",
String::class.java, arrayOf<Class<*>>()::class.java)
val clazz = Class.forName("dalvik.system.VMRuntime")
val setHiddenApiExemptions = getDeclaredMethod(clazz, "setHiddenApiExemptions",
arrayOf(Array<String>::class.java)) as Method
setHiddenApiExemptions(clazz.getDeclaredMethod("getRuntime")(null), arrayOf(""))
}
private val init by lazy { UnblockHelper(app) }
@RequiresApi(31)
fun setUserConfiguration(clazz: Class<*>) = init.let {