|
4 | 4 | */
|
5 | 5 | package com.wireguard.android.viewmodel
|
6 | 6 |
|
| 7 | +import android.os.Build |
7 | 8 | import android.os.Parcel
|
8 | 9 | import android.os.Parcelable
|
| 10 | +import androidx.core.os.ParcelCompat |
9 | 11 | import androidx.databinding.ObservableArrayList
|
10 | 12 | import androidx.databinding.ObservableList
|
11 | 13 | import com.wireguard.config.BadConfigException
|
12 | 14 | import com.wireguard.config.Config
|
13 | 15 | import com.wireguard.config.Peer
|
14 |
| -import java.util.ArrayList |
15 | 16 |
|
16 | 17 | class ConfigProxy : Parcelable {
|
17 | 18 | val `interface`: InterfaceProxy
|
18 | 19 | val peers: ObservableList<PeerProxy> = ObservableArrayList()
|
19 | 20 |
|
20 | 21 | private constructor(parcel: Parcel) {
|
21 |
| - `interface` = InterfaceProxy.CREATOR.createFromParcel(parcel) |
22 |
| - parcel.readTypedList(peers, PeerProxy.CREATOR) |
| 22 | + `interface` = ParcelCompat.readParcelable(parcel, InterfaceProxy::class.java.classLoader, InterfaceProxy::class.java) ?: InterfaceProxy() |
| 23 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
| 24 | + ParcelCompat.readParcelableList(parcel, peers, PeerProxy::class.java.classLoader, PeerProxy::class.java) |
| 25 | + } else { |
| 26 | + parcel.readTypedList(peers, PeerProxy.CREATOR) |
| 27 | + } |
23 | 28 | peers.forEach { it.bind(this) }
|
24 | 29 | }
|
25 | 30 |
|
@@ -57,7 +62,11 @@ class ConfigProxy : Parcelable {
|
57 | 62 |
|
58 | 63 | override fun writeToParcel(dest: Parcel, flags: Int) {
|
59 | 64 | dest.writeParcelable(`interface`, flags)
|
60 |
| - dest.writeTypedList(peers) |
| 65 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
| 66 | + dest.writeParcelableList(peers, flags) |
| 67 | + } else { |
| 68 | + dest.writeTypedList(peers) |
| 69 | + } |
61 | 70 | }
|
62 | 71 |
|
63 | 72 | private class ConfigProxyCreator : Parcelable.Creator<ConfigProxy> {
|
|
0 commit comments