Support tether errors in Android 11 preview
This commit is contained in:
@@ -138,6 +138,7 @@ Non-public API list:
|
||||
* (since API 24) [`Landroid/net/ConnectivityManager;->getLastTetherError(Ljava/lang/String;)I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123309)
|
||||
* (since API 24) [`Landroid/net/ConnectivityManager;->startTethering(IZLandroid/net/ConnectivityManager$OnStartTetheringCallback;Landroid/os/Handler;)V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123408)
|
||||
* (since API 24) [`Landroid/net/ConnectivityManager;->stopTethering(I)V,system-api,whitelist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#123410)
|
||||
* (since API 30) `Landroid/net/TetheringManager;->TETHER_ERROR_*:I,system-api,test-api,whitelist`
|
||||
* (since API 23) [`Landroid/net/wifi/WifiConfiguration;->apBand:I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#131529)
|
||||
* (since API 23) [`Landroid/net/wifi/WifiConfiguration;->apChannel:I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#131530)
|
||||
* (since API 26) [`Landroid/net/wifi/WifiManager;->cancelLocalOnlyHotspotRequest()V,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/3d07e5c/appcompat/hiddenapi-flags.csv#132250)
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.os.BuildCompat
|
||||
import androidx.core.view.updatePaddingRelative
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
@@ -99,10 +100,19 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
||||
(viewHolder as ViewHolder).manager = this
|
||||
}
|
||||
|
||||
fun updateErrorMessage(errored: List<String>) {
|
||||
data.text = errored.filter { TetherType.ofInterface(it) == tetherType }.joinToString("\n") {
|
||||
"$it: " + try {
|
||||
when (val error = TetheringManager.getLastTetherError(it)) {
|
||||
private fun getErrorMessage(iface: String): String {
|
||||
val error = try {
|
||||
TetheringManager.getLastTetherError(iface)
|
||||
} catch (e: InvocationTargetException) {
|
||||
if (Build.VERSION.SDK_INT !in 24..25 || e.cause !is SecurityException) Timber.w(e) else Timber.d(e)
|
||||
return e.readableMessage
|
||||
}
|
||||
if (BuildCompat.isAtLeastR()) try {
|
||||
TetheringManager.tetherErrors.get(error)?.let { return it }
|
||||
} catch (e: ReflectiveOperationException) {
|
||||
Timber.w(e)
|
||||
}
|
||||
return when (error) {
|
||||
TetheringManager.TETHER_ERROR_NO_ERROR -> "TETHER_ERROR_NO_ERROR"
|
||||
TetheringManager.TETHER_ERROR_UNKNOWN_IFACE -> "TETHER_ERROR_UNKNOWN_IFACE"
|
||||
TetheringManager.TETHER_ERROR_SERVICE_UNAVAIL -> "TETHER_ERROR_SERVICE_UNAVAIL"
|
||||
@@ -119,11 +129,10 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
||||
TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKNOWN -> "TETHER_ERROR_ENTITLEMENT_UNKNOWN"
|
||||
else -> app.getString(R.string.failure_reason_unknown, error)
|
||||
}
|
||||
} catch (e: InvocationTargetException) {
|
||||
if (Build.VERSION.SDK_INT !in 24..25 || e.cause !is SecurityException) Timber.w(e) else Timber.d(e)
|
||||
e.readableMessage
|
||||
}
|
||||
}
|
||||
fun updateErrorMessage(errored: List<String>) {
|
||||
data.text = errored.filter { TetherType.ofInterface(it) == tetherType }
|
||||
.joinToString("\n") { "$it: ${getErrorMessage(it)}" }
|
||||
data.notifyChange()
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.net.ConnectivityManager
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.collection.SparseArrayCompat
|
||||
import androidx.core.os.BuildCompat
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import com.android.dx.stock.ProxyBuilder
|
||||
@@ -88,6 +89,18 @@ object TetheringManager {
|
||||
*/
|
||||
const val TETHERING_BLUETOOTH = 2
|
||||
|
||||
@get:RequiresApi(30)
|
||||
val tetherErrors by lazy {
|
||||
SparseArrayCompat<String>().apply {
|
||||
for (field in Class.forName("android.net.TetheringManager").declaredFields) try {
|
||||
// all TETHER_ERROR_* are system-api since API 30
|
||||
if (field.name.startsWith("TETHER_ERROR_")) put(field.get(null) as Int, field.name)
|
||||
} catch (e: Exception) {
|
||||
Timber.w(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val classOnStartTetheringCallback by lazy {
|
||||
Class.forName("android.net.ConnectivityManager\$OnStartTetheringCallback")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user