diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-04-02 15:18:26 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2023-04-04 15:31:52 +0200 |
commit | 46bf98d7f67c443d393cde056f7f6e79ae32f320 (patch) | |
tree | 59c5e148933516abae77636c17c3315e3b7c8bce /ui/src/main/java/com/wireguard | |
parent | 3e9ddd87203899a11e6887e448bf4510cb2b9e8a (diff) |
ui: never access CREATOR directly
All of the parcelers have their own type prefix. So we have to actually
use the legit methods. This is a bit annoying, as there's no fully
compatible way across all API versions, so we have to branch.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com/wireguard')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.kt | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/ui/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.kt b/ui/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.kt index e29de2dd..0be18a6f 100644 --- a/ui/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.kt +++ b/ui/src/main/java/com/wireguard/android/viewmodel/ConfigProxy.kt @@ -4,22 +4,27 @@ */ package com.wireguard.android.viewmodel +import android.os.Build import android.os.Parcel import android.os.Parcelable +import androidx.core.os.ParcelCompat import androidx.databinding.ObservableArrayList import androidx.databinding.ObservableList import com.wireguard.config.BadConfigException import com.wireguard.config.Config import com.wireguard.config.Peer -import java.util.ArrayList class ConfigProxy : Parcelable { val `interface`: InterfaceProxy val peers: ObservableList<PeerProxy> = ObservableArrayList() private constructor(parcel: Parcel) { - `interface` = InterfaceProxy.CREATOR.createFromParcel(parcel) - parcel.readTypedList(peers, PeerProxy.CREATOR) + `interface` = ParcelCompat.readParcelable(parcel, InterfaceProxy::class.java.classLoader, InterfaceProxy::class.java) ?: InterfaceProxy() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + ParcelCompat.readParcelableList(parcel, peers, PeerProxy::class.java.classLoader, PeerProxy::class.java) + } else { + parcel.readTypedList(peers, PeerProxy.CREATOR) + } peers.forEach { it.bind(this) } } @@ -57,7 +62,11 @@ class ConfigProxy : Parcelable { override fun writeToParcel(dest: Parcel, flags: Int) { dest.writeParcelable(`interface`, flags) - dest.writeTypedList(peers) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + dest.writeParcelableList(peers, flags) + } else { + dest.writeTypedList(peers) + } } private class ConfigProxyCreator : Parcelable.Creator<ConfigProxy> { |