package p138.p176.p177.p178.p181.p182;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
import android.util.Log;
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: renamed from: ދ.ހ.֏.֏.ރ.ތ.ވ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C3323 implements InterfaceC3316 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C3324 f9786;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final C3321 f9787;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final Map<String, InterfaceC3326> f9788;

    /* JADX INFO: renamed from: ދ.ހ.֏.֏.ރ.ތ.ވ$֏, reason: contains not printable characters */
    public static class C3324 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final Context f9789;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public Map<String, String> f9790 = null;

        public C3324(Context context) {
            this.f9789 = context;
        }

        /* JADX WARN: Removed duplicated region for block: B:16:0x003a  */
        /* JADX WARN: Removed duplicated region for block: B:17:0x0044  */
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public InterfaceC3315 m5375(String str) {
            Bundle bundle;
            Map<String, String> mapEmptyMap;
            PackageManager packageManager;
            if (this.f9790 == null) {
                Context context = this.f9789;
                try {
                    packageManager = context.getPackageManager();
                } catch (PackageManager.NameNotFoundException unused) {
                    Log.w("BackendRegistry", "Application info not found.");
                }
                if (packageManager == null) {
                    Log.w("BackendRegistry", "Context has no PackageManager.");
                } else {
                    ServiceInfo serviceInfo = packageManager.getServiceInfo(new ComponentName(context, (Class<?>) TransportBackendDiscovery.class), 128);
                    if (serviceInfo == null) {
                        Log.w("BackendRegistry", "TransportBackendDiscovery has no service info.");
                    } else {
                        bundle = serviceInfo.metaData;
                        if (bundle != null) {
                            Log.w("BackendRegistry", "Could not retrieve metadata, returning empty list of transport backends.");
                            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.f9790 = mapEmptyMap;
                    }
                }
                bundle = null;
                if (bundle != null) {
                }
                this.f9790 = mapEmptyMap;
            }
            String str4 = this.f9790.get(str);
            if (str4 == null) {
                return null;
            }
            try {
                return (InterfaceC3315) Class.forName(str4).asSubclass(InterfaceC3315.class).getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
            } catch (ClassNotFoundException e) {
                Log.w("BackendRegistry", String.format("Class %s is not found.", str4), e);
                return null;
            } catch (IllegalAccessException e2) {
                Log.w("BackendRegistry", String.format("Could not instantiate %s.", str4), e2);
                return null;
            } catch (InstantiationException e3) {
                Log.w("BackendRegistry", String.format("Could not instantiate %s.", str4), e3);
                return null;
            } catch (NoSuchMethodException e4) {
                Log.w("BackendRegistry", String.format("Could not instantiate %s", str4), e4);
                return null;
            } catch (InvocationTargetException e5) {
                Log.w("BackendRegistry", String.format("Could not instantiate %s", str4), e5);
                return null;
            }
        }
    }

    public C3323(Context context, C3321 c3321) {
        C3324 c3324 = new C3324(context);
        this.f9788 = new HashMap();
        this.f9786 = c3324;
        this.f9787 = c3321;
    }

    @Override // p138.p176.p177.p178.p181.p182.InterfaceC3316
    /* JADX INFO: renamed from: ֏ */
    public synchronized InterfaceC3326 mo5373(String str) {
        if (this.f9788.containsKey(str)) {
            return this.f9788.get(str);
        }
        InterfaceC3315 interfaceC3315M5375 = this.f9786.m5375(str);
        if (interfaceC3315M5375 == null) {
            return null;
        }
        C3321 c3321 = this.f9787;
        InterfaceC3326 interfaceC3326Create = interfaceC3315M5375.create(new C3314(c3321.f9780, c3321.f9781, c3321.f9782, str));
        this.f9788.put(str, interfaceC3326Create);
        return interfaceC3326Create;
    }
}
