package e.c.d.r.b;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import com.seewo.sdk.internal.model.ISDKServiceManager;

/* JADX INFO: compiled from: SDKServiceManager.java */
/* JADX INFO: loaded from: classes.dex */
public class c {
    private Handler a;
    private boolean b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private boolean f788c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private ISDKServiceManager f789d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private ServiceConnection f790e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private Context f791f;

    /* JADX INFO: compiled from: SDKServiceManager.java */
    class a implements ServiceConnection {
        a() {
        }

        @Override // android.content.ServiceConnection
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            c.this.f789d = ISDKServiceManager.Stub.asInterface(iBinder);
        }

        @Override // android.content.ServiceConnection
        public void onServiceDisconnected(ComponentName componentName) {
            c.this.f789d = null;
            c.this.e();
        }
    }

    /* JADX INFO: compiled from: SDKServiceManager.java */
    class b implements Runnable {
        b() {
        }

        @Override // java.lang.Runnable
        public void run() {
            c.this.d();
        }
    }

    /* JADX INFO: renamed from: e.c.d.r.b.c$c, reason: collision with other inner class name */
    /* JADX INFO: compiled from: SDKServiceManager.java */
    private static class C0034c {
        private static final c a = new c(null);
    }

    /* synthetic */ c(a aVar) {
        this();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void d() {
        Intent intent = new Intent("com.ifpdos.opensdk.SERVICE_MANAGER").setPackage("com.seewo.mcuservice");
        if (this.f791f.bindService(intent, this.f790e, 1)) {
            o(intent);
        } else {
            Log.e("SDKServiceManager", "SDKServiceManager connecting fail!");
            e();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void e() {
        this.a.postDelayed(new b(), 3000L);
    }

    public static c g() {
        return C0034c.a;
    }

    private void i() {
        this.f790e = new a();
        d();
    }

    private boolean k() {
        if (Build.VERSION.SDK_INT >= 28) {
            Context context = this.f791f;
            if (!e.c.d.r.b.b.a(context, context.getPackageName())) {
                return false;
            }
        }
        return true;
    }

    private boolean l() {
        return Build.VERSION.SDK_INT == 30;
    }

    /* JADX WARN: Removed duplicated region for block: B:8:0x0019  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private boolean m() {
        /*
            r3 = this;
            boolean r0 = e.c.d.y.a.d()
            r1 = 0
            if (r0 == 0) goto L19
            boolean r0 = r3.l()
            if (r0 != 0) goto L19
            android.content.Context r0 = r3.f791f
            java.lang.String r2 = r0.getPackageName()
            boolean r0 = e.c.d.r.b.b.a(r0, r2)
            if (r0 == 0) goto L31
        L19:
            boolean r0 = e.c.d.y.a.d()
            if (r0 == 0) goto L2b
            boolean r0 = r3.l()
            if (r0 == 0) goto L2b
            boolean r0 = e.c.d.y.d.d(r1)
            if (r0 == 0) goto L31
        L2b:
            boolean r0 = e.c.d.y.d.c()
            if (r0 != 0) goto L32
        L31:
            r1 = 1
        L32:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: e.c.d.r.b.c.m():boolean");
    }

    private void o(Intent intent) {
        try {
            IBinder iBinder = (IBinder) com.seewo.hiddenapi.d.a.a(com.seewo.hiddenapi.d.a.b(ActivityManager.class, "getService", new Object[0]), "peekService", intent, intent.resolveTypeIfNeeded(this.f791f.getContentResolver()), (String) com.seewo.hiddenapi.d.a.a(this.f791f, "getOpPackageName", new Object[0]));
            if (iBinder != null) {
                Log.i("SDKServiceManager", "peekService: " + iBinder);
                this.f789d = ISDKServiceManager.Stub.asInterface(iBinder);
            }
        } catch (Exception e2) {
            Log.e("SDKServiceManager", e2.getMessage());
        }
    }

    public IBinder f(String str) {
        if (!this.f788c) {
            return d.i().k() ? d.i().g(str) : ServiceManager.getService(str);
        }
        try {
            if (this.f789d != null) {
                return this.f789d.getService(str);
            }
            return null;
        } catch (RemoteException e2) {
            Log.e("SDKServiceManager", "REMOTE_EXCEPTION", e2);
            return null;
        }
    }

    public void h(Context context) {
        this.f791f = context;
        this.b = k();
        boolean zM = m();
        this.f788c = zM;
        if (zM) {
            i();
        }
        d.i().j(context);
    }

    public boolean j() {
        return this.b;
    }

    public void n() {
        if (this.f788c || e.c.d.y.d.c()) {
            return;
        }
        Log.d("SDKServiceManager", "reconnect to bind opensdk service");
        this.f788c = true;
        i();
    }

    private c() {
        this.a = new Handler(Looper.getMainLooper());
    }
}
