package ῲ.ؿ;

import androidx.lifecycle.Lifecycle;
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;
import ඓ.K.K.K.C1293;

/* renamed from: ῲ.ؿ.K  reason: contains not printable characters */
/* compiled from: ClassesInfoCache */
public class C1575 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public static C1575 f5740 = new C1575();

    /* renamed from: ῲ  reason: contains not printable characters */
    public final Map<Class, Boolean> f5741 = new HashMap();

    /* renamed from: K  reason: contains not printable characters */
    public final Map<Class, C1577> f5742 = new HashMap();

    /* renamed from: ῲ.ؿ.K$ῲ  reason: contains not printable characters */
    /* compiled from: ClassesInfoCache */
    public static class C1576 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final Method f5743;

        /* renamed from: K  reason: contains not printable characters */
        public final int f5744;

        public C1576(int i, Method method) {
            this.f5744 = i;
            this.f5743 = method;
            this.f5743.setAccessible(true);
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null || C1576.class != obj.getClass()) {
                return false;
            }
            C1576 r5 = (C1576) obj;
            if (this.f5744 != r5.f5744 || !this.f5743.getName().equals(r5.f5743.getName())) {
                return false;
            }
            return true;
        }

        public int hashCode() {
            return this.f5743.getName().hashCode() + (this.f5744 * 31);
        }

        /* renamed from: K  reason: contains not printable characters */
        public void m4125(AbstractC1574 r5, Lifecycle.Event event, Object obj) {
            try {
                int i = this.f5744;
                if (i == 0) {
                    this.f5743.invoke(obj, new Object[0]);
                } else if (i == 1) {
                    this.f5743.invoke(obj, r5);
                } else if (i == 2) {
                    this.f5743.invoke(obj, r5, event);
                }
            } catch (InvocationTargetException e) {
                throw new RuntimeException("Failed to call observer method", e.getCause());
            } catch (IllegalAccessException e2) {
                throw new RuntimeException(e2);
            }
        }
    }

    /* renamed from: ῲ.ؿ.K$K  reason: contains not printable characters */
    /* compiled from: ClassesInfoCache */
    public static class C1577 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final Map<C1576, Lifecycle.Event> f5745;

        /* renamed from: K  reason: contains not printable characters */
        public final Map<Lifecycle.Event, List<C1576>> f5746 = new HashMap();

        public C1577(Map<C1576, Lifecycle.Event> map) {
            this.f5745 = map;
            for (Map.Entry<C1576, Lifecycle.Event> entry : map.entrySet()) {
                Lifecycle.Event value = entry.getValue();
                List<C1576> list = this.f5746.get(value);
                if (list == null) {
                    list = new ArrayList<>();
                    this.f5746.put(value, list);
                }
                list.add(entry.getKey());
            }
        }

        /* renamed from: K  reason: contains not printable characters */
        public static void m4126(List<C1576> list, AbstractC1574 r3, Lifecycle.Event event, Object obj) {
            if (list != null) {
                for (int size = list.size() - 1; size >= 0; size--) {
                    list.get(size).m4125(r3, event, obj);
                }
            }
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public C1577 m4121(Class cls) {
        C1577 k = this.f5742.get(cls);
        if (k != null) {
            return k;
        }
        return m4122(cls, null);
    }

    /* renamed from: K  reason: contains not printable characters */
    public final Method[] m4124(Class cls) {
        try {
            return cls.getDeclaredMethods();
        } catch (NoClassDefFoundError e) {
            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.", e);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m4123(Map<C1576, Lifecycle.Event> map, C1576 r4, Lifecycle.Event event, Class cls) {
        Lifecycle.Event event2 = map.get(r4);
        if (event2 != null && event != event2) {
            Method method = r4.f5743;
            StringBuilder r1 = C1293.m3416("Method ");
            r1.append(method.getName());
            r1.append(" in ");
            r1.append(cls.getName());
            r1.append(" already declared with different @OnLifecycleEvent value: previous value ");
            r1.append(event2);
            r1.append(", new value ");
            r1.append(event);
            throw new IllegalArgumentException(r1.toString());
        } else if (event2 == null) {
            map.put(r4, event);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final C1577 m4122(Class cls, Method[] methodArr) {
        int i;
        C1577 r0;
        Class superclass = cls.getSuperclass();
        HashMap hashMap = new HashMap();
        if (!(superclass == null || (r0 = m4121(superclass)) == null)) {
            hashMap.putAll(r0.f5745);
        }
        for (Class<?> cls2 : cls.getInterfaces()) {
            for (Map.Entry<C1576, Lifecycle.Event> entry : m4121(cls2).f5745.entrySet()) {
                m4123(hashMap, entry.getKey(), entry.getValue(), cls);
            }
        }
        if (methodArr == null) {
            try {
                methodArr = cls.getDeclaredMethods();
            } catch (NoClassDefFoundError e) {
                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.", e);
            }
        }
        boolean z = false;
        for (Method method : methodArr) {
            AbstractC1566 r6 = (AbstractC1566) method.getAnnotation(AbstractC1566.class);
            if (r6 != null) {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length <= 0) {
                    i = 0;
                } else if (parameterTypes[0].isAssignableFrom(AbstractC1574.class)) {
                    i = 1;
                } else {
                    throw new IllegalArgumentException("invalid parameter type. Must be one and instanceof LifecycleOwner");
                }
                Lifecycle.Event value = r6.value();
                if (parameterTypes.length > 1) {
                    if (!parameterTypes[1].isAssignableFrom(Lifecycle.Event.class)) {
                        throw new IllegalArgumentException("invalid parameter type. second arg must be an event");
                    } else if (value == Lifecycle.Event.ON_ANY) {
                        i = 2;
                    } else {
                        throw new IllegalArgumentException("Second arg is supported only for ON_ANY value");
                    }
                }
                if (parameterTypes.length <= 2) {
                    m4123(hashMap, new C1576(i, method), value, cls);
                    z = true;
                } else {
                    throw new IllegalArgumentException("cannot have more than 2 params");
                }
            }
        }
        C1577 k = new C1577(hashMap);
        this.f5742.put(cls, k);
        this.f5741.put(cls, Boolean.valueOf(z));
        return k;
    }
}
