package androidx.core.app;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresPermission;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static String f1640d;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static p1 f1643g;

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final Object f1639c = new Object();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static HashSet f1641e = new HashSet();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final Object f1642f = new Object();

    public r1(Context context) {
        this.f1644a = context;
        this.f1645b = (NotificationManager) context.getSystemService("notification");
    }

    public void cancel(@Nullable String str, int i10) {
        this.f1645b.cancel(str, i10);
    }

    @Nullable
    public NotificationChannel getNotificationChannel(@NonNull String str) {
        if (Build.VERSION.SDK_INT >= 26) {
            return a0.w(this.f1645b, str);
        }
        return null;
    }

    @Nullable
    public d0 getNotificationChannelCompat(@NonNull String str) {
        NotificationChannel notificationChannel;
        if (Build.VERSION.SDK_INT < 26 || (notificationChannel = getNotificationChannel(str)) == null) {
            return null;
        }
        return new d0(notificationChannel);
    }

    @Nullable
    public NotificationChannelGroup getNotificationChannelGroup(@NonNull String str) {
        int i10 = Build.VERSION.SDK_INT;
        NotificationManager notificationManager = this.f1645b;
        if (i10 >= 28) {
            return m.d.i(notificationManager, str);
        }
        if (i10 >= 26) {
            Iterator it = (i10 >= 26 ? a0.x(notificationManager) : Collections.emptyList()).iterator();
            while (it.hasNext()) {
                NotificationChannelGroup notificationChannelGroupG = a4.g.g(it.next());
                if (a0.q(notificationChannelGroupG).equals(str)) {
                    return notificationChannelGroupG;
                }
            }
        }
        return null;
    }

    @Nullable
    public e0 getNotificationChannelGroupCompat(@NonNull String str) {
        NotificationChannelGroup notificationChannelGroup;
        int i10 = Build.VERSION.SDK_INT;
        if (i10 >= 28) {
            NotificationChannelGroup notificationChannelGroup2 = getNotificationChannelGroup(str);
            if (notificationChannelGroup2 != null) {
                return new e0(notificationChannelGroup2, Collections.emptyList());
            }
            return null;
        }
        if (i10 < 26 || (notificationChannelGroup = getNotificationChannelGroup(str)) == null) {
            return null;
        }
        return new e0(notificationChannelGroup, i10 >= 26 ? a0.y(this.f1645b) : Collections.emptyList());
    }

    @RequiresPermission("android.permission.POST_NOTIFICATIONS")
    public void notify(@Nullable String str, int i10, @NonNull Notification notification) {
        Bundle extras = k1.getExtras(notification);
        NotificationManager notificationManager = this.f1645b;
        if (extras == null || !extras.getBoolean("android.support.useSideChannel")) {
            notificationManager.notify(str, i10, notification);
            return;
        }
        m1 m1Var = new m1(this.f1644a.getPackageName(), i10, notification, str);
        synchronized (f1642f) {
            try {
                if (f1643g == null) {
                    f1643g = new p1(this.f1644a.getApplicationContext());
                }
                f1643g.f1628b.obtainMessage(0, m1Var).sendToTarget();
            } catch (Throwable th) {
                throw th;
            }
        }
        notificationManager.cancel(str, i10);
    }

    @Nullable
    public NotificationChannel getNotificationChannel(@NonNull String str, @NonNull String str2) {
        return Build.VERSION.SDK_INT >= 30 ? c0.h(this.f1645b, str, str2) : getNotificationChannel(str);
    }

    @Nullable
    public d0 getNotificationChannelCompat(@NonNull String str, @NonNull String str2) {
        NotificationChannel notificationChannel;
        if (Build.VERSION.SDK_INT < 26 || (notificationChannel = getNotificationChannel(str, str2)) == null) {
            return null;
        }
        return new d0(notificationChannel);
    }
}
