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

@@ -10,7 +10,6 @@ plugins {
android {
val javaVersion = JavaVersion.VERSION_11
val targetSdk = 29
buildToolsVersion = "31.0.0"
compileOptions {
isCoreLibraryDesugaringEnabled = true
@@ -22,10 +21,10 @@ android {
defaultConfig {
applicationId = "be.mygod.vpnhotspot"
minSdk = 21
this.targetSdk = targetSdk
targetSdk = 29
resourceConfigurations.addAll(arrayOf("it", "ru", "zh-rCN", "zh-rTW"))
versionCode = 279
versionName = "2.12.8"
versionCode = 280
versionName = "2.13.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions.annotationProcessorOptions.arguments.apply {
put("room.expandProjection", "true")
@@ -33,7 +32,7 @@ android {
put("room.schemaLocation", "$projectDir/schemas")
}
buildConfigField("boolean", "DONATIONS", "true")
buildConfigField("int", "TARGET_SDK", targetSdk.toString())
buildConfigField("int", "TARGET_SDK", "29")
}
buildFeatures {
dataBinding = true
@@ -57,7 +56,9 @@ android {
}
create("google") {
dimension = "freedom"
targetSdk = 31
buildConfigField("boolean", "DONATIONS", "false")
buildConfigField("int", "TARGET_SDK", "31")
}
}
sourceSets.getByName("androidTest").assets.srcDir("$projectDir/schemas")
@@ -91,6 +92,7 @@ dependencies {
implementation("com.takisoft.preferencex:preferencex-simplemenu:1.1.0")
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")
add("googleImplementation", "com.github.tiann:FreeReflection:3.1.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.room:room-testing:$roomVersion")
androidTestImplementation("androidx.test:runner:1.4.0")

View File

@@ -0,0 +1,13 @@
package be.mygod.vpnhotspot.util
import android.content.Context
import java.lang.reflect.Method
fun UnblockHelper(context: Context) {
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(""))
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Required since API 31, when targeting API 31 -->
<uses-permission-sdk-23 android:name="android.permission.BLUETOOTH_CONNECT"/>
</manifest>

View File

@@ -0,0 +1,8 @@
package be.mygod.vpnhotspot.util
import android.content.Context
import me.weishu.reflection.Reflection
fun UnblockHelper(context: Context) {
check(Reflection.unseal(context) == 0)
}

View File

@@ -52,10 +52,6 @@
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- Required since API 29 -->
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Required since API 31, when targeting API 31 -->
<!--
<uses-permission-sdk-23 android:name="android.permission.BLUETOOTH_CONNECT"/>
-->
<application
android:name=".App"

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 {