Workaround for using inline class with Parcelize

This commit is contained in:
Mygod
2020-06-05 13:17:52 -04:00
parent df136151e3
commit 195133e782
3 changed files with 14 additions and 7 deletions

View File

@@ -10,8 +10,7 @@ import java.nio.ByteOrder
/** /**
* Compat support class for [MacAddress]. * Compat support class for [MacAddress].
*/ */
@Parcelize inline class MacAddressCompat(val addr: Long) {
inline class MacAddressCompat(val addr: Long) : Parcelable {
companion object { companion object {
private const val ETHER_ADDR_LEN = 6 private const val ETHER_ADDR_LEN = 6
/** /**

View File

@@ -20,7 +20,8 @@ data class SoftApConfigurationCompat(
var band: Int, var band: Int,
@RequiresApi(23) @RequiresApi(23)
var channel: Int, var channel: Int,
var bssid: MacAddressCompat?, @Deprecated("Workaround for using inline class with Parcelize, use bssid")
var bssidAddr: Long?,
var maxNumberOfClients: Int, var maxNumberOfClients: Int,
@RequiresApi(28) @RequiresApi(28)
var shutdownTimeoutMillis: Long, var shutdownTimeoutMillis: Long,
@@ -184,7 +185,7 @@ data class SoftApConfigurationCompat(
preSharedKey, preSharedKey,
if (Build.VERSION.SDK_INT >= 23) apBand.getInt(this) else BAND_ANY, // TODO if (Build.VERSION.SDK_INT >= 23) apBand.getInt(this) else BAND_ANY, // TODO
if (Build.VERSION.SDK_INT >= 23) apChannel.getInt(this) else CH_INVALID, // TODO if (Build.VERSION.SDK_INT >= 23) apChannel.getInt(this) else CH_INVALID, // TODO
BSSID?.let { MacAddressCompat.fromString(it) }, BSSID?.let { MacAddressCompat.fromString(it) }?.addr,
0, // TODO: unsupported field should have @RequiresApi? 0, // TODO: unsupported field should have @RequiresApi?
if (Build.VERSION.SDK_INT >= 28) { if (Build.VERSION.SDK_INT >= 28) {
TetherTimeoutMonitor.timeout.toLong() TetherTimeoutMonitor.timeout.toLong()
@@ -204,7 +205,7 @@ data class SoftApConfigurationCompat(
passphrase, passphrase,
getBand(this) as Int, getBand(this) as Int,
getChannel(this) as Int, getChannel(this) as Int,
bssid?.toCompat(), bssid?.toCompat()?.addr,
getMaxNumberOfClients(this) as Int, getMaxNumberOfClients(this) as Int,
getShutdownTimeoutMillis(this) as Long, getShutdownTimeoutMillis(this) as Long,
isAutoShutdownEnabled(this) as Boolean, isAutoShutdownEnabled(this) as Boolean,
@@ -222,6 +223,13 @@ data class SoftApConfigurationCompat(
if (Build.VERSION.SDK_INT >= 28) TetherTimeoutMonitor.enabled else false, false, false, null, null) if (Build.VERSION.SDK_INT >= 28) TetherTimeoutMonitor.enabled else false, false, false, null, null)
} }
@Suppress("DEPRECATION")
var bssid: MacAddressCompat?
get() = bssidAddr?.let { MacAddressCompat(it) }
set(value) {
bssidAddr = value?.addr
}
/** /**
* Based on: * Based on:
* https://android.googlesource.com/platform/packages/apps/Settings/+/android-5.0.0_r1/src/com/android/settings/wifi/WifiApDialog.java#88 * https://android.googlesource.com/platform/packages/apps/Settings/+/android-5.0.0_r1/src/com/android/settings/wifi/WifiApDialog.java#88

View File

@@ -81,8 +81,8 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
override val ret get() = Arg(arg.configuration.copy( override val ret get() = Arg(arg.configuration.copy(
ssid = dialogView.ssid.text.toString(), ssid = dialogView.ssid.text.toString(),
passphrase = if (dialogView.password.length() != 0) dialogView.password.text.toString() else null, passphrase = if (dialogView.password.length() != 0) dialogView.password.text.toString() else null,
bssid = if (dialogView.bssid.length() != 0) { bssidAddr = if (dialogView.bssid.length() != 0) {
MacAddressCompat.fromString(dialogView.bssid.toString()) MacAddressCompat.fromString(dialogView.bssid.toString()).addr
} else null).apply { } else null).apply {
if (!arg.p2pMode) { if (!arg.p2pMode) {
securityType = dialogView.security.selectedItemPosition securityType = dialogView.security.selectedItemPosition