Refine shutdown(msg)
This commit is contained in:
@@ -88,11 +88,12 @@ class HotspotService : Service(), WifiP2pManager.ChannelListener {
|
|||||||
|
|
||||||
private fun doStart() {
|
private fun doStart() {
|
||||||
p2pManager.createGroup(channel, object : WifiP2pManager.ActionListener, WifiP2pManager.GroupInfoListener {
|
p2pManager.createGroup(channel, object : WifiP2pManager.ActionListener, WifiP2pManager.GroupInfoListener {
|
||||||
private fun shutdown() {
|
private fun shutdown(msg: String) {
|
||||||
startForeground(0, NotificationCompat.Builder(this@HotspotService, CHANNEL)
|
Toast.makeText(this@HotspotService, msg, Toast.LENGTH_SHORT).show()
|
||||||
.build())
|
startForeground(0, NotificationCompat.Builder(this@HotspotService, CHANNEL).build())
|
||||||
clean()
|
clean()
|
||||||
}
|
}
|
||||||
|
override fun onFailure(reason: Int) = shutdown("Failed to create P2P group (reason: $reason)")
|
||||||
|
|
||||||
private var tries = 0
|
private var tries = 0
|
||||||
override fun onSuccess() = p2pManager.requestGroupInfo(channel, this)
|
override fun onSuccess() = p2pManager.requestGroupInfo(channel, this)
|
||||||
@@ -100,16 +101,7 @@ class HotspotService : Service(), WifiP2pManager.ChannelListener {
|
|||||||
if (group != null && group.isGroupOwner) doStart(group) else if (tries < 10) {
|
if (group != null && group.isGroupOwner) doStart(group) else if (tries < 10) {
|
||||||
Thread.sleep(30L shl tries++)
|
Thread.sleep(30L shl tries++)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
} else {
|
} else shutdown("Unexpected group: $group")
|
||||||
Log.w(TAG, "Unexpected group: $group")
|
|
||||||
shutdown()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(reason: Int) {
|
|
||||||
Toast.makeText(this@HotspotService, "Failed to create P2P group (reason: $reason)",
|
|
||||||
Toast.LENGTH_SHORT).show()
|
|
||||||
shutdown()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user