package r2; 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; /* loaded from: classes.dex */ class k implements e { /* renamed from: a, reason: collision with root package name */ private final a f13640a; /* renamed from: b, reason: collision with root package name */ private final i f13641b; /* renamed from: c, reason: collision with root package name */ private final Map f13642c; static class a { /* renamed from: a, reason: collision with root package name */ private final Context f13643a; /* renamed from: b, reason: collision with root package name */ private Map f13644b = null; a(Context context) { this.f13643a = context; } private Map a(Context context) { Bundle d10 = d(context); if (d10 == null) { Log.w("BackendRegistry", "Could not retrieve metadata, returning empty list of transport backends."); return Collections.emptyMap(); } HashMap hashMap = new HashMap(); for (String str : d10.keySet()) { Object obj = d10.get(str); if ((obj instanceof String) && str.startsWith("backend:")) { for (String str2 : ((String) obj).split(",", -1)) { String trim = str2.trim(); if (!trim.isEmpty()) { hashMap.put(trim, str.substring(8)); } } } } return hashMap; } private Map c() { if (this.f13644b == null) { this.f13644b = a(this.f13643a); } return this.f13644b; } private static Bundle d(Context context) { try { PackageManager packageManager = context.getPackageManager(); if (packageManager == null) { Log.w("BackendRegistry", "Context has no PackageManager."); return null; } ServiceInfo serviceInfo = packageManager.getServiceInfo(new ComponentName(context, (Class) TransportBackendDiscovery.class), 128); if (serviceInfo != null) { return serviceInfo.metaData; } Log.w("BackendRegistry", "TransportBackendDiscovery has no service info."); return null; } catch (PackageManager.NameNotFoundException unused) { Log.w("BackendRegistry", "Application info not found."); return null; } } d b(String str) { String str2 = (String) c().get(str); if (str2 == null) { return null; } try { return (d) Class.forName(str2).asSubclass(d.class).getDeclaredConstructor(new Class[0]).newInstance(new Object[0]); } catch (ClassNotFoundException e10) { Log.w("BackendRegistry", String.format("Class %s is not found.", str2), e10); return null; } catch (IllegalAccessException e11) { Log.w("BackendRegistry", String.format("Could not instantiate %s.", str2), e11); return null; } catch (InstantiationException e12) { Log.w("BackendRegistry", String.format("Could not instantiate %s.", str2), e12); return null; } catch (NoSuchMethodException e13) { Log.w("BackendRegistry", String.format("Could not instantiate %s", str2), e13); return null; } catch (InvocationTargetException e14) { Log.w("BackendRegistry", String.format("Could not instantiate %s", str2), e14); return null; } } } k(Context context, i iVar) { this(new a(context), iVar); } @Override // r2.e public synchronized m get(String str) { if (this.f13642c.containsKey(str)) { return (m) this.f13642c.get(str); } d b10 = this.f13640a.b(str); if (b10 == null) { return null; } m create = b10.create(this.f13641b.a(str)); this.f13642c.put(str, create); return create; } k(a aVar, i iVar) { this.f13642c = new HashMap(); this.f13640a = aVar; this.f13641b = iVar; } }