package androidx.core.app;

import android.app.Notification;
import android.app.RemoteInput;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.RemoteViews;
import androidx.annotation.Nullable;
import androidx.core.graphics.drawable.IconCompat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import tv.danmaku.ijk.media.player.IjkMediaMeta;

/* JADX INFO: loaded from: classes.dex */
public final class l1 implements z {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Notification.Builder f1598b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Bundle f1600d;

    public l1(s0 s0Var) {
        ArrayList<z1> arrayList;
        int i10;
        Bundle[] bundleArr;
        ArrayList arrayList2;
        ArrayList arrayList3;
        l1 l1Var = this;
        new ArrayList();
        l1Var.f1600d = new Bundle();
        l1Var.f1599c = s0Var;
        Context context = s0Var.f1646a;
        l1Var.f1597a = context;
        if (Build.VERSION.SDK_INT >= 26) {
            l1Var.f1598b = a0.c(context, s0Var.J);
        } else {
            l1Var.f1598b = new Notification.Builder(s0Var.f1646a);
        }
        Notification notification = s0Var.Q;
        int i11 = 0;
        l1Var.f1598b.setWhen(notification.when).setSmallIcon(notification.icon, notification.iconLevel).setContent(notification.contentView).setTicker(notification.tickerText, s0Var.f1654i).setVibrate(notification.vibrate).setLights(notification.ledARGB, notification.ledOnMS, notification.ledOffMS).setOngoing((notification.flags & 2) != 0).setOnlyAlertOnce((notification.flags & 8) != 0).setAutoCancel((notification.flags & 16) != 0).setDefaults(notification.defaults).setContentTitle(s0Var.f1650e).setContentText(s0Var.f1651f).setContentInfo(s0Var.f1656k).setContentIntent(s0Var.f1652g).setDeleteIntent(notification.deleteIntent).setFullScreenIntent(s0Var.f1653h, (notification.flags & 128) != 0).setNumber(s0Var.f1657l).setProgress(s0Var.f1665t, s0Var.f1666u, s0Var.f1667v);
        Notification.Builder builder = l1Var.f1598b;
        IconCompat iconCompat = s0Var.f1655j;
        builder.setLargeIcon(iconCompat == null ? null : iconCompat.toIcon(context));
        l1Var.f1598b.setSubText(s0Var.f1662q).setUsesChronometer(s0Var.f1660o).setPriority(s0Var.f1658m);
        j1 j1Var = s0Var.f1661p;
        if (j1Var instanceof y0) {
            Iterator it = ((y0) j1Var).c().iterator();
            while (it.hasNext()) {
                l1Var.a((g0) it.next());
            }
        } else {
            Iterator it2 = s0Var.f1647b.iterator();
            while (it2.hasNext()) {
                l1Var.a((g0) it2.next());
            }
        }
        Bundle bundle = s0Var.C;
        if (bundle != null) {
            l1Var.f1600d.putAll(bundle);
        }
        int i12 = Build.VERSION.SDK_INT;
        l1Var.f1598b.setShowWhen(s0Var.f1659n);
        l1Var.f1598b.setLocalOnly(s0Var.f1670y);
        l1Var.f1598b.setGroup(s0Var.f1668w);
        l1Var.f1598b.setSortKey(s0Var.f1669x);
        l1Var.f1598b.setGroupSummary(false);
        l1Var.f1598b.setCategory(s0Var.B);
        l1Var.f1598b.setColor(s0Var.D);
        l1Var.f1598b.setVisibility(s0Var.E);
        l1Var.f1598b.setPublicVersion(s0Var.F);
        l1Var.f1598b.setSound(notification.sound, notification.audioAttributes);
        ArrayList arrayList4 = s0Var.f1648c;
        List listCombineLists = s0Var.R;
        listCombineLists = i12 < 28 ? combineLists(getPeople(arrayList4), listCombineLists) : listCombineLists;
        if (listCombineLists != null && !listCombineLists.isEmpty()) {
            Iterator it3 = listCombineLists.iterator();
            while (it3.hasNext()) {
                l1Var.f1598b.addPerson((String) it3.next());
            }
        }
        ArrayList arrayList5 = s0Var.f1649d;
        if (arrayList5.size() > 0) {
            if (s0Var.C == null) {
                s0Var.C = new Bundle();
            }
            Bundle bundle2 = s0Var.C.getBundle("android.car.EXTENSIONS");
            bundle2 = bundle2 == null ? new Bundle() : bundle2;
            Bundle bundle3 = new Bundle(bundle2);
            Bundle bundle4 = new Bundle();
            int i13 = 0;
            while (i13 < arrayList5.size()) {
                String string = Integer.toString(i13);
                g0 g0Var = (g0) arrayList5.get(i13);
                Bundle bundle5 = new Bundle();
                IconCompat iconCompat2 = g0Var.getIconCompat();
                bundle5.putInt("icon", iconCompat2 != null ? iconCompat2.d() : i11);
                bundle5.putCharSequence(IjkMediaMeta.IJKM_KEY_TITLE, g0Var.getTitle());
                bundle5.putParcelable("actionIntent", g0Var.getActionIntent());
                Bundle bundle6 = g0Var.f1561a;
                Bundle bundle7 = bundle6 != null ? new Bundle(bundle6) : new Bundle();
                bundle7.putBoolean("android.support.allowGeneratedReplies", g0Var.f1564d);
                bundle5.putBundle("extras", bundle7);
                b2[] remoteInputs = g0Var.getRemoteInputs();
                if (remoteInputs == null) {
                    arrayList2 = arrayList5;
                    arrayList3 = arrayList4;
                    bundleArr = null;
                } else {
                    bundleArr = new Bundle[remoteInputs.length];
                    arrayList2 = arrayList5;
                    int i14 = 0;
                    while (i14 < remoteInputs.length) {
                        b2 b2Var = remoteInputs[i14];
                        b2[] b2VarArr = remoteInputs;
                        Bundle bundle8 = new Bundle();
                        ArrayList arrayList6 = arrayList4;
                        bundle8.putString("resultKey", b2Var.f1526a);
                        bundle8.putCharSequence("label", b2Var.getLabel());
                        bundle8.putCharSequenceArray("choices", b2Var.getChoices());
                        bundle8.putBoolean("allowFreeFormInput", b2Var.f1529d);
                        bundle8.putBundle("extras", b2Var.f1531f);
                        Set<String> allowedDataTypes = b2Var.getAllowedDataTypes();
                        if (allowedDataTypes != null && !allowedDataTypes.isEmpty()) {
                            ArrayList<String> arrayList7 = new ArrayList<>(allowedDataTypes.size());
                            Iterator<String> it4 = allowedDataTypes.iterator();
                            while (it4.hasNext()) {
                                arrayList7.add(it4.next());
                            }
                            bundle8.putStringArrayList("allowedDataTypes", arrayList7);
                        }
                        bundleArr[i14] = bundle8;
                        i14++;
                        remoteInputs = b2VarArr;
                        arrayList4 = arrayList6;
                    }
                    arrayList3 = arrayList4;
                }
                bundle5.putParcelableArray("remoteInputs", bundleArr);
                bundle5.putBoolean("showsUserInterface", g0Var.f1565e);
                bundle5.putInt("semanticAction", g0Var.f1566f);
                bundle4.putBundle(string, bundle5);
                i13++;
                i11 = 0;
                arrayList5 = arrayList2;
                arrayList4 = arrayList3;
            }
            arrayList = arrayList4;
            bundle2.putBundle("invisible_actions", bundle4);
            bundle3.putBundle("invisible_actions", bundle4);
            if (s0Var.C == null) {
                s0Var.C = new Bundle();
            }
            s0Var.C.putBundle("android.car.EXTENSIONS", bundle2);
            l1Var = this;
            l1Var.f1600d.putBundle("android.car.EXTENSIONS", bundle3);
        } else {
            arrayList = arrayList4;
        }
        int i15 = Build.VERSION.SDK_INT;
        l1Var.f1598b.setExtras(s0Var.C);
        l1Var.f1598b.setRemoteInputHistory(s0Var.f1664s);
        RemoteViews remoteViews = s0Var.G;
        if (remoteViews != null) {
            l1Var.f1598b.setCustomContentView(remoteViews);
        }
        RemoteViews remoteViews2 = s0Var.H;
        if (remoteViews2 != null) {
            l1Var.f1598b.setCustomBigContentView(remoteViews2);
        }
        RemoteViews remoteViews3 = s0Var.I;
        if (remoteViews3 != null) {
            l1Var.f1598b.setCustomHeadsUpContentView(remoteViews3);
        }
        if (i15 >= 26) {
            a0.I(l1Var.f1598b, s0Var.K);
            a0.P(l1Var.f1598b, s0Var.f1663r);
            a0.Q(l1Var.f1598b, s0Var.L);
            a0.R(l1Var.f1598b);
            a0.L(l1Var.f1598b);
            if (s0Var.A) {
                a0.J(l1Var.f1598b, s0Var.f1671z);
            }
            if (!TextUtils.isEmpty(s0Var.J)) {
                l1Var.f1598b.setSound(null).setDefaults(0).setLights(0, 0, 0).setVibrate(null);
            }
        }
        if (i15 >= 28) {
            for (z1 z1Var : arrayList) {
                Notification.Builder builder2 = l1Var.f1598b;
                z1Var.getClass();
                m.d.a(builder2, m.d.y(z1Var));
            }
        }
        int i16 = Build.VERSION.SDK_INT;
        if (i16 >= 29) {
            b0.n(l1Var.f1598b, s0Var.O);
            b0.p(l1Var.f1598b, p0.toPlatform(s0Var.P));
            g0.i iVar = s0Var.M;
            if (iVar != null) {
                b0.s(l1Var.f1598b, iVar.f26129b);
            }
        }
        if (i16 < 31 || (i10 = s0Var.N) == 0) {
            return;
        }
        h0.c(l1Var.f1598b, i10);
    }

    @Nullable
    private static List<String> combineLists(@Nullable List<String> list, @Nullable List<String> list2) {
        if (list == null) {
            return list2;
        }
        if (list2 == null) {
            return list;
        }
        androidx.collection.g gVar = new androidx.collection.g(list2.size() + list.size());
        gVar.addAll(list);
        gVar.addAll(list2);
        return new ArrayList(gVar);
    }

    @Nullable
    private static List<String> getPeople(@Nullable List<z1> list) {
        if (list == null) {
            return null;
        }
        ArrayList arrayList = new ArrayList(list.size());
        for (z1 z1Var : list) {
            String str = z1Var.mUri;
            if (str == null) {
                str = z1Var.mName != null ? "name:" + ((Object) z1Var.mName) : "";
            }
            arrayList.add(str);
        }
        return arrayList;
    }

    public final void a(g0 g0Var) {
        Set<String> allowedDataTypes;
        IconCompat iconCompat = g0Var.getIconCompat();
        RemoteInput[] remoteInputArr = null;
        Notification.Action.Builder builder = new Notification.Action.Builder(iconCompat != null ? iconCompat.toIcon(null) : null, g0Var.getTitle(), g0Var.getActionIntent());
        if (g0Var.getRemoteInputs() != null) {
            b2[] remoteInputs = g0Var.getRemoteInputs();
            if (remoteInputs != null) {
                remoteInputArr = new RemoteInput[remoteInputs.length];
                for (int i10 = 0; i10 < remoteInputs.length; i10++) {
                    b2 b2Var = remoteInputs[i10];
                    RemoteInput.Builder builderAddExtras = new RemoteInput.Builder(b2Var.f1526a).setLabel(b2Var.getLabel()).setChoices(b2Var.getChoices()).setAllowFreeFormInput(b2Var.f1529d).addExtras(b2Var.f1531f);
                    if (Build.VERSION.SDK_INT >= 26 && (allowedDataTypes = b2Var.getAllowedDataTypes()) != null) {
                        Iterator<String> it = allowedDataTypes.iterator();
                        while (it.hasNext()) {
                            a0.G(builderAddExtras, it.next());
                        }
                    }
                    if (Build.VERSION.SDK_INT >= 29) {
                        b0.r(builderAddExtras, b2Var.f1530e);
                    }
                    remoteInputArr[i10] = builderAddExtras.build();
                }
            }
            for (RemoteInput remoteInput : remoteInputArr) {
                builder.addRemoteInput(remoteInput);
            }
        }
        Bundle bundle = g0Var.f1561a;
        Bundle bundle2 = bundle != null ? new Bundle(bundle) : new Bundle();
        boolean z10 = g0Var.f1564d;
        bundle2.putBoolean("android.support.allowGeneratedReplies", z10);
        int i11 = Build.VERSION.SDK_INT;
        builder.setAllowGeneratedReplies(z10);
        int i12 = g0Var.f1566f;
        bundle2.putInt("android.support.action.semanticAction", i12);
        if (i11 >= 28) {
            m.d.w(builder, i12);
        }
        if (i11 >= 29) {
            b0.q(builder, g0Var.f1567g);
        }
        if (i11 >= 31) {
            h0.b(builder, g0Var.f1570j);
        }
        bundle2.putBoolean("android.support.action.showsUserInterface", g0Var.f1565e);
        builder.addExtras(bundle2);
        this.f1598b.addAction(builder.build());
    }

    public final Notification b() {
        Bundle extras;
        RemoteViews remoteViewsMakeHeadsUpContentView;
        RemoteViews remoteViewsMakeBigContentView;
        s0 s0Var = this.f1599c;
        j1 j1Var = s0Var.f1661p;
        if (j1Var != null) {
            j1Var.apply(this);
        }
        RemoteViews remoteViewsMakeContentView = j1Var != null ? j1Var.makeContentView(this) : null;
        int i10 = Build.VERSION.SDK_INT;
        Notification.Builder builder = this.f1598b;
        Notification notificationBuild = i10 >= 26 ? builder.build() : builder.build();
        if (remoteViewsMakeContentView != null) {
            notificationBuild.contentView = remoteViewsMakeContentView;
        } else {
            RemoteViews remoteViews = s0Var.G;
            if (remoteViews != null) {
                notificationBuild.contentView = remoteViews;
            }
        }
        if (j1Var != null && (remoteViewsMakeBigContentView = j1Var.makeBigContentView(this)) != null) {
            notificationBuild.bigContentView = remoteViewsMakeBigContentView;
        }
        if (j1Var != null && (remoteViewsMakeHeadsUpContentView = s0Var.f1661p.makeHeadsUpContentView(this)) != null) {
            notificationBuild.headsUpContentView = remoteViewsMakeHeadsUpContentView;
        }
        if (j1Var != null && (extras = k1.getExtras(notificationBuild)) != null) {
            j1Var.addCompatExtras(extras);
        }
        return notificationBuild;
    }
}
