package d.e.g.i.a;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
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 a {
    private Handler a;

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

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

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

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

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

    /* JADX INFO: renamed from: d.e.g.i.a.a$a, reason: collision with other inner class name */
    /* JADX INFO: compiled from: SDKServiceManager.java */
    class ServiceConnectionC0097a implements ServiceConnection {
        ServiceConnectionC0097a() {
        }

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

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

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

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

    /* JADX INFO: compiled from: SDKServiceManager.java */
    private static class c {
        private static final a a = new a(null);
    }

    /* synthetic */ a(ServiceConnectionC0097a serviceConnectionC0097a) {
        this();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void d() {
        if (this.f3559f.bindService(new Intent("com.ifpdos.opensdk.SERVICE_MANAGER").setPackage("com.seewo.mcuservice"), this.f3558e, 1)) {
            return;
        }
        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 a g() {
        return c.a;
    }

    private void i() {
        this.f3558e = new ServiceConnectionC0097a();
        d();
    }

    private boolean k() {
        if (Build.VERSION.SDK_INT >= 28) {
            Context context = this.f3559f;
            if (!m(context, context.getPackageName())) {
                return false;
            }
        }
        return true;
    }

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

    private boolean m(Context context, String str) {
        try {
            return context.getPackageManager().getPackageInfo(str, 16384).applicationInfo.uid < 10000;
        } catch (PackageManager.NameNotFoundException e2) {
            Log.e("SDKServiceManager", "", e2);
            return false;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:6:0x0012  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private boolean n() {
        /*
            r2 = this;
            boolean r0 = d.e.g.p.a.d()
            if (r0 == 0) goto L12
            android.content.Context r0 = r2.f3559f
            java.lang.String r1 = r0.getPackageName()
            boolean r0 = r2.m(r0, r1)
            if (r0 == 0) goto L24
        L12:
            boolean r0 = d.e.g.p.a.d()
            if (r0 == 0) goto L1e
            boolean r0 = r2.l()
            if (r0 != 0) goto L24
        L1e:
            boolean r0 = d.e.g.p.c.a()
            if (r0 != 0) goto L26
        L24:
            r0 = 1
            goto L27
        L26:
            r0 = 0
        L27:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: d.e.g.i.a.a.n():boolean");
    }

    public IBinder f(String str) {
        if (!this.f3556c) {
            return ServiceManager.getService(str);
        }
        try {
            if (this.f3557d != null) {
                return this.f3557d.getService(str);
            }
            return null;
        } catch (RemoteException e2) {
            Log.e("SDKServiceManager", "REMOTE_EXCEPTION", e2);
            return null;
        }
    }

    public void h(Context context) {
        this.f3559f = context;
        this.f3555b = k();
        boolean zN = n();
        this.f3556c = zN;
        if (zN) {
            i();
        }
    }

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

    public void o() {
        if (this.f3556c || d.e.g.p.c.a()) {
            return;
        }
        Log.d("SDKServiceManager", "reconnect to bind opensdk service");
        this.f3556c = true;
        i();
    }

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