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