package e2;

import android.os.Parcel;
import android.os.Parcelable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import q.e;

/* JADX INFO: renamed from: e2.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC0864a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final e f12427a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final e f12428b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final e f12429c;

    public AbstractC0864a(e eVar, e eVar2, e eVar3) {
        this.f12427a = eVar;
        this.f12428b = eVar2;
        this.f12429c = eVar3;
    }

    public abstract C0865b a();

    public final Class b(Class cls) throws ClassNotFoundException {
        String name = cls.getName();
        e eVar = this.f12429c;
        Class cls2 = (Class) eVar.get(name);
        if (cls2 != null) {
            return cls2;
        }
        Class<?> cls3 = Class.forName(cls.getPackage().getName() + "." + cls.getSimpleName() + "Parcelizer", false, cls.getClassLoader());
        eVar.put(cls.getName(), cls3);
        return cls3;
    }

    public final Method c(String str) throws NoSuchMethodException {
        e eVar = this.f12427a;
        Method method = (Method) eVar.get(str);
        if (method != null) {
            return method;
        }
        System.currentTimeMillis();
        Method declaredMethod = Class.forName(str, true, AbstractC0864a.class.getClassLoader()).getDeclaredMethod("read", AbstractC0864a.class);
        eVar.put(str, declaredMethod);
        return declaredMethod;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final Method d(Class cls) throws NoSuchMethodException, ClassNotFoundException {
        String name = cls.getName();
        e eVar = this.f12428b;
        Method method = (Method) eVar.get(name);
        if (method != null) {
            return method;
        }
        Class clsB = b(cls);
        System.currentTimeMillis();
        Method declaredMethod = clsB.getDeclaredMethod("write", cls, AbstractC0864a.class);
        eVar.put(cls.getName(), declaredMethod);
        return declaredMethod;
    }

    public abstract boolean e(int i);

    public final int f(int i, int i5) {
        return !e(i5) ? i : ((C0865b) this).f12431e.readInt();
    }

    public final Parcelable g(Parcelable parcelable, int i) {
        if (!e(i)) {
            return parcelable;
        }
        return ((C0865b) this).f12431e.readParcelable(C0865b.class.getClassLoader());
    }

    public final InterfaceC0866c h() {
        String string = ((C0865b) this).f12431e.readString();
        if (string == null) {
            return null;
        }
        try {
            return (InterfaceC0866c) c(string).invoke(null, a());
        } catch (ClassNotFoundException e8) {
            throw new RuntimeException("VersionedParcel encountered ClassNotFoundException", e8);
        } catch (IllegalAccessException e9) {
            throw new RuntimeException("VersionedParcel encountered IllegalAccessException", e9);
        } catch (NoSuchMethodException e10) {
            throw new RuntimeException("VersionedParcel encountered NoSuchMethodException", e10);
        } catch (InvocationTargetException e11) {
            if (e11.getCause() instanceof RuntimeException) {
                throw ((RuntimeException) e11.getCause());
            }
            throw new RuntimeException("VersionedParcel encountered InvocationTargetException", e11);
        }
    }

    public abstract void i(int i);

    public final void j(int i, int i5) {
        i(i5);
        ((C0865b) this).f12431e.writeInt(i);
    }

    public final void k(InterfaceC0866c interfaceC0866c) {
        if (interfaceC0866c == null) {
            ((C0865b) this).f12431e.writeString(null);
            return;
        }
        try {
            ((C0865b) this).f12431e.writeString(b(interfaceC0866c.getClass()).getName());
            C0865b c0865bA = a();
            try {
                d(interfaceC0866c.getClass()).invoke(null, interfaceC0866c, c0865bA);
                int i = c0865bA.i;
                if (i >= 0) {
                    int i5 = c0865bA.f12430d.get(i);
                    Parcel parcel = c0865bA.f12431e;
                    int iDataPosition = parcel.dataPosition();
                    parcel.setDataPosition(i5);
                    parcel.writeInt(iDataPosition - i5);
                    parcel.setDataPosition(iDataPosition);
                }
            } catch (ClassNotFoundException e8) {
                throw new RuntimeException("VersionedParcel encountered ClassNotFoundException", e8);
            } catch (IllegalAccessException e9) {
                throw new RuntimeException("VersionedParcel encountered IllegalAccessException", e9);
            } catch (NoSuchMethodException e10) {
                throw new RuntimeException("VersionedParcel encountered NoSuchMethodException", e10);
            } catch (InvocationTargetException e11) {
                if (!(e11.getCause() instanceof RuntimeException)) {
                    throw new RuntimeException("VersionedParcel encountered InvocationTargetException", e11);
                }
                throw ((RuntimeException) e11.getCause());
            }
        } catch (ClassNotFoundException e12) {
            throw new RuntimeException(interfaceC0866c.getClass().getSimpleName().concat(" does not have a Parcelizer"), e12);
        }
    }
}
