package com.google.android.play.core.assetpacks;

import X.2FV;
import X.2He;
import X.AnonymousClass7lW;
import X.C08347s1;
import X.C28338jA;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.helios.sdk.utils.ServiceLifecycle;
import com.google.android.play.core.b.b;
import java.lang.reflect.Field;

public class AssetPackExtractionService extends Service {
    public Context LIZ;
    public cx LIZIZ;
    public ac LIZJ;
    public final b LIZLLL = new b("AssetPackExtractionService");
    public aa LJ;
    public NotificationManager LJFF;

    static {
        Covode.recordClassIndex(44102);
    }

    private final synchronized void LIZIZ(Bundle bundle) {
        MethodCollector.i(18246);
        String string = bundle.getString("notification_title");
        String string2 = bundle.getString("notification_subtext");
        long j = bundle.getLong("notification_timeout");
        PendingIntent pendingIntent = (PendingIntent) bundle.getParcelable("notification_on_click_intent");
        Notification.Builder timeoutAfter = Build.VERSION.SDK_INT >= 26 ? new Notification.Builder(this.LIZ, "playcore-assetpacks-service-notification-channel").setTimeoutAfter(j) : new Notification.Builder(this.LIZ).setPriority(-2);
        if (pendingIntent != null) {
            timeoutAfter.setContentIntent(pendingIntent);
        }
        timeoutAfter.setSmallIcon(17301633).setOngoing(false).setContentTitle(string).setSubText(string2);
        timeoutAfter.setColor(bundle.getInt("notification_color")).setVisibility(-1);
        Notification build = timeoutAfter.build();
        this.LIZLLL.LIZJ("Starting foreground service.", new Object[0]);
        this.LIZIZ.LIZ(true);
        if (Build.VERSION.SDK_INT >= 26) {
            this.LJFF.createNotificationChannel(new NotificationChannel("playcore-assetpacks-service-notification-channel", bundle.getString("notification_channel_name"), 2));
        }
        startForeground(-1883842196, build);
        MethodCollector.o(18246);
    }

    public final synchronized Bundle LIZ(Bundle bundle) {
        Bundle bundle2;
        MethodCollector.i(18175);
        int i = bundle.getInt("action_type");
        b bVar = this.LIZLLL;
        Integer valueOf = Integer.valueOf(i);
        bVar.LIZ("updateServiceState: %d", valueOf);
        if (i == 1) {
            LIZIZ(bundle);
        } else if (i == 2) {
            LIZ();
        } else {
            this.LIZLLL.LIZIZ("Unknown action type received: %d", valueOf);
        }
        bundle2 = new Bundle();
        MethodCollector.o(18175);
        return bundle2;
    }

    public final synchronized void LIZ() {
        MethodCollector.i(18247);
        this.LIZLLL.LIZJ("Stopping service.", new Object[0]);
        this.LIZIZ.LIZ(false);
        stopForeground(true);
        stopSelf();
        MethodCollector.o(18247);
    }

    public final IBinder onBind(Intent intent) {
        return this.LJ;
    }

    public int onStartCommand(Intent intent, int i, int i2) {
        ServiceLifecycle.onStartCommand(this, intent, i, i2);
        return super.onStartCommand(intent, i, i2);
    }

    public static Object LIZ(Context context, String str) {
        Object obj;
        MethodCollector.i(18086);
        if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) {
            if (!2FV.LIZIZ && "connectivity".equals(str)) {
                try {
                    new C08347s1().LIZ();
                    2FV.LIZIZ = true;
                    obj = context.getSystemService(str);
                } catch (Throwable unused) {
                }
            }
            obj = context.getSystemService(str);
        } else if (2FV.LIZ) {
            synchronized (ClipboardManager.class) {
                try {
                    obj = context.getSystemService(str);
                    if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
                        Field declaredField = ClipboardManager.class.getDeclaredField("mHandler");
                        declaredField.setAccessible(true);
                        declaredField.set(obj, new 2He((Handler) declaredField.get(obj)));
                    }
                } catch (Exception e) {
                    C28338jA.LIZ(e, "ClipboardManager Handler Reflect Fail");
                } catch (Throwable th) {
                    MethodCollector.o(18086);
                    throw th;
                }
                2FV.LIZ = false;
            }
        } else {
            obj = context.getSystemService(str);
        }
        MethodCollector.o(18086);
        return obj;
    }

    public final void onCreate() {
        super.onCreate();
        this.LIZLLL.LIZ("onCreate", new Object[0]);
        Context applicationContext = getApplicationContext();
        if (AnonymousClass7lW.LIZJ && applicationContext == null) {
            applicationContext = AnonymousClass7lW.LIZ;
        }
        bw.LIZ(applicationContext).LIZ(this);
        this.LJ = new aa(this.LIZ, this, this.LIZJ);
        this.LJFF = (NotificationManager) LIZ(this.LIZ, "notification");
    }
}
