package androidx.work.impl.foreground;

import android.app.NotificationManager;
import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import androidx.lifecycle.LifecycleService;
import java.util.Objects;
import java.util.UUID;
import o.C0669Zu;
import o.C1493ic0;
import o.C1879mg;
import o.C2651um0;
import o.RunnableC0890cD;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public class SystemForegroundService extends LifecycleService {
    public static final /* synthetic */ int q = 0;
    public Handler m;
    public boolean n;

    /* renamed from: o, reason: collision with root package name */
    public C1493ic0 f23o;
    public NotificationManager p;

    static {
        C0669Zu.l("SystemFgService");
    }

    public final void a() {
        this.m = new Handler(Looper.getMainLooper());
        this.p = (NotificationManager) getApplicationContext().getSystemService("notification");
        C1493ic0 c1493ic0 = new C1493ic0(getApplicationContext());
        this.f23o = c1493ic0;
        if (c1493ic0.t != null) {
            C0669Zu.e().getClass();
        } else {
            c1493ic0.t = this;
        }
    }

    @Override // androidx.lifecycle.LifecycleService, android.app.Service
    public final void onCreate() {
        super.onCreate();
        a();
    }

    @Override // androidx.lifecycle.LifecycleService, android.app.Service
    public final void onDestroy() {
        super.onDestroy();
        this.f23o.f();
    }

    @Override // android.app.Service
    public final int onStartCommand(Intent intent, int i, int i2) {
        super.onStartCommand(intent, i, i2);
        if (this.n) {
            C0669Zu.e().getClass();
            this.f23o.f();
            a();
            this.n = false;
        }
        if (intent == null) {
            return 3;
        }
        C1493ic0 c1493ic0 = this.f23o;
        c1493ic0.getClass();
        String action = intent.getAction();
        if ("ACTION_START_FOREGROUND".equals(action)) {
            C0669Zu c0669ZuE = C0669Zu.e();
            Objects.toString(intent);
            c0669ZuE.getClass();
            c1493ic0.m.c(new RunnableC0890cD(17, c1493ic0, intent.getStringExtra("KEY_WORKSPEC_ID"), false));
            c1493ic0.e(intent);
            return 3;
        }
        if ("ACTION_NOTIFY".equals(action)) {
            c1493ic0.e(intent);
            return 3;
        }
        if (!"ACTION_CANCEL_WORK".equals(action)) {
            if (!"ACTION_STOP_FOREGROUND".equals(action)) {
                return 3;
            }
            C0669Zu.e().getClass();
            SystemForegroundService systemForegroundService = c1493ic0.t;
            if (systemForegroundService == null) {
                return 3;
            }
            systemForegroundService.n = true;
            C0669Zu.e().getClass();
            if (Build.VERSION.SDK_INT >= 26) {
                systemForegroundService.stopForeground(true);
            }
            systemForegroundService.stopSelf();
            return 3;
        }
        C0669Zu c0669ZuE2 = C0669Zu.e();
        Objects.toString(intent);
        c0669ZuE2.getClass();
        String stringExtra = intent.getStringExtra("KEY_WORKSPEC_ID");
        if (stringExtra == null || TextUtils.isEmpty(stringExtra)) {
            return 3;
        }
        C2651um0 c2651um0 = c1493ic0.l;
        UUID uuidFromString = UUID.fromString(stringExtra);
        c2651um0.getClass();
        c2651um0.n.c(new C1879mg(c2651um0, uuidFromString));
        return 3;
    }
}
