Handle new nullability issues

This commit is contained in:
Mygod
2019-04-14 12:24:17 +08:00
parent 313f0da7f9
commit 219d868089
2 changed files with 44 additions and 40 deletions

View File

@@ -271,24 +271,27 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
/**
* startService Step 2 (if a group isn't already available)
*/
private fun doStart() = try {
private fun doStart() {
val listener = object : WifiP2pManager.ActionListener {
override fun onFailure(reason: Int) {
startFailure(formatReason(R.string.repeater_create_group_failure, reason))
}
override fun onSuccess() { } // wait for WIFI_P2P_CONNECTION_CHANGED_ACTION to fire to go to step 3
}
val channel = channel ?: return listener.onFailure(WifiP2pManager.BUSY)
val networkName = networkName
val passphrase = passphrase
try {
if (!BuildCompat.isAtLeastQ() || networkName == null || passphrase == null) {
persistNextGroup = true
p2pManager.createGroup(channel, listener)
} else p2pManager.createGroup(channel, WifiP2pConfig.Builder().apply {
setNetworkName(PLACEHOLDER_NETWORK_NAME)
setPassphrase(passphrase)
val channel = operatingChannel
if (channel == 0) setGroupOperatingBand(operatingBand)
else setGroupOperatingFrequency(channelToFrequency(channel))
operatingChannel.let { oc ->
if (oc == 0) setGroupOperatingBand(operatingBand)
else setGroupOperatingFrequency(channelToFrequency(oc))
}
}.build().run {
useParcel { p ->
p.writeParcelable(this, 0)
@@ -318,6 +321,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
Timber.w(e)
startFailure(e.readableMessage)
}
}
/**
* Used during step 2, also called when connection changed
*/

View File

@@ -177,8 +177,8 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
override fun onMenuItemClick(item: MenuItem?): Boolean {
return when (item?.itemId) {
android.R.id.copy -> {
app.clipboard.primaryClip = ClipData.newPlainText(null,
Base64.encodeToString(ret.configuration.toByteArray(), BASE64_FLAGS))
app.clipboard.setPrimaryClip(ClipData.newPlainText(null,
Base64.encodeToString(ret.configuration.toByteArray(), BASE64_FLAGS)))
true
}
android.R.id.paste -> {