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 n1 {

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

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

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

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

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

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

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

    static {
        Unsafe unsafeI = i();
        f2120a = unsafeI;
        f2121b = d.f2053a;
        boolean zH = h(Long.TYPE);
        boolean zH2 = h(Integer.TYPE);
        char c6 = 1;
        int i10 = 0;
        m1 l1Var = null;
        if (unsafeI != null) {
            if (!d.a()) {
                l1Var = new l1(unsafeI);
            } else if (zH) {
                l1Var = new k1(unsafeI, c6 == true ? 1 : 0);
            } else if (zH2) {
                l1Var = new k1(unsafeI, i10);
            }
        }
        f2122c = l1Var;
        f2123d = l1Var == null ? false : l1Var.r();
        f2124e = l1Var == null ? false : l1Var.q();
        f2125f = 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 && l1Var != null) {
            l1Var.i(fieldG);
        }
        f2126g = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
    }

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

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

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

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

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

    public static void f(Class cls) {
        if (f2124e) {
            f2122c.b(cls);
        }
    }

    public static Field g() {
        Field declaredField;
        Field declaredField2;
        if (d.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 (!d.a()) {
            return false;
        }
        try {
            Class cls2 = f2121b;
            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 j1());
        } catch (Throwable unused) {
            return null;
        }
    }

    public static void j(byte[] bArr, long j10, byte b10) {
        f2122c.k(bArr, f2125f + j10, b10);
    }

    public static void k(Object obj, long j10, byte b10) {
        long j11 = (-4) & j10;
        int iF = f2122c.f(j11, obj);
        int i10 = ((~((int) j10)) & 3) << 3;
        m(((255 & b10) << i10) | (iF & (~(255 << i10))), j11, obj);
    }

    public static void l(Object obj, long j10, byte b10) {
        long j11 = (-4) & j10;
        int i10 = (((int) j10) & 3) << 3;
        m(((255 & b10) << i10) | (f2122c.f(j11, obj) & (~(255 << i10))), j11, obj);
    }

    public static void m(int i10, long j10, Object obj) {
        f2122c.n(i10, j10, obj);
    }

    public static void n(Object obj, long j10, long j11) {
        f2122c.o(obj, j10, j11);
    }

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