Support ap error codes on Android 6-8.1
This commit is contained in:
@@ -73,8 +73,7 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope {
|
||||
}
|
||||
// based on: https://android.googlesource.com/platform/packages/services/Car/+/df5cd06/service/src/com/android/car/CarProjectionService.java#160
|
||||
val sticky = registerReceiver(null, IntentFilter(WifiApManager.WIFI_AP_STATE_CHANGED_ACTION))!!
|
||||
val apState = sticky.getIntExtra(WifiApManager.EXTRA_WIFI_AP_STATE,
|
||||
WifiApManager.WIFI_AP_STATE_DISABLED)
|
||||
val apState = sticky.getIntExtra(WifiApManager.EXTRA_WIFI_AP_STATE, 0)
|
||||
val iface = sticky.getStringExtra(WifiApManager.EXTRA_WIFI_AP_INTERFACE_NAME)
|
||||
if (apState != WifiApManager.WIFI_AP_STATE_ENABLED || iface.isNullOrEmpty()) {
|
||||
if (apState == WifiApManager.WIFI_AP_STATE_FAILED) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.Manifest
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Parcelable
|
||||
@@ -141,22 +142,32 @@ sealed class TetherManager(protected val parent: TetheringFragment) : Manager(),
|
||||
@RequiresApi(24)
|
||||
class Wifi(parent: TetheringFragment) : TetherManager(parent), DefaultLifecycleObserver,
|
||||
WifiApManager.SoftApCallbackCompat {
|
||||
private val receiver = broadcastReceiver { _, intent ->
|
||||
failureReason = if (intent.getIntExtra(WifiApManager.EXTRA_WIFI_AP_STATE, 0) ==
|
||||
WifiApManager.WIFI_AP_STATE_FAILED) {
|
||||
intent.getIntExtra(WifiApManager.EXTRA_WIFI_AP_FAILURE_REASON, 0)
|
||||
} else null
|
||||
data.notifyChange()
|
||||
}
|
||||
private var failureReason: Int? = null
|
||||
private var numClients: Int? = null
|
||||
private var info = emptyList<Parcelable>()
|
||||
private var capability: Parcelable? = null
|
||||
|
||||
init {
|
||||
if (Build.VERSION.SDK_INT >= 28) parent.viewLifecycleOwner.lifecycle.addObserver(this)
|
||||
if (Build.VERSION.SDK_INT >= 23) parent.viewLifecycleOwner.lifecycle.addObserver(this)
|
||||
}
|
||||
|
||||
@TargetApi(28)
|
||||
override fun onStart(owner: LifecycleOwner) {
|
||||
WifiApCommands.registerSoftApCallback(this)
|
||||
if (Build.VERSION.SDK_INT < 28) {
|
||||
parent.requireContext().registerReceiver(receiver,
|
||||
IntentFilter(WifiApManager.WIFI_AP_STATE_CHANGED_ACTION))
|
||||
} else WifiApCommands.registerSoftApCallback(this)
|
||||
}
|
||||
@TargetApi(28)
|
||||
override fun onStop(owner: LifecycleOwner) {
|
||||
WifiApCommands.unregisterSoftApCallback(this)
|
||||
if (Build.VERSION.SDK_INT < 28) {
|
||||
parent.requireContext().unregisterReceiver(receiver)
|
||||
} else WifiApCommands.unregisterSoftApCallback(this)
|
||||
}
|
||||
|
||||
override fun onStateChanged(state: Int, failureReason: Int) {
|
||||
|
||||
Reference in New Issue
Block a user