package androidx.lifecycle; import com.google.android.gms.ads.RequestConfiguration; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; /* loaded from: classes.dex */ public abstract class k { /* renamed from: a, reason: collision with root package name */ private static Map f2092a = new HashMap(); /* renamed from: b, reason: collision with root package name */ private static Map f2093b = new HashMap(); private static d a(Constructor constructor, Object obj) { try { androidx.appcompat.app.m.a(constructor.newInstance(obj)); return null; } catch (IllegalAccessException e10) { throw new RuntimeException(e10); } catch (InstantiationException e11) { throw new RuntimeException(e11); } catch (InvocationTargetException e12) { throw new RuntimeException(e12); } } /* JADX WARN: Multi-variable type inference failed */ private static Constructor b(Class cls) { try { Package r02 = cls.getPackage(); String canonicalName = cls.getCanonicalName(); String name = r02 != null ? r02.getName() : RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED; if (!name.isEmpty()) { canonicalName = canonicalName.substring(name.length() + 1); } String c10 = c(canonicalName); if (!name.isEmpty()) { c10 = name + "." + c10; } Constructor declaredConstructor = Class.forName(c10).getDeclaredConstructor(cls); if (!declaredConstructor.isAccessible()) { declaredConstructor.setAccessible(true); } return declaredConstructor; } catch (ClassNotFoundException unused) { return null; } catch (NoSuchMethodException e10) { throw new RuntimeException(e10); } } public static String c(String str) { return str.replace(".", "_") + "_LifecycleAdapter"; } private static int d(Class cls) { Integer num = (Integer) f2092a.get(cls); if (num != null) { return num.intValue(); } int g10 = g(cls); f2092a.put(cls, Integer.valueOf(g10)); return g10; } private static boolean e(Class cls) { return cls != null && h.class.isAssignableFrom(cls); } static g f(Object obj) { if (obj instanceof g) { return (g) obj; } Class cls = obj.getClass(); if (d(cls) != 2) { return new ReflectiveGenericLifecycleObserver(obj); } List list = (List) f2093b.get(cls); if (list.size() == 1) { a((Constructor) list.get(0), obj); return new SingleGeneratedAdapterObserver(null); } d[] dVarArr = new d[list.size()]; for (int i10 = 0; i10 < list.size(); i10++) { a((Constructor) list.get(i10), obj); dVarArr[i10] = null; } return new CompositeGeneratedAdaptersObserver(dVarArr); } private static int g(Class cls) { ArrayList arrayList; if (cls.getCanonicalName() == null) { return 1; } Constructor b10 = b(cls); if (b10 != null) { f2093b.put(cls, Collections.singletonList(b10)); return 2; } if (b.f2064c.d(cls)) { return 1; } Class superclass = cls.getSuperclass(); if (!e(superclass)) { arrayList = null; } else { if (d(superclass) == 1) { return 1; } arrayList = new ArrayList((Collection) f2093b.get(superclass)); } for (Class cls2 : cls.getInterfaces()) { if (e(cls2)) { if (d(cls2) == 1) { return 1; } if (arrayList == null) { arrayList = new ArrayList(); } arrayList.addAll((Collection) f2093b.get(cls2)); } } if (arrayList == null) { return 1; } f2093b.put(cls, arrayList); return 2; } }