From bfc304a480f72f14f5412fe13a93e73bc6572b29 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 4 Dec 2022 12:15:58 -0500 Subject: [PATCH] Target Android 13 on freedom as well --- README.md | 2 -- mobile/build.gradle.kts | 8 ++------ .../java/be/mygod/vpnhotspot/util/UnblockHelper.kt | 13 ------------- mobile/src/google/AndroidManifest.xml | 11 ----------- .../java/be/mygod/vpnhotspot/util/UnblockHelper.kt | 8 -------- mobile/src/main/AndroidManifest.xml | 9 ++++++--- mobile/src/main/java/be/mygod/vpnhotspot/App.kt | 13 +++++++------ .../vpnhotspot/manage/LocalOnlyHotspotManager.kt | 2 +- .../be/mygod/vpnhotspot/manage/RepeaterManager.kt | 2 +- .../be/mygod/vpnhotspot/net/monitor/IpMonitor.kt | 3 +-- .../java/be/mygod/vpnhotspot/util/UnblockCentral.kt | 3 ++- 11 files changed, 20 insertions(+), 54 deletions(-) delete mode 100644 mobile/src/freedom/java/be/mygod/vpnhotspot/util/UnblockHelper.kt delete mode 100644 mobile/src/google/AndroidManifest.xml delete mode 100644 mobile/src/google/java/be/mygod/vpnhotspot/util/UnblockHelper.kt diff --git a/README.md b/README.md index cc336eab..13d6c733 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ Connecting things to your VPN made simple. Share your VPN connection over hotspo | Release channel | [GitHub (recommended)](https://github.com/Mygod/VPNHotspot/releases) | [Google Play](https://play.google.com/store/apps/details?id=be.mygod.vpnhotspot) ([beta](https://play.google.com/apps/testing/be.mygod.vpnhotspot)) | |---------------------------------------------------------|:--------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------:| -| Monitor connected clients without root | Up to Android 12L | Up to Android 10 | -| Use repeater/temporary hotspot without location enabled | Up to Android 10/9 | Up to Android 10/9 or Android 13+ | | Auto update | Email updates via watching releases | ✓ | | In-app update channel | GitHub | Google Play | | [Sponsor/Donation](https://github.com/sponsors/Mygod) | ✓ | Google Play In-App Purchases only | diff --git a/mobile/build.gradle.kts b/mobile/build.gradle.kts index c1bb0c71..7b0d79a7 100644 --- a/mobile/build.gradle.kts +++ b/mobile/build.gradle.kts @@ -23,8 +23,7 @@ android { defaultConfig { applicationId = "be.mygod.vpnhotspot" minSdk = 21 - @android.annotation.SuppressLint("ExpiredTargetSdkVersion") - targetSdk = 29 + targetSdk = 33 resourceConfigurations.addAll(arrayOf("it", "ru", "zh-rCN", "zh-rTW")) versionCode = 302 versionName = "2.15.2" @@ -35,7 +34,6 @@ android { put("room.schemaLocation", "$projectDir/schemas") } buildConfigField("boolean", "DONATIONS", "true") - buildConfigField("int", "TARGET_SDK", "29") } buildFeatures { dataBinding = true @@ -59,10 +57,8 @@ android { } create("google") { dimension = "freedom" - targetSdk = 33 versionNameSuffix = "-g" buildConfigField("boolean", "DONATIONS", "false") - buildConfigField("int", "TARGET_SDK", "33") } } sourceSets.getByName("androidTest").assets.srcDir("$projectDir/schemas") @@ -85,6 +81,7 @@ dependencies { implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0") implementation("be.mygod.librootkotlinx:librootkotlinx:1.0.0") implementation("com.android.billingclient:billing-ktx:5.1.0") + implementation("com.github.tiann:FreeReflection:3.1.0") implementation("com.google.android.gms:play-services-oss-licenses:17.0.0") implementation("com.google.android.material:material:1.7.0") implementation("com.google.firebase:firebase-analytics-ktx:21.2.0") @@ -95,7 +92,6 @@ dependencies { implementation("com.takisoft.preferencex:preferencex-simplemenu:1.1.0") implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4") - add("googleImplementation", "com.github.tiann:FreeReflection:3.1.0") add("googleImplementation", "com.google.android.play:core:1.10.3") add("googleImplementation", "com.google.android.play:core-ktx:1.8.1") testImplementation("junit:junit:4.13.2") diff --git a/mobile/src/freedom/java/be/mygod/vpnhotspot/util/UnblockHelper.kt b/mobile/src/freedom/java/be/mygod/vpnhotspot/util/UnblockHelper.kt deleted file mode 100644 index 873d210a..00000000 --- a/mobile/src/freedom/java/be/mygod/vpnhotspot/util/UnblockHelper.kt +++ /dev/null @@ -1,13 +0,0 @@ -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.java) - val clazz = Class.forName("dalvik.system.VMRuntime") - val setHiddenApiExemptions = getDeclaredMethod(clazz, "setHiddenApiExemptions", - arrayOf(Array::class.java)) as Method - setHiddenApiExemptions(clazz.getDeclaredMethod("getRuntime")(null), arrayOf("")) -} diff --git a/mobile/src/google/AndroidManifest.xml b/mobile/src/google/AndroidManifest.xml deleted file mode 100644 index cba266f0..00000000 --- a/mobile/src/google/AndroidManifest.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - diff --git a/mobile/src/google/java/be/mygod/vpnhotspot/util/UnblockHelper.kt b/mobile/src/google/java/be/mygod/vpnhotspot/util/UnblockHelper.kt deleted file mode 100644 index 88e62c76..00000000 --- a/mobile/src/google/java/be/mygod/vpnhotspot/util/UnblockHelper.kt +++ /dev/null @@ -1,8 +0,0 @@ -package be.mygod.vpnhotspot.util - -import android.content.Context -import me.weishu.reflection.Reflection - -fun UnblockHelper(context: Context) { - check(Reflection.unseal(context) == 0) -} diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml index f7bfd47a..e801d194 100644 --- a/mobile/src/main/AndroidManifest.xml +++ b/mobile/src/main/AndroidManifest.xml @@ -28,6 +28,7 @@ + @@ -40,6 +41,7 @@ android:usesPermissionFlags="neverForLocation"/> + @@ -50,9 +52,10 @@ tools:ignore="ProtectedPermissions"/> - - - + + startServiceWithLocation(context: Context) { - if (BuildConfig.TARGET_SDK >= 33 && Build.VERSION.SDK_INT >= 33 || if (Build.VERSION.SDK_INT >= 28) { - location?.isLocationEnabled == true - } else @Suppress("DEPRECATION") { - Settings.Secure.getInt(context.contentResolver, Settings.Secure.LOCATION_MODE, - Settings.Secure.LOCATION_MODE_OFF) != Settings.Secure.LOCATION_MODE_OFF - }) ContextCompat.startForegroundService(context, Intent(context, T::class.java)) else try { + val canStart = Build.VERSION.SDK_INT >= 33 || if (Build.VERSION.SDK_INT >= 28) { + location?.isLocationEnabled == true + } else @Suppress("DEPRECATION") { + Settings.Secure.getInt(context.contentResolver, Settings.Secure.LOCATION_MODE, + Settings.Secure.LOCATION_MODE_OFF) != Settings.Secure.LOCATION_MODE_OFF + } + if (canStart) ContextCompat.startForegroundService(context, Intent(context, T::class.java)) else try { context.startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) Toast.makeText(context, R.string.tethering_location_off, Toast.LENGTH_LONG).show() } catch (e: ActivityNotFoundException) { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt index 03ddb23e..73cc4e0f 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt @@ -20,7 +20,7 @@ import java.net.NetworkInterface class LocalOnlyHotspotManager(private val parent: TetheringFragment) : Manager(), ServiceConnection { companion object { val permission = when { - BuildConfig.TARGET_SDK >= 33 && Build.VERSION.SDK_INT >= 33 -> Manifest.permission.NEARBY_WIFI_DEVICES + Build.VERSION.SDK_INT >= 33 -> Manifest.permission.NEARBY_WIFI_DEVICES Build.VERSION.SDK_INT >= 29 -> Manifest.permission.ACCESS_FINE_LOCATION else -> Manifest.permission.ACCESS_COARSE_LOCATION } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt index c3bce869..68794d91 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt @@ -92,7 +92,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic when (binder?.service?.status) { RepeaterService.Status.IDLE -> if (Build.VERSION.SDK_INT < 29) parent.requireContext().let { context -> ContextCompat.startForegroundService(context, Intent(context, RepeaterService::class.java)) - } else parent.startRepeater.launch(if (BuildConfig.TARGET_SDK >= 33 && Build.VERSION.SDK_INT >= 33) { + } else parent.startRepeater.launch(if (Build.VERSION.SDK_INT >= 33) { Manifest.permission.NEARBY_WIFI_DEVICES } else Manifest.permission.ACCESS_FINE_LOCATION) RepeaterService.Status.ACTIVE -> binder.shutdown() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt index 4c6e4bfd..cd00bef1 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpMonitor.kt @@ -30,8 +30,7 @@ abstract class IpMonitor { var currentMode: Mode get() { // Completely restricted on Android 13: https://github.com/termux/termux-app/issues/2993#issuecomment-1250312777 - val isLegacy = Build.VERSION.SDK_INT < 33 && (Build.VERSION.SDK_INT < 30 || BuildConfig.TARGET_SDK < 30) - val defaultMode = if (isLegacy) @Suppress("DEPRECATION") { + val defaultMode = if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") { Mode.Poll } else Mode.MonitorRoot return Mode.valueOf(app.pref.getString(KEY, defaultMode.toString()) ?: "") diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/UnblockCentral.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/UnblockCentral.kt index cc1807b3..cfef3829 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/UnblockCentral.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/UnblockCentral.kt @@ -6,6 +6,7 @@ import android.net.wifi.SoftApConfiguration import android.net.wifi.p2p.WifiP2pConfig import androidx.annotation.RequiresApi import be.mygod.vpnhotspot.App.Companion.app +import me.weishu.reflection.Reflection /** * The central object for accessing all the useful blocked APIs. Thanks Google! @@ -20,7 +21,7 @@ object UnblockCentral { /** * Retrieve this property before doing dangerous shit. */ - private val init by lazy { if (needInit) UnblockHelper(app.deviceStorage) } + private val init by lazy { if (needInit) check(Reflection.unseal(app.deviceStorage) == 0) } @RequiresApi(33) fun getCountryCode(clazz: Class<*>) = init.let { clazz.getDeclaredMethod("getCountryCode") }