From 46bf98d7f67c443d393cde056f7f6e79ae32f320 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 2 Apr 2023 15:18:26 +0200 Subject: 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 --- .../java/com/wireguard/android/viewmodel/ConfigProxy.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'ui/src/main/java/com/wireguard') 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 = 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 { -- cgit v1.2.3