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 B(T t, a aVar) {
        try {
            c(t).getDeclaredMethod("write", t.getClass(), a.class).invoke(null, t, aVar);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("VersionedParcel encountered ClassNotFoundException", e);
        } catch (IllegalAccessException e2) {
            throw new RuntimeException("VersionedParcel encountered IllegalAccessException", e2);
        } catch (NoSuchMethodException e3) {
            throw new RuntimeException("VersionedParcel encountered NoSuchMethodException", e3);
        } catch (InvocationTargetException e4) {
            if (!(e4.getCause() instanceof RuntimeException)) {
                throw new RuntimeException("VersionedParcel encountered InvocationTargetException", e4);
            }
            throw ((RuntimeException) e4.getCause());
        }
    }

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

    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 e) {
            throw new RuntimeException("VersionedParcel encountered ClassNotFoundException", e);
        } catch (IllegalAccessException e2) {
            throw new RuntimeException("VersionedParcel encountered IllegalAccessException", e2);
        } catch (NoSuchMethodException e3) {
            throw new RuntimeException("VersionedParcel encountered NoSuchMethodException", e3);
        } catch (InvocationTargetException e4) {
            if (e4.getCause() instanceof RuntimeException) {
                throw ((RuntimeException) e4.getCause());
            }
            throw new RuntimeException("VersionedParcel encountered InvocationTargetException", e4);
        }
    }

    public void A(String str, int i2) {
        r(i2);
        z(str);
    }

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

    public void D(c cVar, int i2) {
        r(i2);
        C(cVar);
    }

    protected abstract void a();

    protected abstract a b();

    public boolean e() {
        return false;
    }

    protected abstract byte[] f();

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

    protected abstract boolean h(int i2);

    protected abstract int j();

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

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

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

    protected abstract String n();

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

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

    public <T extends c> T q(T t, int i2) {
        return !h(i2) ? t : (T) p();
    }

    protected abstract void r(int i2);

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

    protected abstract void t(byte[] bArr);

    public void u(byte[] bArr, int i2) {
        r(i2);
        t(bArr);
    }

    protected abstract void v(int i2);

    public void w(int i2, int i3) {
        r(i3);
        v(i2);
    }

    protected abstract void x(Parcelable parcelable);

    public void y(Parcelable parcelable, int i2) {
        r(i2);
        x(parcelable);
    }

    protected abstract void z(String str);
}
