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;

/* JADX INFO: renamed from: ᵾᵩᵮ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C5458 implements InterfaceC5265, InterfaceC4174 {

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public static final /* synthetic */ int f20666 = 0;

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public final HashMap f20667;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final C2935 f20668;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public final C0738 f20669;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final Object f20670 = new Object();

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final C4055 f20671;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public C4272 f20672;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public final LinkedHashMap f20673;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public final HashMap f20674;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public SystemForegroundService f20675;

    static {
        C3814.m8512("SystemFgDispatcher");
    }

    public C5458(Context context) {
        C2935 c2935M6998 = C2935.m6998(context);
        this.f20668 = c2935M6998;
        this.f20671 = c2935M6998.f11294;
        this.f20672 = null;
        this.f20673 = new LinkedHashMap();
        this.f20667 = new HashMap();
        this.f20674 = new HashMap();
        this.f20669 = new C0738(c2935M6998.f11291);
        c2935M6998.f11296.m11203(this);
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static Intent m11078(Context context, C4272 c4272, C2860 c2860) {
        Intent intent = new Intent(context, (Class<?>) SystemForegroundService.class);
        intent.setAction("ACTION_START_FOREGROUND");
        intent.putExtra("KEY_WORKSPEC_ID", c4272.f16323);
        intent.putExtra("KEY_GENERATION", c4272.f16322);
        intent.putExtra("KEY_NOTIFICATION_ID", c2860.f10960);
        intent.putExtra("KEY_FOREGROUND_SERVICE_TYPE", c2860.f10958);
        intent.putExtra("KEY_NOTIFICATION", c2860.f10959);
        return intent;
    }

    @Override // defpackage.InterfaceC4174
    /* JADX INFO: renamed from: ʽˈˋ */
    public final void mo4247(C4272 c4272, boolean z) {
        Map.Entry entry;
        synchronized (this.f20670) {
            try {
                InterfaceC4645 interfaceC4645 = ((C2590) this.f20674.remove(c4272)) != null ? (InterfaceC4645) this.f20667.remove(c4272) : null;
                if (interfaceC4645 != null) {
                    interfaceC4645.mo6096(null);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        C2860 c2860 = (C2860) this.f20673.remove(c4272);
        if (c4272.equals(this.f20672)) {
            if (this.f20673.size() > 0) {
                Iterator it = this.f20673.entrySet().iterator();
                Object next = it.next();
                while (true) {
                    entry = (Map.Entry) next;
                    if (!it.hasNext()) {
                        break;
                    } else {
                        next = it.next();
                    }
                }
                this.f20672 = (C4272) entry.getKey();
                if (this.f20675 != null) {
                    C2860 c28602 = (C2860) entry.getValue();
                    SystemForegroundService systemForegroundService = this.f20675;
                    int i = c28602.f10960;
                    int i2 = c28602.f10958;
                    Notification notification = c28602.f10959;
                    systemForegroundService.getClass();
                    int i3 = Build.VERSION.SDK_INT;
                    if (i3 >= 31) {
                        AbstractC1630.m4501(systemForegroundService, i, notification, i2);
                    } else if (i3 >= 29) {
                        AbstractC1630.m4498(systemForegroundService, i, notification, i2);
                    } else {
                        systemForegroundService.startForeground(i, notification);
                    }
                    this.f20675.ᵨᵼⁱ.cancel(c28602.f10960);
                }
            } else {
                this.f20672 = null;
            }
        }
        SystemForegroundService systemForegroundService2 = this.f20675;
        if (c2860 == null || systemForegroundService2 == null) {
            return;
        }
        C3814 c3814M8515 = C3814.m8515();
        c4272.toString();
        c3814M8515.getClass();
        systemForegroundService2.ᵨᵼⁱ.cancel(c2860.f10960);
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final void m11079() {
        this.f20675 = null;
        synchronized (this.f20670) {
            try {
                Iterator it = this.f20667.values().iterator();
                while (it.hasNext()) {
                    ((InterfaceC4645) it.next()).mo6096(null);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        this.f20668.f11296.m11204(this);
    }

    @Override // defpackage.InterfaceC5265
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final void mo4248(C2590 c2590, AbstractC0223 abstractC0223) {
        if (abstractC0223 instanceof C0963) {
            C3814.m8515().getClass();
            C4272 c4272 = ᵷᵸˁ.ᵝᵶ(c2590);
            int i = ((C0963) abstractC0223).f4239;
            C2935 c2935 = this.f20668;
            c2935.f11294.m8889(new RunnableC4456(c2935.f11296, new C5242(c4272), true, i));
        }
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final void m11080(Intent intent) {
        if (this.f20675 == 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);
        C4272 c4272 = new C4272(intent.getIntExtra("KEY_GENERATION", 0), intent.getStringExtra("KEY_WORKSPEC_ID"));
        Notification notification = (Notification) intent.getParcelableExtra("KEY_NOTIFICATION");
        C3814.m8515().getClass();
        if (notification == null) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("Notification passed in the intent was null.");
            return;
        }
        C2860 c2860 = new C2860(intExtra, notification, intExtra2);
        LinkedHashMap linkedHashMap = this.f20673;
        linkedHashMap.put(c4272, c2860);
        C2860 c28602 = (C2860) linkedHashMap.get(this.f20672);
        if (c28602 == null) {
            this.f20672 = c4272;
        } else {
            this.f20675.ᵨᵼⁱ.notify(intExtra, notification);
            if (Build.VERSION.SDK_INT >= 29) {
                Iterator it = linkedHashMap.entrySet().iterator();
                while (it.hasNext()) {
                    i |= ((C2860) ((Map.Entry) it.next()).getValue()).f10958;
                }
                c2860 = new C2860(c28602.f10960, c28602.f10959, i);
            } else {
                c2860 = c28602;
            }
        }
        SystemForegroundService systemForegroundService = this.f20675;
        int i2 = c2860.f10960;
        int i3 = c2860.f10958;
        Notification notification2 = c2860.f10959;
        systemForegroundService.getClass();
        int i4 = Build.VERSION.SDK_INT;
        if (i4 >= 31) {
            AbstractC1630.m4501(systemForegroundService, i2, notification2, i3);
        } else if (i4 >= 29) {
            AbstractC1630.m4498(systemForegroundService, i2, notification2, i3);
        } else {
            systemForegroundService.startForeground(i2, notification2);
        }
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final void m11081(int i, int i2) {
        C3814.m8515().getClass();
        for (Map.Entry entry : this.f20673.entrySet()) {
            if (((C2860) entry.getValue()).f10958 == i2) {
                C4272 c4272 = (C4272) entry.getKey();
                C2935 c2935 = this.f20668;
                c2935.f11294.m8889(new RunnableC4456(c2935.f11296, new C5242(c4272), true, -128));
            }
        }
        SystemForegroundService systemForegroundService = this.f20675;
        if (systemForegroundService != null) {
            systemForegroundService.ᵜᵪʾ = true;
            C3814.m8515().getClass();
            if (Build.VERSION.SDK_INT >= 26) {
                systemForegroundService.stopForeground(true);
            }
            systemForegroundService.stopSelf(i);
        }
    }
}
