package androidx.work.impl.foreground;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import androidx.lifecycle.y;
import androidx.work.impl.foreground.a;
import z5.k;

/* loaded from: classes.dex */
public class SystemForegroundService extends y implements a.b {

    /* renamed from: u, reason: collision with root package name */
    private static final String f5968u = k.f("SystemFgService");

    /* renamed from: v, reason: collision with root package name */
    private static SystemForegroundService f5969v = null;

    /* renamed from: q, reason: collision with root package name */
    private Handler f5970q;

    /* renamed from: r, reason: collision with root package name */
    private boolean f5971r;

    /* renamed from: s, reason: collision with root package name */
    androidx.work.impl.foreground.a f5972s;

    /* renamed from: t, reason: collision with root package name */
    NotificationManager f5973t;

    /* loaded from: classes.dex */
    class a implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ int f5974p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ Notification f5975q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ int f5976r;

        a(int i10, Notification notification, int i11) {
            this.f5974p = i10;
            this.f5975q = notification;
            this.f5976r = i11;
        }

        @Override // java.lang.Runnable
        public void run() {
            SystemForegroundService.this.startForeground(this.f5974p, this.f5975q, this.f5976r);
        }
    }

    /* loaded from: classes.dex */
    class b implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ int f5978p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ Notification f5979q;

        b(int i10, Notification notification) {
            this.f5978p = i10;
            this.f5979q = notification;
        }

        @Override // java.lang.Runnable
        public void run() {
            SystemForegroundService.this.f5973t.notify(this.f5978p, this.f5979q);
        }
    }

    /* loaded from: classes.dex */
    class c implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ int f5981p;

        c(int i10) {
            this.f5981p = i10;
        }

        @Override // java.lang.Runnable
        public void run() {
            SystemForegroundService.this.f5973t.cancel(this.f5981p);
        }
    }

    private void e() {
        this.f5970q = new Handler(Looper.getMainLooper());
        this.f5973t = (NotificationManager) getApplicationContext().getSystemService("notification");
        androidx.work.impl.foreground.a aVar = new androidx.work.impl.foreground.a(getApplicationContext());
        this.f5972s = aVar;
        aVar.l(this);
    }

    @Override // androidx.work.impl.foreground.a.b
    public void b(int i10, int i11, Notification notification) {
        this.f5970q.post(new a(i10, notification, i11));
    }

    @Override // androidx.work.impl.foreground.a.b
    public void c(int i10, Notification notification) {
        this.f5970q.post(new b(i10, notification));
    }

    @Override // androidx.work.impl.foreground.a.b
    public void d(int i10) {
        this.f5970q.post(new c(i10));
    }

    @Override // androidx.lifecycle.y, android.app.Service
    public void onCreate() {
        super.onCreate();
        f5969v = this;
        e();
    }

    @Override // androidx.lifecycle.y, android.app.Service
    public void onDestroy() {
        super.onDestroy();
        this.f5972s.j();
    }

    @Override // androidx.lifecycle.y, android.app.Service
    public int onStartCommand(Intent intent, int i10, int i11) {
        super.onStartCommand(intent, i10, i11);
        if (this.f5971r) {
            k.c().d(f5968u, "Re-initializing SystemForegroundService after a request to shut-down.", new Throwable[0]);
            this.f5972s.j();
            e();
            this.f5971r = false;
        }
        if (intent == null) {
            return 3;
        }
        this.f5972s.k(intent);
        return 3;
    }

    @Override // androidx.work.impl.foreground.a.b
    public void stop() {
        this.f5971r = true;
        k.c().a(f5968u, "All commands completed.", new Throwable[0]);
        stopForeground(true);
        f5969v = null;
        stopSelf();
    }
}
