package o;

import android.os.ParcelFileDescriptor;
import androidx.datastore.core.NativeSharedCounter;
import java.io.File;
import java.io.IOException;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.wQ, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2806wQ extends AbstractC0706aK implements NC {
    public final /* synthetic */ int m;
    public final /* synthetic */ C3091zQ n;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ C2806wQ(C3091zQ c3091zQ, int i) {
        super(0);
        this.m = i;
        this.n = c3091zQ;
    }

    @Override // o.NC
    public final Object a() throws Throwable {
        ParcelFileDescriptor parcelFileDescriptorOpen;
        switch (this.m) {
            case 0:
                System.loadLibrary("datastore_shared_counter");
                C3091zQ c3091zQ = this.n;
                File file = new File(c3091zQ.b.getAbsolutePath() + c3091zQ.e);
                C3091zQ.f(c3091zQ, file);
                try {
                    parcelFileDescriptorOpen = ParcelFileDescriptor.open(file, 939524096);
                    try {
                        int fd = parcelFileDescriptorOpen.getFd();
                        NativeSharedCounter nativeSharedCounter = C0980d80.b;
                        if (nativeSharedCounter.nativeTruncateFile(fd) != 0) {
                            throw new IOException("Failed to truncate counter file");
                        }
                        long jNativeCreateSharedCounter = nativeSharedCounter.nativeCreateSharedCounter(fd);
                        if (jNativeCreateSharedCounter < 0) {
                            throw new IOException("Failed to mmap counter file");
                        }
                        C0980d80 c0980d80 = new C0980d80(jNativeCreateSharedCounter);
                        parcelFileDescriptorOpen.close();
                        return c0980d80;
                    } catch (Throwable th) {
                        th = th;
                        if (parcelFileDescriptorOpen != null) {
                            parcelFileDescriptorOpen.close();
                        }
                        throw th;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    parcelFileDescriptorOpen = null;
                }
            default:
                C3091zQ c3091zQ2 = this.n;
                File file2 = new File(c3091zQ2.b.getAbsolutePath() + c3091zQ2.d);
                C3091zQ.f(c3091zQ2, file2);
                return file2;
        }
    }
}
