package com.google.android.gms.common.internal.safeparcel; import android.content.Intent; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import com.google.android.gms.common.internal.Preconditions; import com.google.android.gms.common.util.Base64Utils; import com.google.android.gms.internal.common.zzag; import java.util.ArrayList; import java.util.Iterator; import org.simpleframework.xml.core.FieldScanner; /* loaded from: classes.dex */ public final class SafeParcelableSerializer { public static T deserializeFromBytes(byte[] bArr, Parcelable.Creator creator) { Preconditions.checkNotNull(creator); Parcel obtain = Parcel.obtain(); obtain.unmarshall(bArr, 0, bArr.length); obtain.setDataPosition(0); T createFromParcel = creator.createFromParcel(obtain); obtain.recycle(); return createFromParcel; } public static T deserializeFromIntentExtra(Intent intent, String str, Parcelable.Creator creator) { byte[] byteArrayExtra = intent.getByteArrayExtra(str); if (byteArrayExtra == null) { return null; } return (T) deserializeFromBytes(byteArrayExtra, creator); } public static T deserializeFromString(String str, Parcelable.Creator creator) { return (T) deserializeFromBytes(Base64Utils.decodeUrlSafe(str), creator); } @Deprecated public static ArrayList deserializeIterableFromBundle(Bundle bundle, String str, Parcelable.Creator creator) { ArrayList arrayList = (ArrayList) bundle.getSerializable(str); if (arrayList == null) { return null; } FieldScanner fieldScanner = (ArrayList) new ArrayList(arrayList.size()); int size = arrayList.size(); for (int i = 0; i < size; i++) { fieldScanner.add(deserializeFromBytes((byte[]) arrayList.get(i), creator)); } return fieldScanner; } public static ArrayList deserializeIterableFromBundleSafe(Bundle bundle, String str, Parcelable.Creator creator) { return deserializeIterableFromBytes(bundle.getByteArray(str), creator); } public static ArrayList deserializeIterableFromBytes(byte[] bArr, Parcelable.Creator creator) { if (bArr == null) { return null; } int length = bArr.length; Parcel obtain = Parcel.obtain(); obtain.unmarshall(bArr, 0, length); obtain.setDataPosition(0); try { ArrayList arrayList = new ArrayList<>(); obtain.readTypedList(arrayList, creator); return arrayList; } finally { obtain.recycle(); } } @Deprecated public static ArrayList deserializeIterableFromIntentExtra(Intent intent, String str, Parcelable.Creator creator) { ArrayList arrayList = (ArrayList) intent.getSerializableExtra(str); if (arrayList == null) { return null; } FieldScanner fieldScanner = (ArrayList) new ArrayList(arrayList.size()); int size = arrayList.size(); for (int i = 0; i < size; i++) { fieldScanner.add(deserializeFromBytes((byte[]) arrayList.get(i), creator)); } return fieldScanner; } public static ArrayList deserializeIterableFromIntentExtraSafe(Intent intent, String str, Parcelable.Creator creator) { return deserializeIterableFromBytes(intent.getByteArrayExtra(str), creator); } @Deprecated public static void serializeIterableToBundle(Iterable iterable, Bundle bundle, String str) { ArrayList arrayList = new ArrayList(); Iterator it = iterable.iterator(); while (it.hasNext()) { arrayList.add(serializeToBytes(it.next())); } bundle.putSerializable(str, arrayList); } public static void serializeIterableToBundleSafe(Iterable iterable, Bundle bundle, String str) { bundle.putByteArray(str, zza(iterable)); } @Deprecated public static void serializeIterableToIntentExtra(Iterable iterable, Intent intent, String str) { ArrayList arrayList = new ArrayList(); Iterator it = iterable.iterator(); while (it.hasNext()) { arrayList.add(serializeToBytes(it.next())); } intent.putExtra(str, arrayList); } public static void serializeIterableToIntentExtraSafe(Iterable iterable, Intent intent, String str) { intent.putExtra(str, zza(iterable)); } public static byte[] serializeToBytes(T t) { Parcel obtain = Parcel.obtain(); t.writeToParcel(obtain, 0); byte[] marshall = obtain.marshall(); obtain.recycle(); return marshall; } public static void serializeToIntentExtra(T t, Intent intent, String str) { intent.putExtra(str, serializeToBytes(t)); } public static String serializeToString(T t) { return Base64Utils.encodeUrlSafe(serializeToBytes(t)); } private static byte[] zza(Iterable iterable) { Parcel obtain = Parcel.obtain(); try { obtain.writeTypedList(zzag.zzj(iterable)); return obtain.marshall(); } finally { obtain.recycle(); } } private SafeParcelableSerializer() { } }