package x2;

import android.os.Parcel;
import android.os.Parcelable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import n.C2578e;

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

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

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

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

    public AbstractC3213a(C2578e c2578e, C2578e c2578e2, C2578e c2578e3) {
        this.f25991a = c2578e;
        this.f25992b = c2578e2;
        this.f25993c = c2578e3;
    }

    public abstract C3214b a();

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

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

    public final Method d(Class cls) throws NoSuchMethodException, ClassNotFoundException {
        String name = cls.getName();
        C2578e c2578e = this.f25992b;
        Method method = (Method) c2578e.get(name);
        if (method != null) {
            return method;
        }
        Class clsB = b(cls);
        System.currentTimeMillis();
        Method declaredMethod = clsB.getDeclaredMethod("write", cls, AbstractC3213a.class);
        c2578e.put(cls.getName(), declaredMethod);
        return declaredMethod;
    }

    public abstract boolean e(int i6);

    public final int f(int i6, int i7) {
        return !e(i7) ? i6 : ((C3214b) this).f25995e.readInt();
    }

    public final Parcelable g(Parcelable parcelable, int i6) {
        if (!e(i6)) {
            return parcelable;
        }
        return ((C3214b) this).f25995e.readParcelable(C3214b.class.getClassLoader());
    }

    public final InterfaceC3215c h() {
        String string = ((C3214b) this).f25995e.readString();
        if (string == null) {
            return null;
        }
        try {
            return (InterfaceC3215c) c(string).invoke(null, a());
        } catch (ClassNotFoundException e6) {
            throw new RuntimeException("VersionedParcel encountered ClassNotFoundException", e6);
        } catch (IllegalAccessException e7) {
            throw new RuntimeException("VersionedParcel encountered IllegalAccessException", e7);
        } catch (NoSuchMethodException e8) {
            throw new RuntimeException("VersionedParcel encountered NoSuchMethodException", e8);
        } catch (InvocationTargetException e9) {
            if (e9.getCause() instanceof RuntimeException) {
                throw ((RuntimeException) e9.getCause());
            }
            throw new RuntimeException("VersionedParcel encountered InvocationTargetException", e9);
        }
    }

    public abstract void i(int i6);

    public final void j(int i6, int i7) {
        i(i7);
        ((C3214b) this).f25995e.writeInt(i6);
    }

    public final void k(Parcelable parcelable, int i6) {
        i(i6);
        ((C3214b) this).f25995e.writeParcelable(parcelable, 0);
    }

    public final void l(InterfaceC3215c interfaceC3215c) {
        if (interfaceC3215c == null) {
            ((C3214b) this).f25995e.writeString(null);
            return;
        }
        try {
            ((C3214b) this).f25995e.writeString(b(interfaceC3215c.getClass()).getName());
            C3214b c3214bA = a();
            try {
                d(interfaceC3215c.getClass()).invoke(null, interfaceC3215c, c3214bA);
                int i6 = c3214bA.f25999i;
                if (i6 >= 0) {
                    int i7 = c3214bA.f25994d.get(i6);
                    Parcel parcel = c3214bA.f25995e;
                    int iDataPosition = parcel.dataPosition();
                    parcel.setDataPosition(i7);
                    parcel.writeInt(iDataPosition - i7);
                    parcel.setDataPosition(iDataPosition);
                }
            } catch (ClassNotFoundException e6) {
                throw new RuntimeException("VersionedParcel encountered ClassNotFoundException", e6);
            } catch (IllegalAccessException e7) {
                throw new RuntimeException("VersionedParcel encountered IllegalAccessException", e7);
            } catch (NoSuchMethodException e8) {
                throw new RuntimeException("VersionedParcel encountered NoSuchMethodException", e8);
            } catch (InvocationTargetException e9) {
                if (!(e9.getCause() instanceof RuntimeException)) {
                    throw new RuntimeException("VersionedParcel encountered InvocationTargetException", e9);
                }
                throw ((RuntimeException) e9.getCause());
            }
        } catch (ClassNotFoundException e10) {
            throw new RuntimeException(interfaceC3215c.getClass().getSimpleName().concat(" does not have a Parcelizer"), e10);
        }
    }
}
