Try to obtain country code on old devices as well

This commit is contained in:
Mygod
2022-07-12 21:13:51 -04:00
parent 80f3afcb73
commit bc1b4d41ed
3 changed files with 8 additions and 5 deletions

View File

@@ -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`

View File

@@ -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))
}
}

View File

@@ -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
}
}