package com.ss.android.socialbase.downloader.downloader;

import X.7lW;
import X.93n;
import X.C3561QXu;
import X.C3577QYk;
import X.QY1;
import X.QZC;
import X.QZN;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.IBinder;
import com.bytedance.covode.number.Covode;
import com.bytedance.helios.sdk.utils.ServiceLifecycle;

public class SqlDownloadCacheService extends Service {
    public static final String LIZ = SqlDownloadCacheService.class.getSimpleName();

    static {
        Covode.recordClassIndex(49007);
    }

    public void onCreate() {
        super.onCreate();
        Context applicationContext = getApplicationContext();
        if (7lW.LIZJ && applicationContext == null) {
            applicationContext = 7lW.LIZ;
        }
        QY1.LIZ(applicationContext);
    }

    public IBinder onBind(Intent intent) {
        C3577QYk qYk;
        QZN LJIILLIIL = QY1.LJIILLIIL();
        if (LJIILLIIL instanceof QZC) {
            qYk = ((QZC) LJIILLIIL).LIZIZ;
        } else if (LJIILLIIL instanceof C3577QYk) {
            qYk = (C3577QYk) LJIILLIIL;
        } else {
            qYk = null;
        }
        if (qYk instanceof IBinder) {
            return (IBinder) qYk;
        }
        return new Binder();
    }

    public static void LIZ(Context context, ServiceConnection serviceConnection) {
        if (context != null) {
            try {
                Intent intent = new Intent(context, SqlDownloadCacheService.class);
                if (serviceConnection != null) {
                    LIZ(context, intent, serviceConnection);
                }
                LIZ(context, intent);
            } catch (Throwable unused) {
                C3561QXu.LIZ(LIZ);
            }
        }
    }

    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:14:0x003c */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static android.content.ComponentName LIZ(android.content.Context r9, android.content.Intent r10) {
        /*
            boolean r0 = r9 instanceof android.content.Context
            if (r0 == 0) goto L_0x006c
            boolean r0 = X.93n.LIZ(r9, r10)
            r8 = 0
            if (r0 == 0) goto L_0x000c
            return r8
        L_0x000c:
            r7 = 0
            com.bytedance.ies.abmock.SettingsManager r1 = com.bytedance.ies.abmock.SettingsManager.LIZ()     // Catch:{ Exception -> 0x003c }
            java.lang.String r0 = "StartServiceLancet_startService"
            boolean r0 = r1.LIZ(r0, r7)     // Catch:{ Exception -> 0x003c }
            if (r0 == 0) goto L_0x003c
            int r1 = android.os.Build.VERSION.SDK_INT     // Catch:{ Exception -> 0x003c }
            r0 = 26
            if (r1 < r0) goto L_0x003c
            boolean r0 = X.SfZ.LJIIJJI     // Catch:{ Exception -> 0x003c }
            if (r0 == 0) goto L_0x003c
            java.lang.StringBuilder r1 = new java.lang.StringBuilder     // Catch:{ Exception -> 0x003c }
            java.lang.String r0 = "dangerousStartService warning! make sure you are in forground call startService "
            r1.<init>(r0)     // Catch:{ Exception -> 0x003c }
            java.lang.Class r0 = r10.getClass()     // Catch:{ Exception -> 0x003c }
            java.lang.String r0 = r0.getName()     // Catch:{ Exception -> 0x003c }
            r1.append(r0)     // Catch:{ Exception -> 0x003c }
            java.lang.String r0 = r1.toString()     // Catch:{ Exception -> 0x003c }
            X.TSt.LIZ(r0)     // Catch:{ Exception -> 0x003c }
        L_0x003c:
            android.content.ComponentName r8 = r9.startService(r10)     // Catch:{ RuntimeException -> 0x0041 }
            goto L_0x006a
        L_0x0041:
            r6 = move-exception
            java.lang.StackTraceElement[] r5 = r6.getStackTrace()
            int r4 = r5.length
            r3 = 0
        L_0x0048:
            if (r7 >= r4) goto L_0x0068
            r2 = r5[r7]
            java.lang.String r1 = r2.getClassName()
            java.lang.String r0 = "com.ss.android.ugc.aweme.scheduler.PublishService"
            boolean r0 = r1.startsWith(r0)
            if (r0 == 0) goto L_0x0065
            java.lang.String r1 = r2.getMethodName()
            java.lang.String r0 = "show"
            boolean r0 = r0.equals(r1)
            if (r0 == 0) goto L_0x0065
            r3 = 1
        L_0x0065:
            int r7 = r7 + 1
            goto L_0x0048
        L_0x0068:
            if (r3 == 0) goto L_0x006b
        L_0x006a:
            return r8
        L_0x006b:
            throw r6
        L_0x006c:
            android.content.ComponentName r0 = r9.startService(r10)
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.socialbase.downloader.downloader.SqlDownloadCacheService.LIZ(android.content.Context, android.content.Intent):android.content.ComponentName");
    }

    public int onStartCommand(Intent intent, int i, int i2) {
        ServiceLifecycle.onStartCommand(this, intent, i, i2);
        int onStartCommand = super.onStartCommand(intent, i, i2);
        if (QY1.LJ()) {
            return 2;
        }
        return onStartCommand;
    }

    public static boolean LIZ(Context context, Intent intent, ServiceConnection serviceConnection) {
        if (context == null || !(context instanceof Context)) {
            return context.bindService(intent, serviceConnection, 1);
        }
        if (93n.LIZ(context, intent, serviceConnection, 1)) {
            return true;
        }
        return context.bindService(intent, serviceConnection, 1);
    }
}
