package android.support.v4.app;

import android.app.Notification;
import android.app.RemoteInput;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.v;
import android.text.TextUtils;
import android.util.SparseArray;
import android.widget.RemoteViews;
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 w implements u {

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

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final Bundle f650f = new Bundle();
    private int g;
    private RemoteViews h;

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

    private void a(v.a aVar) {
        int i = Build.VERSION.SDK_INT;
        if (i < 20) {
            if (i >= 16) {
                this.f649e.add(x.f(this.f645a, aVar));
                return;
            }
            return;
        }
        Notification.Action.Builder builder = new Notification.Action.Builder(aVar.e(), aVar.i(), aVar.a());
        if (aVar.f() != null) {
            for (RemoteInput remoteInput : z.b(aVar.f())) {
                builder.addRemoteInput(remoteInput);
            }
        }
        Bundle bundle = aVar.d() != null ? new Bundle(aVar.d()) : new Bundle();
        bundle.putBoolean("android.support.allowGeneratedReplies", aVar.b());
        if (Build.VERSION.SDK_INT >= 24) {
            builder.setAllowGeneratedReplies(aVar.b());
        }
        bundle.putInt("android.support.action.semanticAction", aVar.g());
        if (Build.VERSION.SDK_INT >= 28) {
            builder.setSemanticAction(aVar.g());
        }
        bundle.putBoolean("android.support.action.showsUserInterface", aVar.h());
        builder.addExtras(bundle);
        this.f645a.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() {
        Bundle bundleA;
        RemoteViews remoteViewsE;
        RemoteViews remoteViewsC;
        v.c cVar = this.f646b.o;
        if (cVar != null) {
            cVar.b(this);
        }
        RemoteViews remoteViewsD = cVar != null ? cVar.d(this) : null;
        Notification notificationC = c();
        if (remoteViewsD != null) {
            notificationC.contentView = remoteViewsD;
        } else {
            RemoteViews remoteViews = this.f646b.F;
            if (remoteViews != null) {
                notificationC.contentView = remoteViews;
            }
        }
        if (Build.VERSION.SDK_INT >= 16 && cVar != null && (remoteViewsC = cVar.c(this)) != null) {
            notificationC.bigContentView = remoteViewsC;
        }
        if (Build.VERSION.SDK_INT >= 21 && cVar != null && (remoteViewsE = this.f646b.o.e(this)) != null) {
            notificationC.headsUpContentView = remoteViewsE;
        }
        if (Build.VERSION.SDK_INT >= 16 && cVar != null && (bundleA = v.a(notificationC)) != null) {
            cVar.a(bundleA);
        }
        return notificationC;
    }

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