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) * startService Step 2 (if a group isn't already available)
*/ */
private fun doStart() = try { private fun doStart() {
val listener = object : WifiP2pManager.ActionListener { val listener = object : WifiP2pManager.ActionListener {
override fun onFailure(reason: Int) { override fun onFailure(reason: Int) {
startFailure(formatReason(R.string.repeater_create_group_failure, reason)) 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 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 networkName = networkName
val passphrase = passphrase val passphrase = passphrase
try {
if (!BuildCompat.isAtLeastQ() || networkName == null || passphrase == null) { if (!BuildCompat.isAtLeastQ() || networkName == null || passphrase == null) {
persistNextGroup = true persistNextGroup = true
p2pManager.createGroup(channel, listener) p2pManager.createGroup(channel, listener)
} else p2pManager.createGroup(channel, WifiP2pConfig.Builder().apply { } else p2pManager.createGroup(channel, WifiP2pConfig.Builder().apply {
setNetworkName(PLACEHOLDER_NETWORK_NAME) setNetworkName(PLACEHOLDER_NETWORK_NAME)
setPassphrase(passphrase) setPassphrase(passphrase)
val channel = operatingChannel operatingChannel.let { oc ->
if (channel == 0) setGroupOperatingBand(operatingBand) if (oc == 0) setGroupOperatingBand(operatingBand)
else setGroupOperatingFrequency(channelToFrequency(channel)) else setGroupOperatingFrequency(channelToFrequency(oc))
}
}.build().run { }.build().run {
useParcel { p -> useParcel { p ->
p.writeParcelable(this, 0) p.writeParcelable(this, 0)
@@ -318,6 +321,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
Timber.w(e) Timber.w(e)
startFailure(e.readableMessage) startFailure(e.readableMessage)
} }
}
/** /**
* Used during step 2, also called when connection changed * 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 { override fun onMenuItemClick(item: MenuItem?): Boolean {
return when (item?.itemId) { return when (item?.itemId) {
android.R.id.copy -> { android.R.id.copy -> {
app.clipboard.primaryClip = ClipData.newPlainText(null, app.clipboard.setPrimaryClip(ClipData.newPlainText(null,
Base64.encodeToString(ret.configuration.toByteArray(), BASE64_FLAGS)) Base64.encodeToString(ret.configuration.toByteArray(), BASE64_FLAGS)))
true true
} }
android.R.id.paste -> { android.R.id.paste -> {