package ῲ.ؿ;

import androidx.lifecycle.CompositeGeneratedAdaptersObserver;
import androidx.lifecycle.FullLifecycleObserverAdapter;
import androidx.lifecycle.ReflectiveGenericLifecycleObserver;
import androidx.lifecycle.SingleGeneratedAdapterObserver;
import com.facebook.appevents.codeless.CodelessMatcher;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* renamed from: ῲ.ؿ.㳳  reason: contains not printable characters */
/* compiled from: Lifecycling */
public class C1581 {

    /* renamed from: ῲ  reason: contains not printable characters */
    public static Map<Class, List<Constructor<? extends AbstractC1565>>> f5747 = new HashMap();

    /* renamed from: K  reason: contains not printable characters */
    public static Map<Class, Integer> f5748 = new HashMap();

    /* renamed from: ῲ  reason: contains not printable characters */
    public static boolean m4133(Class<?> cls) {
        return cls != null && AbstractC1582.class.isAssignableFrom(cls);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static AbstractC1569 m4137(Object obj) {
        boolean z = obj instanceof AbstractC1569;
        boolean z2 = obj instanceof AbstractC1573;
        if (z && z2) {
            return new FullLifecycleObserverAdapter((AbstractC1573) obj, (AbstractC1569) obj);
        }
        if (z2) {
            return new FullLifecycleObserverAdapter((AbstractC1573) obj, null);
        }
        if (z) {
            return (AbstractC1569) obj;
        }
        Class<?> cls = obj.getClass();
        if (m4134(cls) != 2) {
            return new ReflectiveGenericLifecycleObserver(obj);
        }
        List<Constructor<? extends AbstractC1565>> list = f5747.get(cls);
        if (list.size() == 1) {
            return new SingleGeneratedAdapterObserver(m4136(list.get(0), obj));
        }
        AbstractC1565[] r1 = new AbstractC1565[list.size()];
        for (int i = 0; i < list.size(); i++) {
            r1[i] = m4136(list.get(i), obj);
        }
        return new CompositeGeneratedAdaptersObserver(r1);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static AbstractC1565 m4136(Constructor<? extends AbstractC1565> constructor, Object obj) {
        try {
            return (AbstractC1565) constructor.newInstance(obj);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e2) {
            throw new RuntimeException(e2);
        } catch (InvocationTargetException e3) {
            throw new RuntimeException(e3);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static int m4134(Class<?> cls) {
        Constructor<?> constructor;
        boolean z;
        Integer num = f5748.get(cls);
        if (num != null) {
            return num.intValue();
        }
        int i = 1;
        if (cls.getCanonicalName() != null) {
            ArrayList arrayList = null;
            int i2 = 0;
            try {
                Package r3 = cls.getPackage();
                String canonicalName = cls.getCanonicalName();
                String name = r3 != null ? r3.getName() : "";
                if (!name.isEmpty()) {
                    canonicalName = canonicalName.substring(name.length() + 1);
                }
                String r4 = m4135(canonicalName);
                if (!name.isEmpty()) {
                    r4 = name + CodelessMatcher.CURRENT_CLASS_NAME + r4;
                }
                constructor = Class.forName(r4).getDeclaredConstructor(cls);
                if (!constructor.isAccessible()) {
                    constructor.setAccessible(true);
                }
            } catch (ClassNotFoundException unused) {
                constructor = null;
            } catch (NoSuchMethodException e) {
                throw new RuntimeException(e);
            }
            if (constructor != null) {
                f5747.put(cls, Collections.singletonList(constructor));
            } else {
                C1575 k = C1575.f5740;
                Boolean bool = k.f5741.get(cls);
                if (bool == null) {
                    Method[] r5 = k.m4124(cls);
                    int length = r5.length;
                    int i3 = 0;
                    while (true) {
                        if (i3 >= length) {
                            k.f5741.put(cls, false);
                            z = false;
                            break;
                        } else if (((AbstractC1566) r5[i3].getAnnotation(AbstractC1566.class)) != null) {
                            k.m4122(cls, r5);
                            z = true;
                            break;
                        } else {
                            i3++;
                        }
                    }
                } else {
                    z = bool.booleanValue();
                }
                if (!z) {
                    Class<? super Object> superclass = cls.getSuperclass();
                    if (m4133(superclass)) {
                        if (m4134((Class<?>) superclass) != 1) {
                            arrayList = new ArrayList(f5747.get(superclass));
                        }
                    }
                    Class<?>[] interfaces = cls.getInterfaces();
                    int length2 = interfaces.length;
                    while (true) {
                        if (i2 < length2) {
                            Class<?> cls2 = interfaces[i2];
                            if (m4133(cls2)) {
                                if (m4134(cls2) == 1) {
                                    break;
                                }
                                if (arrayList == null) {
                                    arrayList = new ArrayList();
                                }
                                arrayList.addAll(f5747.get(cls2));
                            }
                            i2++;
                        } else if (arrayList != null) {
                            f5747.put(cls, arrayList);
                        }
                    }
                }
            }
            i = 2;
        }
        f5748.put(cls, Integer.valueOf(i));
        return i;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static String m4135(String str) {
        return str.replace(CodelessMatcher.CURRENT_CLASS_NAME, "_") + "_LifecycleAdapter";
    }
}
