package w6;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.google.android.datatransport.runtime.backends.TransportBackendDiscovery;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/* JADX INFO: loaded from: classes2.dex */
public final class l {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f34218a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Map f34219b = null;

    public l(Context context) {
        this.f34218a = context;
    }

    @Nullable
    public e get(String str) {
        Map mapEmptyMap;
        PackageManager packageManager;
        ServiceInfo serviceInfo;
        if (this.f34219b == null) {
            Context context = this.f34218a;
            try {
                packageManager = context.getPackageManager();
            } catch (PackageManager.NameNotFoundException unused) {
            }
            Bundle bundle = (packageManager == null || (serviceInfo = packageManager.getServiceInfo(new ComponentName(context, (Class<?>) TransportBackendDiscovery.class), 128)) == null) ? null : serviceInfo.metaData;
            if (bundle == null) {
                mapEmptyMap = Collections.emptyMap();
            } else {
                HashMap map = new HashMap();
                for (String str2 : bundle.keySet()) {
                    Object obj = bundle.get(str2);
                    if ((obj instanceof String) && str2.startsWith("backend:")) {
                        for (String str3 : ((String) obj).split(",", -1)) {
                            String strTrim = str3.trim();
                            if (!strTrim.isEmpty()) {
                                map.put(strTrim, str2.substring(8));
                            }
                        }
                    }
                }
                mapEmptyMap = map;
            }
            this.f34219b = mapEmptyMap;
        }
        String str4 = (String) this.f34219b.get(str);
        if (str4 == null) {
            return null;
        }
        try {
            return (e) Class.forName(str4).asSubclass(e.class).getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
        } catch (ClassNotFoundException unused2) {
            String.format("Class %s is not found.", str4);
            return null;
        } catch (IllegalAccessException unused3) {
            String.format("Could not instantiate %s.", str4);
            return null;
        } catch (InstantiationException unused4) {
            String.format("Could not instantiate %s.", str4);
            return null;
        } catch (NoSuchMethodException unused5) {
            String.format("Could not instantiate %s", str4);
            return null;
        } catch (InvocationTargetException unused6) {
            String.format("Could not instantiate %s", str4);
            return null;
        }
    }
}
