package androidx.datastore.preferences.protobuf;

import java.lang.reflect.Field;
import java.nio.Buffer;
import java.nio.ByteOrder;
import java.security.AccessController;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.misc.Unsafe;

/* JADX INFO: loaded from: classes.dex */
public abstract class h0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final Unsafe f8080a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Class f8081b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final g0 f8082c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final boolean f8083d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final boolean f8084e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final long f8085f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final boolean f8086g;

    static {
        Unsafe unsafeI = i();
        f8080a = unsafeI;
        f8081b = AbstractC0425c.f8059a;
        boolean zH = h(Long.TYPE);
        boolean zH2 = h(Integer.TYPE);
        g0 f0Var = null;
        if (unsafeI != null) {
            if (!AbstractC0425c.a()) {
                f0Var = new f0(unsafeI);
            } else if (zH) {
                f0Var = new e0(unsafeI, 1);
            } else if (zH2) {
                f0Var = new e0(unsafeI, 0);
            }
        }
        f8082c = f0Var;
        f8083d = f0Var == null ? false : f0Var.r();
        f8084e = f0Var == null ? false : f0Var.q();
        f8085f = e(byte[].class);
        e(boolean[].class);
        f(boolean[].class);
        e(int[].class);
        f(int[].class);
        e(long[].class);
        f(long[].class);
        e(float[].class);
        f(float[].class);
        e(double[].class);
        f(double[].class);
        e(Object[].class);
        f(Object[].class);
        Field fieldG = g();
        if (fieldG != null && f0Var != null) {
            f0Var.i(fieldG);
        }
        f8086g = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
    }

    public static void a(Throwable th) {
        Logger.getLogger(h0.class.getName()).log(Level.WARNING, "platform method missing - proto runtime falling back to safer methods: " + th);
    }

    public static boolean b(long j8, Object obj) {
        return ((byte) ((f8082c.f((-4) & j8, obj) >>> ((int) (((~j8) & 3) << 3))) & 255)) != 0;
    }

    public static boolean c(long j8, Object obj) {
        return ((byte) ((f8082c.f((-4) & j8, obj) >>> ((int) ((j8 & 3) << 3))) & 255)) != 0;
    }

    public static Object d(Class cls) {
        try {
            return f8080a.allocateInstance(cls);
        } catch (InstantiationException e8) {
            throw new IllegalStateException(e8);
        }
    }

    public static int e(Class cls) {
        if (f8084e) {
            return f8082c.a(cls);
        }
        return -1;
    }

    public static void f(Class cls) {
        if (f8084e) {
            f8082c.b(cls);
        }
    }

    public static Field g() {
        Field declaredField;
        Field declaredField2;
        if (AbstractC0425c.a()) {
            try {
                declaredField2 = Buffer.class.getDeclaredField("effectiveDirectAddress");
            } catch (Throwable unused) {
                declaredField2 = null;
            }
            if (declaredField2 != null) {
                return declaredField2;
            }
        }
        try {
            declaredField = Buffer.class.getDeclaredField("address");
        } catch (Throwable unused2) {
            declaredField = null;
        }
        if (declaredField == null || declaredField.getType() != Long.TYPE) {
            return null;
        }
        return declaredField;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static boolean h(Class cls) {
        if (!AbstractC0425c.a()) {
            return false;
        }
        try {
            Class cls2 = f8081b;
            Class cls3 = Boolean.TYPE;
            cls2.getMethod("peekLong", cls, cls3);
            cls2.getMethod("pokeLong", cls, Long.TYPE, cls3);
            Class cls4 = Integer.TYPE;
            cls2.getMethod("pokeInt", cls, cls4, cls3);
            cls2.getMethod("peekInt", cls, cls3);
            cls2.getMethod("pokeByte", cls, Byte.TYPE);
            cls2.getMethod("peekByte", cls);
            cls2.getMethod("pokeByteArray", cls, byte[].class, cls4, cls4);
            cls2.getMethod("peekByteArray", cls, byte[].class, cls4, cls4);
            return true;
        } catch (Throwable unused) {
            return false;
        }
    }

    public static Unsafe i() {
        try {
            return (Unsafe) AccessController.doPrivileged(new d0());
        } catch (Throwable unused) {
            return null;
        }
    }

    public static void j(byte[] bArr, long j8, byte b8) {
        f8082c.k(bArr, f8085f + j8, b8);
    }

    public static void k(Object obj, long j8, byte b8) {
        long j9 = (-4) & j8;
        int iF = f8082c.f(j9, obj);
        int i = ((~((int) j8)) & 3) << 3;
        m(((255 & b8) << i) | (iF & (~(255 << i))), j9, obj);
    }

    public static void l(Object obj, long j8, byte b8) {
        long j9 = (-4) & j8;
        int i = (((int) j8) & 3) << 3;
        m(((255 & b8) << i) | (f8082c.f(j9, obj) & (~(255 << i))), j9, obj);
    }

    public static void m(int i, long j8, Object obj) {
        f8082c.n(i, j8, obj);
    }

    public static void n(Object obj, long j8, long j9) {
        f8082c.o(obj, j8, j9);
    }

    public static void o(Object obj, long j8, Object obj2) {
        f8082c.p(obj, j8, obj2);
    }
}
