From bc1b4d41ededa4b43cfce562344ff5931bc3e3ff Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 12 Jul 2022 21:13:51 -0400 Subject: [PATCH] Try to obtain country code on old devices as well --- README.md | 2 +- .../java/be/mygod/vpnhotspot/manage/TetherManager.kt | 2 +- .../be/mygod/vpnhotspot/net/wifi/SoftApCapability.kt | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a5c56914..8a9c805e 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ Greylisted/blacklisted APIs or internal constants: (some constants are hardcoded * (prior to API 30) `Landroid/net/ConnectivityManager;->getLastTetherError(Ljava/lang/String;)I,max-target-r` * (since API 30) `Landroid/net/ConnectivityModuleConnector;->IN_PROCESS_SUFFIX:Ljava/lang/String;` * (since API 30) `Landroid/net/TetheringManager$TetheringEventCallback;->onTetherableInterfaceRegexpsChanged(Landroid/net/TetheringManager$TetheringInterfaceRegexps;)V,blocked` -* (since API 33) `Landroid/net/wifi/SoftApCapability;->getCountryCode()Ljava/lang/String;,blocked` +* (since API 31) `Landroid/net/wifi/SoftApCapability;->getCountryCode()Ljava/lang/String;,blocked` * (since API 31) `Landroid/net/wifi/SoftApConfiguration$Builder;->setUserConfiguration(Z)Landroid/net/wifi/SoftApConfiguration$Builder;,blocked` * (since API 31) `Landroid/net/wifi/SoftApConfiguration;->BAND_TYPES:[I,blocked` * (since API 31) `Landroid/net/wifi/SoftApInfo;->getApInstanceIdentifier()Ljava/lang/String;,blocked` diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt index 2f5cfba5..1bd7ab44 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetherManager.kt @@ -257,7 +257,7 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(), }.filterNotNull() if (list.isNotEmpty()) result.append(parent.getText(R.string.tethering_manage_wifi_supported_channels) .format(locale, list.joinToString("; "))) - if (Build.VERSION.SDK_INT >= 33) capability.countryCode?.let { + capability.countryCode?.let { result.append(parent.getText(R.string.tethering_manage_wifi_country_code).format(locale, it)) } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApCapability.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApCapability.kt index 1ab5901f..556e4bc5 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApCapability.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApCapability.kt @@ -1,5 +1,7 @@ package be.mygod.vpnhotspot.net.wifi +import android.annotation.TargetApi +import android.os.Build import android.os.Parcelable import androidx.annotation.RequiresApi import be.mygod.vpnhotspot.util.LongConstantLookup @@ -17,7 +19,8 @@ value class SoftApCapability(val inner: Parcelable) { private val getSupportedChannelList by lazy { clazz.getDeclaredMethod("getSupportedChannelList", Int::class.java) } - @get:RequiresApi(33) + @get:RequiresApi(31) + @get:TargetApi(33) private val getCountryCode by lazy { UnblockCentral.getCountryCode(clazz) } @RequiresApi(31) @@ -42,11 +45,11 @@ value class SoftApCapability(val inner: Parcelable) { return supportedFeatures } fun getSupportedChannelList(band: Int) = getSupportedChannelList(inner, band) as IntArray - @get:RequiresApi(33) + @get:RequiresApi(31) val countryCode: String? get() = try { getCountryCode(inner) as String? } catch (e: ReflectiveOperationException) { - Timber.w(e) + if (Build.VERSION.SDK_INT >= 33) Timber.w(e) null } }