Migrate from using deprecated getLastTetherError
This commit is contained in:
@@ -148,7 +148,7 @@ This is only meant to be an index. You can read more in the source code.
|
||||
|
||||
Greylisted/blacklisted APIs or internal constants: (some constants are hardcoded or implicitly used)
|
||||
|
||||
* [`Landroid/net/ConnectivityManager;->getLastTetherError(Ljava/lang/String;)I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#144306)
|
||||
* (prior to API 30) [`Landroid/net/ConnectivityManager;->getLastTetherError(Ljava/lang/String;)I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#144306)
|
||||
* (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,blacklist`](https://android.googlesource.com/platform/prebuilts/runtime/+/4601d91/appcompat/hiddenapi-flags.csv#148899)
|
||||
* (since API 30) `Landroid/net/TetheringManager;->TETHERING_WIGIG:I`
|
||||
|
||||
@@ -119,11 +119,13 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
||||
(viewHolder as ViewHolder).manager = this
|
||||
}
|
||||
|
||||
fun updateErrorMessage(errored: List<String>) {
|
||||
fun updateErrorMessage(errored: List<String>, lastErrors: Map<String, Int>) {
|
||||
val interested = errored.filter { TetherType.ofInterface(it) == tetherType }
|
||||
baseError = if (interested.isEmpty()) null else interested.joinToString("\n") { iface ->
|
||||
"$iface: " + try {
|
||||
TetheringManager.tetherErrorLookup(TetheringManager.getLastTetherError(iface))
|
||||
TetheringManager.tetherErrorLookup(if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") {
|
||||
TetheringManager.getLastTetherError(iface)
|
||||
} else lastErrors[iface] ?: 0)
|
||||
} catch (e: InvocationTargetException) {
|
||||
if (Build.VERSION.SDK_INT !in 24..25 || e.cause !is SecurityException) Timber.w(e) else Timber.d(e)
|
||||
e.readableMessage
|
||||
|
||||
@@ -42,7 +42,8 @@ import java.net.NetworkInterface
|
||||
import java.net.SocketException
|
||||
|
||||
class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClickListener {
|
||||
inner class ManagerAdapter : ListAdapter<Manager, RecyclerView.ViewHolder>(Manager) {
|
||||
inner class ManagerAdapter : ListAdapter<Manager, RecyclerView.ViewHolder>(Manager),
|
||||
TetheringManager.TetheringEventCallback {
|
||||
internal val repeaterManager by lazy { RepeaterManager(this@TetheringFragment) }
|
||||
@get:RequiresApi(26)
|
||||
internal val localOnlyHotspotManager by lazy @TargetApi(26) { LocalOnlyHotspotManager(this@TetheringFragment) }
|
||||
@@ -69,6 +70,11 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
||||
this@TetheringFragment.enabledTypes = enabledIfaces.map { TetherType.ofInterface(it) }.toSet()
|
||||
}
|
||||
|
||||
val lastErrors = mutableMapOf<String, Int>()
|
||||
override fun onError(ifName: String, error: Int) {
|
||||
if (error == 0) lastErrors.remove(ifName) else lastErrors[ifName] = error
|
||||
}
|
||||
|
||||
suspend fun notifyInterfaceChanged(lastList: List<Manager>? = null) {
|
||||
@Suppress("NAME_SHADOWING") val lastList = lastList ?: listDeferred.await()
|
||||
val first = lastList.indexOfFirst { it is InterfaceManager }
|
||||
@@ -104,11 +110,11 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
||||
list.add(ManageBar)
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
list.addAll(tetherManagers)
|
||||
tetherManagers.forEach { it.updateErrorMessage(erroredIfaces) }
|
||||
tetherManagers.forEach { it.updateErrorMessage(erroredIfaces, lastErrors) }
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
list.addAll(tetherManagers30)
|
||||
tetherManagers30.forEach { it.updateErrorMessage(erroredIfaces) }
|
||||
tetherManagers30.forEach { it.updateErrorMessage(erroredIfaces, lastErrors) }
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < 26) {
|
||||
list.add(wifiManagerLegacy)
|
||||
@@ -279,15 +285,20 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
||||
lifecycleScope.launchWhenStarted { adapter.notifyInterfaceChanged() }
|
||||
}
|
||||
requireContext().registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
||||
if (Build.VERSION.SDK_INT >= 30) TetherType.listener[this] = {
|
||||
lifecycleScope.launchWhenStarted { adapter.notifyTetherTypeChanged() }
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
TetheringManager.registerTetheringEventCallback(null, adapter)
|
||||
TetherType.listener[this] = { lifecycleScope.launchWhenStarted { adapter.notifyTetherTypeChanged() } }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
(binder ?: return).routingsChanged -= this
|
||||
binder = null
|
||||
if (Build.VERSION.SDK_INT >= 30) TetherType.listener -= this
|
||||
if (Build.VERSION.SDK_INT >= 30) {
|
||||
TetherType.listener -= this
|
||||
TetheringManager.unregisterTetheringEventCallback(adapter)
|
||||
adapter.lastErrors.clear()
|
||||
}
|
||||
requireContext().unregisterReceiver(receiver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,6 +629,7 @@ object TetheringManager {
|
||||
* @return error The error code of the last error tethering or untethering the named
|
||||
* interface
|
||||
*/
|
||||
@Deprecated("Use {@link TetheringEventCallback#onError(String, int)} instead.")
|
||||
fun getLastTetherError(iface: String): Int = getLastTetherError(Services.connectivity, iface) as Int
|
||||
|
||||
val tetherErrorLookup = ConstantLookup("TETHER_ERROR_",
|
||||
|
||||
Reference in New Issue
Block a user