package defpackage;

import android.app.Notification;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import androidx.work.impl.foreground.SystemForegroundService;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

/* renamed from: ˏᵬˌˋ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1892 implements InterfaceC4074, InterfaceC1924 {

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public static final /* synthetic */ int f7613 = 0;

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public final HashMap f7614;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public SystemForegroundService f7615;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final C4356 f7616;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final HashMap f7617;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final C0030 f7618;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final LinkedHashMap f7619;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final C5205 f7620;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public C3084 f7621;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final Object f7622 = new Object();

    static {
        ᵼᵫᵧˀ.ˁˑᵰ("SystemFgDispatcher");
    }

    public C1892(Context context) {
        C5205 c5205M10761 = C5205.m10761(context);
        this.f7620 = c5205M10761;
        this.f7618 = c5205M10761.f19429;
        this.f7621 = null;
        this.f7619 = new LinkedHashMap();
        this.f7614 = new HashMap();
        this.f7617 = new HashMap();
        this.f7616 = new C4356(c5205M10761.f19427);
        c5205M10761.f19422.m5130(this);
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public static Intent m5304(Context context, C3084 c3084, C1055 c1055) {
        Intent intent = new Intent(context, (Class<?>) SystemForegroundService.class);
        intent.setAction("ACTION_START_FOREGROUND");
        intent.putExtra("KEY_WORKSPEC_ID", c3084.f11772);
        intent.putExtra("KEY_GENERATION", c3084.f11773);
        intent.putExtra("KEY_NOTIFICATION_ID", c1055.f4581);
        intent.putExtra("KEY_FOREGROUND_SERVICE_TYPE", c1055.f4582);
        intent.putExtra("KEY_NOTIFICATION", c1055.f4580);
        return intent;
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final void m5305() {
        this.f7615 = null;
        synchronized (this.f7622) {
            try {
                Iterator it = this.f7614.values().iterator();
                while (it.hasNext()) {
                    ((InterfaceC3506) it.next()).mo2239(null);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        this.f7620.f19422.m5127(this);
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final void m5306(int i, int i2) {
        ᵼᵫᵧˀ.ˀᵗᵝᵭ().getClass();
        for (Map.Entry entry : this.f7619.entrySet()) {
            if (((C1055) entry.getValue()).f4582 == i2) {
                C3084 c3084 = (C3084) entry.getKey();
                C5205 c5205 = this.f7620;
                c5205.f19429.m1023(new RunnableC2769(c5205.f19422, new C4997(c3084), true, -128));
            }
        }
        SystemForegroundService systemForegroundService = this.f7615;
        if (systemForegroundService != null) {
            systemForegroundService.ᵢˇᵭ = true;
            ᵼᵫᵧˀ.ˀᵗᵝᵭ().getClass();
            if (Build.VERSION.SDK_INT >= 26) {
                systemForegroundService.stopForeground(true);
            }
            systemForegroundService.stopSelf(i);
        }
    }

    @Override // defpackage.InterfaceC4074
    /* renamed from: ᵥᵯˎ */
    public final void mo4860(C3887 c3887, AbstractC0074 abstractC0074) {
        if (abstractC0074 instanceof C2336) {
            ᵼᵫᵧˀ.ˀᵗᵝᵭ().getClass();
            C3084 c3084M2168 = AbstractC0494.m2168(c3887);
            int i = ((C2336) abstractC0074).f9158;
            C5205 c5205 = this.f7620;
            c5205.f19429.m1023(new RunnableC2769(c5205.f19422, new C4997(c3084M2168), true, i));
        }
    }

    @Override // defpackage.InterfaceC1924
    /* renamed from: ᵴᵳ */
    public final void mo4861(C3084 c3084, boolean z) {
        Map.Entry entry;
        synchronized (this.f7622) {
            try {
                InterfaceC3506 interfaceC3506 = ((C3887) this.f7617.remove(c3084)) != null ? (InterfaceC3506) this.f7614.remove(c3084) : null;
                if (interfaceC3506 != null) {
                    interfaceC3506.mo2239(null);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        C1055 c1055 = (C1055) this.f7619.remove(c3084);
        if (c3084.equals(this.f7621)) {
            if (this.f7619.size() > 0) {
                Iterator it = this.f7619.entrySet().iterator();
                Object next = it.next();
                while (true) {
                    entry = (Map.Entry) next;
                    if (!it.hasNext()) {
                        break;
                    } else {
                        next = it.next();
                    }
                }
                this.f7621 = (C3084) entry.getKey();
                if (this.f7615 != null) {
                    C1055 c10552 = (C1055) entry.getValue();
                    SystemForegroundService systemForegroundService = this.f7615;
                    int i = c10552.f4581;
                    int i2 = c10552.f4582;
                    Notification notification = c10552.f4580;
                    systemForegroundService.getClass();
                    int i3 = Build.VERSION.SDK_INT;
                    if (i3 >= 31) {
                        AbstractC5363.m10990(systemForegroundService, i, notification, i2);
                    } else if (i3 >= 29) {
                        AbstractC5363.m10999(systemForegroundService, i, notification, i2);
                    } else {
                        systemForegroundService.startForeground(i, notification);
                    }
                    this.f7615.ᵾᵬ.cancel(c10552.f4581);
                }
            } else {
                this.f7621 = null;
            }
        }
        SystemForegroundService systemForegroundService2 = this.f7615;
        if (c1055 == null || systemForegroundService2 == null) {
            return;
        }
        ᵼᵫᵧˀ r0 = ᵼᵫᵧˀ.ˀᵗᵝᵭ();
        c3084.toString();
        r0.getClass();
        systemForegroundService2.ᵾᵬ.cancel(c1055.f4581);
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final void m5307(Intent intent) {
        if (this.f7615 == null) {
            ᵹˉᵞ.ᵳٴᵶ("handleNotify was called on the destroyed dispatcher");
            return;
        }
        int i = 0;
        int intExtra = intent.getIntExtra("KEY_NOTIFICATION_ID", 0);
        int intExtra2 = intent.getIntExtra("KEY_FOREGROUND_SERVICE_TYPE", 0);
        C3084 c3084 = new C3084(intent.getIntExtra("KEY_GENERATION", 0), intent.getStringExtra("KEY_WORKSPEC_ID"));
        Notification notification = (Notification) intent.getParcelableExtra("KEY_NOTIFICATION");
        ᵼᵫᵧˀ.ˀᵗᵝᵭ().getClass();
        if (notification == null) {
            ᵹˉᵞ.ˌᵜᵹᵩ("Notification passed in the intent was null.");
            return;
        }
        C1055 c1055 = new C1055(intExtra, notification, intExtra2);
        LinkedHashMap linkedHashMap = this.f7619;
        linkedHashMap.put(c3084, c1055);
        C1055 c10552 = (C1055) linkedHashMap.get(this.f7621);
        if (c10552 == null) {
            this.f7621 = c3084;
        } else {
            this.f7615.ᵾᵬ.notify(intExtra, notification);
            if (Build.VERSION.SDK_INT >= 29) {
                Iterator it = linkedHashMap.entrySet().iterator();
                while (it.hasNext()) {
                    i |= ((C1055) ((Map.Entry) it.next()).getValue()).f4582;
                }
                c1055 = new C1055(c10552.f4581, c10552.f4580, i);
            } else {
                c1055 = c10552;
            }
        }
        SystemForegroundService systemForegroundService = this.f7615;
        int i2 = c1055.f4581;
        int i3 = c1055.f4582;
        Notification notification2 = c1055.f4580;
        systemForegroundService.getClass();
        int i4 = Build.VERSION.SDK_INT;
        if (i4 >= 31) {
            AbstractC5363.m10990(systemForegroundService, i2, notification2, i3);
        } else if (i4 >= 29) {
            AbstractC5363.m10999(systemForegroundService, i2, notification2, i3);
        } else {
            systemForegroundService.startForeground(i2, notification2);
        }
    }
}
