package D;

import android.app.Notification;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import java.util.ArrayList;

/* JADX INFO: loaded from: classes.dex */
public final class D {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final CharSequence f294a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final long f295b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Y f296c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Bundle f297d = new Bundle();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public String f298e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Uri f299f;

    public D(CharSequence charSequence, long j5, Y y5) {
        this.f294a = charSequence;
        this.f295b = j5;
        this.f296c = y5;
    }

    public static Bundle[] a(ArrayList arrayList) {
        Bundle[] bundleArr = new Bundle[arrayList.size()];
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            D d3 = (D) arrayList.get(i);
            d3.getClass();
            Bundle bundle = new Bundle();
            CharSequence charSequence = d3.f294a;
            if (charSequence != null) {
                bundle.putCharSequence("text", charSequence);
            }
            bundle.putLong("time", d3.f295b);
            Y y5 = d3.f296c;
            if (y5 != null) {
                bundle.putCharSequence("sender", y5.f348a);
                if (Build.VERSION.SDK_INT >= 28) {
                    bundle.putParcelable("sender_person", C.a(M.r(y5)));
                } else {
                    bundle.putBundle("person", y5.b());
                }
            }
            String str = d3.f298e;
            if (str != null) {
                bundle.putString("type", str);
            }
            Uri uri = d3.f299f;
            if (uri != null) {
                bundle.putParcelable("uri", uri);
            }
            Bundle bundle2 = d3.f297d;
            if (bundle2 != null) {
                bundle.putBundle("extras", bundle2);
            }
            bundleArr[i] = bundle;
        }
        return bundleArr;
    }

    public static ArrayList b(Parcelable[] parcelableArr) {
        Y yC;
        ArrayList arrayList = new ArrayList(parcelableArr.length);
        for (Parcelable parcelable : parcelableArr) {
            if (parcelable instanceof Bundle) {
                Bundle bundle = (Bundle) parcelable;
                D d3 = null;
                try {
                    if (bundle.containsKey("text") && bundle.containsKey("time")) {
                        if (bundle.containsKey("person")) {
                            yC = Y.a(bundle.getBundle("person"));
                        } else if (bundle.containsKey("sender_person") && Build.VERSION.SDK_INT >= 28) {
                            yC = M.c(AbstractC0046q.d(bundle.getParcelable("sender_person")));
                        } else if (bundle.containsKey("sender")) {
                            CharSequence charSequence = bundle.getCharSequence("sender");
                            Y y5 = new Y();
                            y5.f348a = charSequence;
                            y5.f349b = null;
                            y5.f350c = null;
                            y5.f351d = null;
                            y5.f352e = false;
                            y5.f353f = false;
                            yC = y5;
                        } else {
                            yC = null;
                        }
                        D d6 = new D(bundle.getCharSequence("text"), bundle.getLong("time"), yC);
                        if (bundle.containsKey("type") && bundle.containsKey("uri")) {
                            String string = bundle.getString("type");
                            Uri uri = (Uri) bundle.getParcelable("uri");
                            d6.f298e = string;
                            d6.f299f = uri;
                        }
                        if (bundle.containsKey("extras")) {
                            d6.f297d.putAll(bundle.getBundle("extras"));
                        }
                        d3 = d6;
                    }
                } catch (ClassCastException unused) {
                }
                if (d3 != null) {
                    arrayList.add(d3);
                }
            }
        }
        return arrayList;
    }

    public final Notification.MessagingStyle.Message c() {
        Notification.MessagingStyle.Message messageA;
        int i = Build.VERSION.SDK_INT;
        long j5 = this.f295b;
        CharSequence charSequence = this.f294a;
        Y y5 = this.f296c;
        if (i >= 28) {
            messageA = C.b(charSequence, j5, y5 != null ? M.r(y5) : null);
        } else {
            messageA = B.a(charSequence, j5, y5 != null ? y5.f348a : null);
        }
        String str = this.f298e;
        if (str != null) {
            B.b(messageA, str, this.f299f);
        }
        return messageA;
    }
}
