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)
|
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/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$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`
|
* (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
|
(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 }
|
val interested = errored.filter { TetherType.ofInterface(it) == tetherType }
|
||||||
baseError = if (interested.isEmpty()) null else interested.joinToString("\n") { iface ->
|
baseError = if (interested.isEmpty()) null else interested.joinToString("\n") { iface ->
|
||||||
"$iface: " + try {
|
"$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) {
|
} catch (e: InvocationTargetException) {
|
||||||
if (Build.VERSION.SDK_INT !in 24..25 || e.cause !is SecurityException) Timber.w(e) else Timber.d(e)
|
if (Build.VERSION.SDK_INT !in 24..25 || e.cause !is SecurityException) Timber.w(e) else Timber.d(e)
|
||||||
e.readableMessage
|
e.readableMessage
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ import java.net.NetworkInterface
|
|||||||
import java.net.SocketException
|
import java.net.SocketException
|
||||||
|
|
||||||
class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClickListener {
|
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) }
|
internal val repeaterManager by lazy { RepeaterManager(this@TetheringFragment) }
|
||||||
@get:RequiresApi(26)
|
@get:RequiresApi(26)
|
||||||
internal val localOnlyHotspotManager by lazy @TargetApi(26) { LocalOnlyHotspotManager(this@TetheringFragment) }
|
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()
|
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) {
|
suspend fun notifyInterfaceChanged(lastList: List<Manager>? = null) {
|
||||||
@Suppress("NAME_SHADOWING") val lastList = lastList ?: listDeferred.await()
|
@Suppress("NAME_SHADOWING") val lastList = lastList ?: listDeferred.await()
|
||||||
val first = lastList.indexOfFirst { it is InterfaceManager }
|
val first = lastList.indexOfFirst { it is InterfaceManager }
|
||||||
@@ -104,11 +110,11 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
|||||||
list.add(ManageBar)
|
list.add(ManageBar)
|
||||||
if (Build.VERSION.SDK_INT >= 24) {
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
list.addAll(tetherManagers)
|
list.addAll(tetherManagers)
|
||||||
tetherManagers.forEach { it.updateErrorMessage(erroredIfaces) }
|
tetherManagers.forEach { it.updateErrorMessage(erroredIfaces, lastErrors) }
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= 30) {
|
if (Build.VERSION.SDK_INT >= 30) {
|
||||||
list.addAll(tetherManagers30)
|
list.addAll(tetherManagers30)
|
||||||
tetherManagers30.forEach { it.updateErrorMessage(erroredIfaces) }
|
tetherManagers30.forEach { it.updateErrorMessage(erroredIfaces, lastErrors) }
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT < 26) {
|
if (Build.VERSION.SDK_INT < 26) {
|
||||||
list.add(wifiManagerLegacy)
|
list.add(wifiManagerLegacy)
|
||||||
@@ -279,15 +285,20 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
|||||||
lifecycleScope.launchWhenStarted { adapter.notifyInterfaceChanged() }
|
lifecycleScope.launchWhenStarted { adapter.notifyInterfaceChanged() }
|
||||||
}
|
}
|
||||||
requireContext().registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
requireContext().registerReceiver(receiver, IntentFilter(TetheringManager.ACTION_TETHER_STATE_CHANGED))
|
||||||
if (Build.VERSION.SDK_INT >= 30) TetherType.listener[this] = {
|
if (Build.VERSION.SDK_INT >= 30) {
|
||||||
lifecycleScope.launchWhenStarted { adapter.notifyTetherTypeChanged() }
|
TetheringManager.registerTetheringEventCallback(null, adapter)
|
||||||
|
TetherType.listener[this] = { lifecycleScope.launchWhenStarted { adapter.notifyTetherTypeChanged() } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceDisconnected(name: ComponentName?) {
|
override fun onServiceDisconnected(name: ComponentName?) {
|
||||||
(binder ?: return).routingsChanged -= this
|
(binder ?: return).routingsChanged -= this
|
||||||
binder = null
|
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)
|
requireContext().unregisterReceiver(receiver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -629,6 +629,7 @@ object TetheringManager {
|
|||||||
* @return error The error code of the last error tethering or untethering the named
|
* @return error The error code of the last error tethering or untethering the named
|
||||||
* interface
|
* interface
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Use {@link TetheringEventCallback#onError(String, int)} instead.")
|
||||||
fun getLastTetherError(iface: String): Int = getLastTetherError(Services.connectivity, iface) as Int
|
fun getLastTetherError(iface: String): Int = getLastTetherError(Services.connectivity, iface) as Int
|
||||||
|
|
||||||
val tetherErrorLookup = ConstantLookup("TETHER_ERROR_",
|
val tetherErrorLookup = ConstantLookup("TETHER_ERROR_",
|
||||||
|
|||||||
Reference in New Issue
Block a user