Handle new nullability issues
This commit is contained in:
@@ -271,52 +271,56 @@ 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
|
||||||
if (!BuildCompat.isAtLeastQ() || networkName == null || passphrase == null) {
|
try {
|
||||||
persistNextGroup = true
|
if (!BuildCompat.isAtLeastQ() || networkName == null || passphrase == null) {
|
||||||
p2pManager.createGroup(channel, listener)
|
persistNextGroup = true
|
||||||
} else p2pManager.createGroup(channel, WifiP2pConfig.Builder().apply {
|
p2pManager.createGroup(channel, listener)
|
||||||
setNetworkName(PLACEHOLDER_NETWORK_NAME)
|
} else p2pManager.createGroup(channel, WifiP2pConfig.Builder().apply {
|
||||||
setPassphrase(passphrase)
|
setNetworkName(PLACEHOLDER_NETWORK_NAME)
|
||||||
val channel = operatingChannel
|
setPassphrase(passphrase)
|
||||||
if (channel == 0) setGroupOperatingBand(operatingBand)
|
operatingChannel.let { oc ->
|
||||||
else setGroupOperatingFrequency(channelToFrequency(channel))
|
if (oc == 0) setGroupOperatingBand(operatingBand)
|
||||||
}.build().run {
|
else setGroupOperatingFrequency(channelToFrequency(oc))
|
||||||
useParcel { p ->
|
}
|
||||||
p.writeParcelable(this, 0)
|
}.build().run {
|
||||||
val end = p.dataPosition()
|
useParcel { p ->
|
||||||
p.setDataPosition(0)
|
p.writeParcelable(this, 0)
|
||||||
val creator = p.readString()
|
val end = p.dataPosition()
|
||||||
val deviceAddress = p.readString()
|
p.setDataPosition(0)
|
||||||
val wps = p.readParcelable<WpsInfo>(javaClass.classLoader)
|
val creator = p.readString()
|
||||||
val long = p.readLong()
|
val deviceAddress = p.readString()
|
||||||
check(p.readString() == PLACEHOLDER_NETWORK_NAME)
|
val wps = p.readParcelable<WpsInfo>(javaClass.classLoader)
|
||||||
check(p.readString() == passphrase)
|
val long = p.readLong()
|
||||||
val int = p.readInt()
|
check(p.readString() == PLACEHOLDER_NETWORK_NAME)
|
||||||
check(p.dataPosition() == end)
|
check(p.readString() == passphrase)
|
||||||
p.setDataPosition(0)
|
val int = p.readInt()
|
||||||
p.writeString(creator)
|
check(p.dataPosition() == end)
|
||||||
p.writeString(deviceAddress)
|
p.setDataPosition(0)
|
||||||
p.writeParcelable(wps, 0)
|
p.writeString(creator)
|
||||||
p.writeLong(long)
|
p.writeString(deviceAddress)
|
||||||
p.writeString(networkName)
|
p.writeParcelable(wps, 0)
|
||||||
p.writeString(passphrase)
|
p.writeLong(long)
|
||||||
p.writeInt(int)
|
p.writeString(networkName)
|
||||||
p.setDataPosition(0)
|
p.writeString(passphrase)
|
||||||
p.readParcelable<WifiP2pConfig>(javaClass.classLoader)
|
p.writeInt(int)
|
||||||
}
|
p.setDataPosition(0)
|
||||||
}, listener)
|
p.readParcelable<WifiP2pConfig>(javaClass.classLoader)
|
||||||
} catch (e: SecurityException) {
|
}
|
||||||
Timber.w(e)
|
}, listener)
|
||||||
startFailure(e.readableMessage)
|
} catch (e: SecurityException) {
|
||||||
|
Timber.w(e)
|
||||||
|
startFailure(e.readableMessage)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Used during step 2, also called when connection changed
|
* Used during step 2, also called when connection changed
|
||||||
|
|||||||
@@ -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 -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user