package J0;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.IBinder;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.util.Log;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/* JADX INFO: loaded from: classes.dex */
public class d {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static final Map f1139e;

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

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

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

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

    class a implements Runnable {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ ComponentName f1144b;

        a(ComponentName componentName) {
            this.f1144b = componentName;
        }

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

    private static class b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private static final d f1146a = new d(null);
    }

    private class c implements ServiceConnection {
        private c() {
        }

        @Override // android.content.ServiceConnection
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            String strH = d.h(componentName);
            if (strH != null) {
                d.this.f1142c.put(strH, iBinder);
            }
        }

        @Override // android.content.ServiceConnection
        public void onServiceDisconnected(ComponentName componentName) {
            String strH = d.h(componentName);
            if (strH != null) {
                d.this.f1142c.remove(strH);
                d.this.f(componentName);
            }
        }

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

    static {
        ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();
        f1139e = concurrentHashMap;
        concurrentHashMap.put("opensdk", new ComponentName("com.seewo.mcuservice", "com.seewo.sdk.service.SDKService"));
    }

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

    /* JADX INFO: Access modifiers changed from: private */
    public void e(ComponentName componentName) {
        Intent intent = new Intent();
        intent.setComponent(componentName);
        if (this.f1141b.bindService(intent, this.f1143d, 1)) {
            return;
        }
        Log.e("ServiceManagerCompat", "bindService failed, component name: " + componentName);
        f(componentName);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void f(ComponentName componentName) {
        J0.a.a().postDelayed(new a(componentName), 3000L);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static String h(ComponentName componentName) {
        Map map = f1139e;
        if (!map.containsValue(componentName)) {
            return null;
        }
        for (Map.Entry entry : map.entrySet()) {
            if (componentName.equals(entry.getValue())) {
                return (String) entry.getKey();
            }
        }
        return null;
    }

    public static d i() {
        return b.f1146a;
    }

    private static boolean l(Context context) {
        return Build.VERSION.SDK_INT == 26 && "enforce".equals(SystemProperties.get("ro.boot.selinux")) && !J0.b.a(context, context.getPackageName()) && context.getApplicationInfo().targetSdkVersion >= 26;
    }

    public IBinder g(String str) {
        IBinder iBinder = (IBinder) this.f1142c.get(str);
        return iBinder != null ? iBinder : ServiceManager.getService(str);
    }

    public void j(Context context) {
        boolean zL = l(context);
        this.f1140a = zL;
        if (zL) {
            Log.i("ServiceManagerCompat", "Use ServiceManagerCompat");
            this.f1141b = context;
            Iterator it = f1139e.values().iterator();
            while (it.hasNext()) {
                e((ComponentName) it.next());
            }
        }
    }

    public boolean k() {
        return this.f1140a;
    }

    private d() {
        this.f1142c = new ConcurrentHashMap();
        this.f1143d = new c(this, null);
    }
}
