Fix a crash caused by race
This commit is contained in:
@@ -16,6 +16,7 @@ import android.os.Parcelable
|
|||||||
import android.text.method.LinkMovementMethod
|
import android.text.method.LinkMovementMethod
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
|
import androidx.annotation.MainThread
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.databinding.BaseObservable
|
import androidx.databinding.BaseObservable
|
||||||
@@ -160,7 +161,8 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val configuration: WifiConfiguration? get() {
|
@MainThread
|
||||||
|
suspend fun getConfiguration(): WifiConfiguration? {
|
||||||
if (RepeaterService.safeMode) {
|
if (RepeaterService.safeMode) {
|
||||||
val networkName = RepeaterService.networkName
|
val networkName = RepeaterService.networkName
|
||||||
val passphrase = RepeaterService.passphrase
|
val passphrase = RepeaterService.passphrase
|
||||||
@@ -179,7 +181,10 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
} else {
|
} else {
|
||||||
val group = binder?.group
|
val group = binder?.group
|
||||||
if (group != null) try {
|
if (group != null) try {
|
||||||
val config = P2pSupplicantConfiguration(group, binder?.thisDevice?.deviceAddress)
|
val config = withContext(Dispatchers.Default) {
|
||||||
|
P2pSupplicantConfiguration(group, binder?.thisDevice?.deviceAddress)
|
||||||
|
}
|
||||||
|
if (parent.isDetached) return null // if we took too long
|
||||||
holder.config = config
|
holder.config = config
|
||||||
return newWifiApConfiguration(group.networkName, config.psk).apply {
|
return newWifiApConfiguration(group.networkName, config.psk).apply {
|
||||||
allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK) // is not actually used
|
allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK) // is not actually used
|
||||||
|
|||||||
@@ -127,9 +127,10 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
|||||||
}
|
}
|
||||||
R.id.configuration_repeater -> {
|
R.id.configuration_repeater -> {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
WifiApDialogFragment().withArg(WifiApDialogFragment.Arg(withContext(Dispatchers.Default) {
|
adapter.repeaterManager.getConfiguration()?.let { config ->
|
||||||
adapter.repeaterManager.configuration
|
WifiApDialogFragment().withArg(WifiApDialogFragment.Arg(config, p2pMode = true)).show(
|
||||||
} ?: return@launchWhenCreated, p2pMode = true)).show(this@TetheringFragment, CONFIGURE_REPEATER)
|
this@TetheringFragment, CONFIGURE_REPEATER)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user