package androidx.core.app;

import android.app.Notification;
import android.app.RemoteInput;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.SparseArray;
import android.widget.RemoteViews;
import androidx.core.app.b;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: compiled from: NotificationCompatBuilder.java */
/* JADX INFO: loaded from: classes.dex */
class c {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final Notification.Builder f731a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final b.C0025b f732b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private RemoteViews f733c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private RemoteViews f734d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final List<Bundle> f735e = new ArrayList();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final Bundle f736f = new Bundle();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private int f737g;
    private RemoteViews h;

    c(b.C0025b c0025b) {
        ArrayList<String> arrayList;
        this.f732b = c0025b;
        int i = Build.VERSION.SDK_INT;
        if (i >= 26) {
            this.f731a = new Notification.Builder(c0025b.f724a, c0025b.I);
        } else {
            this.f731a = new Notification.Builder(c0025b.f724a);
        }
        Notification notification = c0025b.N;
        this.f731a.setWhen(notification.when).setSmallIcon(notification.icon, notification.iconLevel).setContent(notification.contentView).setTicker(notification.tickerText, c0025b.h).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(c0025b.f727d).setContentText(c0025b.f728e).setContentInfo(c0025b.j).setContentIntent(c0025b.f729f).setDeleteIntent(notification.deleteIntent).setFullScreenIntent(c0025b.f730g, (notification.flags & 128) != 0).setLargeIcon(c0025b.i).setNumber(c0025b.k).setProgress(c0025b.r, c0025b.s, c0025b.t);
        if (i < 21) {
            this.f731a.setSound(notification.sound, notification.audioStreamType);
        }
        if (i >= 16) {
            this.f731a.setSubText(c0025b.p).setUsesChronometer(c0025b.n).setPriority(c0025b.l);
            Iterator<b.a> it = c0025b.f725b.iterator();
            while (it.hasNext()) {
                a(it.next());
            }
            Bundle bundle = c0025b.B;
            if (bundle != null) {
                this.f736f.putAll(bundle);
            }
            if (Build.VERSION.SDK_INT < 20) {
                if (c0025b.x) {
                    this.f736f.putBoolean("android.support.localOnly", true);
                }
                String str = c0025b.u;
                if (str != null) {
                    this.f736f.putString("android.support.groupKey", str);
                    if (c0025b.v) {
                        this.f736f.putBoolean("android.support.isGroupSummary", true);
                    } else {
                        this.f736f.putBoolean("android.support.useSideChannel", true);
                    }
                }
                String str2 = c0025b.w;
                if (str2 != null) {
                    this.f736f.putString("android.support.sortKey", str2);
                }
            }
            this.f733c = c0025b.F;
            this.f734d = c0025b.G;
        }
        int i2 = Build.VERSION.SDK_INT;
        if (i2 >= 19) {
            this.f731a.setShowWhen(c0025b.m);
            if (i2 < 21 && (arrayList = c0025b.O) != null && !arrayList.isEmpty()) {
                Bundle bundle2 = this.f736f;
                ArrayList<String> arrayList2 = c0025b.O;
                bundle2.putStringArray("android.people", (String[]) arrayList2.toArray(new String[arrayList2.size()]));
            }
        }
        if (i2 >= 20) {
            this.f731a.setLocalOnly(c0025b.x).setGroup(c0025b.u).setGroupSummary(c0025b.v).setSortKey(c0025b.w);
            this.f737g = c0025b.M;
        }
        if (i2 >= 21) {
            this.f731a.setCategory(c0025b.A).setColor(c0025b.C).setVisibility(c0025b.D).setPublicVersion(c0025b.E).setSound(notification.sound, notification.audioAttributes);
            Iterator<String> it2 = c0025b.O.iterator();
            while (it2.hasNext()) {
                this.f731a.addPerson(it2.next());
            }
            this.h = c0025b.H;
            if (c0025b.f726c.size() > 0) {
                Bundle bundle3 = c0025b.b().getBundle("android.car.EXTENSIONS");
                bundle3 = bundle3 == null ? new Bundle() : bundle3;
                Bundle bundle4 = new Bundle();
                for (int i3 = 0; i3 < c0025b.f726c.size(); i3++) {
                    bundle4.putBundle(Integer.toString(i3), d.b(c0025b.f726c.get(i3)));
                }
                bundle3.putBundle("invisible_actions", bundle4);
                c0025b.b().putBundle("android.car.EXTENSIONS", bundle3);
                this.f736f.putBundle("android.car.EXTENSIONS", bundle3);
            }
        }
        int i4 = Build.VERSION.SDK_INT;
        if (i4 >= 24) {
            this.f731a.setExtras(c0025b.B).setRemoteInputHistory(c0025b.q);
            RemoteViews remoteViews = c0025b.F;
            if (remoteViews != null) {
                this.f731a.setCustomContentView(remoteViews);
            }
            RemoteViews remoteViews2 = c0025b.G;
            if (remoteViews2 != null) {
                this.f731a.setCustomBigContentView(remoteViews2);
            }
            RemoteViews remoteViews3 = c0025b.H;
            if (remoteViews3 != null) {
                this.f731a.setCustomHeadsUpContentView(remoteViews3);
            }
        }
        if (i4 >= 26) {
            this.f731a.setBadgeIconType(c0025b.J).setShortcutId(c0025b.K).setTimeoutAfter(c0025b.L).setGroupAlertBehavior(c0025b.M);
            if (c0025b.z) {
                this.f731a.setColorized(c0025b.y);
            }
            if (TextUtils.isEmpty(c0025b.I)) {
                return;
            }
            this.f731a.setSound(null).setDefaults(0).setLights(0, 0, 0).setVibrate(null);
        }
    }

    private void a(b.a aVar) {
        int i = Build.VERSION.SDK_INT;
        if (i < 20) {
            if (i >= 16) {
                this.f735e.add(d.f(this.f731a, aVar));
                return;
            }
            return;
        }
        Notification.Action.Builder builder = new Notification.Action.Builder(aVar.e(), aVar.i(), aVar.a());
        if (aVar.f() != null) {
            for (RemoteInput remoteInput : e.b(aVar.f())) {
                builder.addRemoteInput(remoteInput);
            }
        }
        Bundle bundle = aVar.d() != null ? new Bundle(aVar.d()) : new Bundle();
        bundle.putBoolean("android.support.allowGeneratedReplies", aVar.b());
        int i2 = Build.VERSION.SDK_INT;
        if (i2 >= 24) {
            builder.setAllowGeneratedReplies(aVar.b());
        }
        bundle.putInt("android.support.action.semanticAction", aVar.g());
        if (i2 >= 28) {
            builder.setSemanticAction(aVar.g());
        }
        bundle.putBoolean("android.support.action.showsUserInterface", aVar.h());
        builder.addExtras(bundle);
        this.f731a.addAction(builder.build());
    }

    private void d(Notification notification) {
        notification.sound = null;
        notification.vibrate = null;
        int i = notification.defaults & (-2);
        notification.defaults = i;
        notification.defaults = i & (-3);
    }

    public Notification b() {
        b.c cVar = this.f732b.o;
        if (cVar != null || cVar != null) {
            throw null;
        }
        Notification notificationC = c();
        b.C0025b c0025b = this.f732b;
        RemoteViews remoteViews = c0025b.F;
        if (remoteViews != null) {
            notificationC.contentView = remoteViews;
        }
        int i = Build.VERSION.SDK_INT;
        if (i >= 16 && cVar != null) {
            throw null;
        }
        if (i >= 21 && cVar != null) {
            b.c cVar2 = c0025b.o;
            throw null;
        }
        if (i < 16 || cVar == null || b.a(notificationC) == null) {
            return notificationC;
        }
        throw null;
    }

    protected Notification c() {
        int i = Build.VERSION.SDK_INT;
        if (i >= 26) {
            return this.f731a.build();
        }
        if (i >= 24) {
            Notification notificationBuild = this.f731a.build();
            if (this.f737g != 0) {
                if (notificationBuild.getGroup() != null && (notificationBuild.flags & 512) != 0 && this.f737g == 2) {
                    d(notificationBuild);
                }
                if (notificationBuild.getGroup() != null && (notificationBuild.flags & 512) == 0 && this.f737g == 1) {
                    d(notificationBuild);
                }
            }
            return notificationBuild;
        }
        if (i >= 21) {
            this.f731a.setExtras(this.f736f);
            Notification notificationBuild2 = this.f731a.build();
            RemoteViews remoteViews = this.f733c;
            if (remoteViews != null) {
                notificationBuild2.contentView = remoteViews;
            }
            RemoteViews remoteViews2 = this.f734d;
            if (remoteViews2 != null) {
                notificationBuild2.bigContentView = remoteViews2;
            }
            RemoteViews remoteViews3 = this.h;
            if (remoteViews3 != null) {
                notificationBuild2.headsUpContentView = remoteViews3;
            }
            if (this.f737g != 0) {
                if (notificationBuild2.getGroup() != null && (notificationBuild2.flags & 512) != 0 && this.f737g == 2) {
                    d(notificationBuild2);
                }
                if (notificationBuild2.getGroup() != null && (notificationBuild2.flags & 512) == 0 && this.f737g == 1) {
                    d(notificationBuild2);
                }
            }
            return notificationBuild2;
        }
        if (i >= 20) {
            this.f731a.setExtras(this.f736f);
            Notification notificationBuild3 = this.f731a.build();
            RemoteViews remoteViews4 = this.f733c;
            if (remoteViews4 != null) {
                notificationBuild3.contentView = remoteViews4;
            }
            RemoteViews remoteViews5 = this.f734d;
            if (remoteViews5 != null) {
                notificationBuild3.bigContentView = remoteViews5;
            }
            if (this.f737g != 0) {
                if (notificationBuild3.getGroup() != null && (notificationBuild3.flags & 512) != 0 && this.f737g == 2) {
                    d(notificationBuild3);
                }
                if (notificationBuild3.getGroup() != null && (notificationBuild3.flags & 512) == 0 && this.f737g == 1) {
                    d(notificationBuild3);
                }
            }
            return notificationBuild3;
        }
        if (i >= 19) {
            SparseArray<Bundle> sparseArrayA = d.a(this.f735e);
            if (sparseArrayA != null) {
                this.f736f.putSparseParcelableArray("android.support.actionExtras", sparseArrayA);
            }
            this.f731a.setExtras(this.f736f);
            Notification notificationBuild4 = this.f731a.build();
            RemoteViews remoteViews6 = this.f733c;
            if (remoteViews6 != null) {
                notificationBuild4.contentView = remoteViews6;
            }
            RemoteViews remoteViews7 = this.f734d;
            if (remoteViews7 != null) {
                notificationBuild4.bigContentView = remoteViews7;
            }
            return notificationBuild4;
        }
        if (i < 16) {
            return this.f731a.getNotification();
        }
        Notification notificationBuild5 = this.f731a.build();
        Bundle bundleA = b.a(notificationBuild5);
        Bundle bundle = new Bundle(this.f736f);
        for (String str : this.f736f.keySet()) {
            if (bundleA.containsKey(str)) {
                bundle.remove(str);
            }
        }
        bundleA.putAll(bundle);
        SparseArray<Bundle> sparseArrayA2 = d.a(this.f735e);
        if (sparseArrayA2 != null) {
            b.a(notificationBuild5).putSparseParcelableArray("android.support.actionExtras", sparseArrayA2);
        }
        RemoteViews remoteViews8 = this.f733c;
        if (remoteViews8 != null) {
            notificationBuild5.contentView = remoteViews8;
        }
        RemoteViews remoteViews9 = this.f734d;
        if (remoteViews9 != null) {
            notificationBuild5.bigContentView = remoteViews9;
        }
        return notificationBuild5;
    }
}
