package androidx.versionedparcelable;

import android.os.Parcelable;
import java.lang.reflect.InvocationTargetException;

/* JADX INFO: compiled from: VersionedParcel.java */
/* JADX INFO: loaded from: classes.dex */
public abstract class a {
    protected static <T extends c> void A(T t, a aVar) {
        try {
            c(t).getDeclaredMethod("write", t.getClass(), a.class).invoke(null, t, aVar);
        } catch (ClassNotFoundException e2) {
            throw new RuntimeException("VersionedParcel encountered ClassNotFoundException", e2);
        } catch (IllegalAccessException e3) {
            throw new RuntimeException("VersionedParcel encountered IllegalAccessException", e3);
        } catch (NoSuchMethodException e4) {
            throw new RuntimeException("VersionedParcel encountered NoSuchMethodException", e4);
        } catch (InvocationTargetException e5) {
            if (!(e5.getCause() instanceof RuntimeException)) {
                throw new RuntimeException("VersionedParcel encountered InvocationTargetException", e5);
            }
            throw ((RuntimeException) e5.getCause());
        }
    }

    private void C(c cVar) {
        try {
            y(d(cVar.getClass()).getName());
        } catch (ClassNotFoundException e2) {
            throw new RuntimeException(cVar.getClass().getSimpleName() + " does not have a Parcelizer", e2);
        }
    }

    private static <T extends c> Class c(T t) throws ClassNotFoundException {
        return d(t.getClass());
    }

    private static Class d(Class<? extends c> cls) throws ClassNotFoundException {
        return Class.forName(String.format("%s.%sParcelizer", cls.getPackage().getName(), cls.getSimpleName()), false, cls.getClassLoader());
    }

    protected static <T extends c> T i(String str, a aVar) {
        try {
            return (T) Class.forName(str, true, a.class.getClassLoader()).getDeclaredMethod("read", a.class).invoke(null, aVar);
        } catch (ClassNotFoundException e2) {
            throw new RuntimeException("VersionedParcel encountered ClassNotFoundException", e2);
        } catch (IllegalAccessException e3) {
            throw new RuntimeException("VersionedParcel encountered IllegalAccessException", e3);
        } catch (NoSuchMethodException e4) {
            throw new RuntimeException("VersionedParcel encountered NoSuchMethodException", e4);
        } catch (InvocationTargetException e5) {
            if (e5.getCause() instanceof RuntimeException) {
                throw ((RuntimeException) e5.getCause());
            }
            throw new RuntimeException("VersionedParcel encountered InvocationTargetException", e5);
        }
    }

    protected void B(c cVar) {
        if (cVar == null) {
            y(null);
            return;
        }
        C(cVar);
        a aVarB = b();
        A(cVar, aVarB);
        aVarB.a();
    }

    protected abstract void a();

    protected abstract a b();

    public boolean e() {
        return false;
    }

    protected abstract byte[] f();

    public byte[] g(byte[] bArr, int i) {
        return !h(i) ? bArr : f();
    }

    protected abstract boolean h(int i);

    protected abstract int j();

    public int k(int i, int i2) {
        return !h(i2) ? i : j();
    }

    protected abstract <T extends Parcelable> T l();

    public <T extends Parcelable> T m(T t, int i) {
        return !h(i) ? t : (T) l();
    }

    protected abstract String n();

    public String o(String str, int i) {
        return !h(i) ? str : n();
    }

    protected <T extends c> T p() {
        String strN = n();
        if (strN == null) {
            return null;
        }
        return (T) i(strN, b());
    }

    protected abstract void q(int i);

    public void r(boolean z, boolean z2) {
    }

    protected abstract void s(byte[] bArr);

    public void t(byte[] bArr, int i) {
        q(i);
        s(bArr);
    }

    protected abstract void u(int i);

    public void v(int i, int i2) {
        q(i2);
        u(i);
    }

    protected abstract void w(Parcelable parcelable);

    public void x(Parcelable parcelable, int i) {
        q(i);
        w(parcelable);
    }

    protected abstract void y(String str);

    public void z(String str, int i) {
        q(i);
        y(str);
    }
}
