Remove unnecessary try-catch

This commit is contained in:
Mygod
2021-06-04 02:06:06 -04:00
parent 880843c8cb
commit 02e7f06e61

View File

@@ -394,7 +394,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
}
val networkName = networkName
val passphrase = passphrase
try {
@SuppressLint("MissingPermission") // missing permission will simply leading to returning ERROR
if (!safeMode || networkName == null || passphrase == null) {
persistNextGroup = true
p2pManager.createGroup(channel, listener)
@@ -404,7 +404,12 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
mNetworkName.set(this, networkName) // bypass networkName check
} catch (e: ReflectiveOperationException) {
Timber.w(e)
try {
setNetworkName(networkName)
} catch (e: IllegalArgumentException) {
Timber.w(e)
return startFailure(e.readableMessage)
}
}
setPassphrase(passphrase)
when (val oc = operatingChannel) {
@@ -423,13 +428,6 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
setDeviceAddress(deviceAddress?.toPlatform())
}.build(), listener)
}
} catch (e: SecurityException) {
Timber.w(e)
startFailure(e.readableMessage)
} catch (e: IllegalArgumentException) {
Timber.w(e)
startFailure(e.readableMessage)
}
}
/**
* Used during step 2, also called when connection changed
@@ -481,8 +479,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
private fun showNotification(group: WifiP2pGroup? = null) = ServiceNotification.startForeground(this,
if (group == null) emptyMap() else mapOf(Pair(group.`interface`, group.clientList?.size ?: 0)))
private fun removeGroup() {
p2pManager.removeGroup(channel, object : WifiP2pManager.ActionListener {
private fun removeGroup() = p2pManager.removeGroup(channel, object : WifiP2pManager.ActionListener {
override fun onSuccess() {
launch { cleanLocked() }
}
@@ -490,10 +487,9 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
if (reason != WifiP2pManager.BUSY) {
SmartSnackbar.make(formatReason(R.string.repeater_remove_group_failure, reason)).show()
} // else assuming it's already gone
launch { cleanLocked() }
onSuccess()
}
})
}
private fun cleanLocked() {
if (receiverRegistered) {
ensureReceiverUnregistered(receiver)