requestGroupInfo in main thread

This commit is contained in:
Mygod
2019-08-01 12:57:08 +08:00
parent e55aa17399
commit 9fb7fd25c1

View File

@@ -258,26 +258,24 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
} }
registerReceiver(receiver, intentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION, registerReceiver(receiver, intentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION,
WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)) WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION))
launch { try {
try { p2pManager.requestGroupInfo(channel) {
p2pManager.requestGroupInfo(channel) { when {
when { it == null -> doStart()
it == null -> doStart() it.isGroupOwner -> launch { if (routingManager == null) doStartLocked(it) }
it.isGroupOwner -> launch { if (routingManager == null) doStartLocked(it) } else -> {
else -> { Timber.i("Removing old group ($it)")
Timber.i("Removing old group ($it)") p2pManager.removeGroup(channel, object : WifiP2pManager.ActionListener {
p2pManager.removeGroup(channel, object : WifiP2pManager.ActionListener { override fun onSuccess() = doStart()
override fun onSuccess() = doStart() override fun onFailure(reason: Int) =
override fun onFailure(reason: Int) = startFailure(formatReason(R.string.repeater_remove_old_group_failure, reason))
startFailure(formatReason(R.string.repeater_remove_old_group_failure, reason)) })
})
}
} }
} }
} catch (e: SecurityException) {
Timber.w(e)
startFailure(e.readableMessage)
} }
} catch (e: RuntimeException) {
Timber.w(e)
startFailure(e.readableMessage)
} }
return START_NOT_STICKY return START_NOT_STICKY
} }