package androidx.lifecycle; import androidx.lifecycle.e; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /* loaded from: classes.dex */ final class b { /* renamed from: c, reason: collision with root package name */ static b f2064c = new b(); /* renamed from: a, reason: collision with root package name */ private final Map f2065a = new HashMap(); /* renamed from: b, reason: collision with root package name */ private final Map f2066b = new HashMap(); static class a { /* renamed from: a, reason: collision with root package name */ final Map f2067a = new HashMap(); /* renamed from: b, reason: collision with root package name */ final Map f2068b; a(Map map) { this.f2068b = map; for (Map.Entry entry : map.entrySet()) { e.b bVar = (e.b) entry.getValue(); List list = (List) this.f2067a.get(bVar); if (list == null) { list = new ArrayList(); this.f2067a.put(bVar, list); } list.add((C0026b) entry.getKey()); } } private static void b(List list, LifecycleOwner lifecycleOwner, e.b bVar, Object obj) { if (list != null) { for (int size = list.size() - 1; size >= 0; size--) { ((C0026b) list.get(size)).a(lifecycleOwner, bVar, obj); } } } void a(LifecycleOwner lifecycleOwner, e.b bVar, Object obj) { b((List) this.f2067a.get(bVar), lifecycleOwner, bVar, obj); b((List) this.f2067a.get(e.b.ON_ANY), lifecycleOwner, bVar, obj); } } /* renamed from: androidx.lifecycle.b$b, reason: collision with other inner class name */ static final class C0026b { /* renamed from: a, reason: collision with root package name */ final int f2069a; /* renamed from: b, reason: collision with root package name */ final Method f2070b; C0026b(int i10, Method method) { this.f2069a = i10; this.f2070b = method; method.setAccessible(true); } void a(LifecycleOwner lifecycleOwner, e.b bVar, Object obj) { try { int i10 = this.f2069a; if (i10 == 0) { this.f2070b.invoke(obj, new Object[0]); } else if (i10 == 1) { this.f2070b.invoke(obj, lifecycleOwner); } else { if (i10 != 2) { return; } this.f2070b.invoke(obj, lifecycleOwner, bVar); } } catch (IllegalAccessException e10) { throw new RuntimeException(e10); } catch (InvocationTargetException e11) { throw new RuntimeException("Failed to call observer method", e11.getCause()); } } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof C0026b)) { return false; } C0026b c0026b = (C0026b) obj; return this.f2069a == c0026b.f2069a && this.f2070b.getName().equals(c0026b.f2070b.getName()); } public int hashCode() { return (this.f2069a * 31) + this.f2070b.getName().hashCode(); } } b() { } private a a(Class cls, Method[] methodArr) { int i10; a c10; Class superclass = cls.getSuperclass(); HashMap hashMap = new HashMap(); if (superclass != null && (c10 = c(superclass)) != null) { hashMap.putAll(c10.f2068b); } for (Class cls2 : cls.getInterfaces()) { for (Map.Entry entry : c(cls2).f2068b.entrySet()) { e(hashMap, (C0026b) entry.getKey(), (e.b) entry.getValue(), cls); } } if (methodArr == null) { methodArr = b(cls); } boolean z10 = false; for (Method method : methodArr) { n nVar = (n) method.getAnnotation(n.class); if (nVar != null) { Class[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length <= 0) { i10 = 0; } else { if (!parameterTypes[0].isAssignableFrom(LifecycleOwner.class)) { throw new IllegalArgumentException("invalid parameter type. Must be one and instanceof LifecycleOwner"); } i10 = 1; } e.b value = nVar.value(); if (parameterTypes.length > 1) { if (!parameterTypes[1].isAssignableFrom(e.b.class)) { throw new IllegalArgumentException("invalid parameter type. second arg must be an event"); } if (value != e.b.ON_ANY) { throw new IllegalArgumentException("Second arg is supported only for ON_ANY value"); } i10 = 2; } if (parameterTypes.length > 2) { throw new IllegalArgumentException("cannot have more than 2 params"); } e(hashMap, new C0026b(i10, method), value, cls); z10 = true; } } a aVar = new a(hashMap); this.f2065a.put(cls, aVar); this.f2066b.put(cls, Boolean.valueOf(z10)); return aVar; } private Method[] b(Class cls) { try { return cls.getDeclaredMethods(); } catch (NoClassDefFoundError e10) { throw new IllegalArgumentException("The observer class has some methods that use newer APIs which are not available in the current OS version. Lifecycles cannot access even other methods so you should make sure that your observer classes only access framework classes that are available in your min API level OR use lifecycle:compiler annotation processor.", e10); } } private void e(Map map, C0026b c0026b, e.b bVar, Class cls) { e.b bVar2 = (e.b) map.get(c0026b); if (bVar2 == null || bVar == bVar2) { if (bVar2 == null) { map.put(c0026b, bVar); return; } return; } throw new IllegalArgumentException("Method " + c0026b.f2070b.getName() + " in " + cls.getName() + " already declared with different @OnLifecycleEvent value: previous value " + bVar2 + ", new value " + bVar); } a c(Class cls) { a aVar = (a) this.f2065a.get(cls); return aVar != null ? aVar : a(cls, null); } boolean d(Class cls) { Boolean bool = (Boolean) this.f2066b.get(cls); if (bool != null) { return bool.booleanValue(); } Method[] b10 = b(cls); for (Method method : b10) { if (((n) method.getAnnotation(n.class)) != null) { a(cls, b10); return true; } } this.f2066b.put(cls, Boolean.FALSE); return false; } }