package e.c.d.r.b;

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: compiled from: ServiceManagerCompat.java */
/* JADX INFO: loaded from: classes.dex */
public class d {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static final Map<String, ComponentName> f792e;
    private boolean a;
    private Context b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private Map<String, IBinder> f793c;

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

    /* JADX INFO: compiled from: ServiceManagerCompat.java */
    class a implements Runnable {
        final /* synthetic */ ComponentName b;

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

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

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

    /* JADX INFO: compiled from: ServiceManagerCompat.java */
    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.f793c.put(strH, iBinder);
            }
        }

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

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

    static {
        ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();
        f792e = 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.b.bindService(intent, this.f794d, 1)) {
            return;
        }
        Log.e("ServiceManagerCompat", "bindService failed, component name: " + componentName);
        f(componentName);
    }

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

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

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

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

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

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

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

    private d() {
        this.f793c = new ConcurrentHashMap();
        this.f794d = new c(this, null);
    }
}
