package a2;

import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.HashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/* JADX INFO: renamed from: a2.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0397a {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final HashMap f7592e = new HashMap();

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final boolean f7593a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final File f7594b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Lock f7595c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public FileChannel f7596d;

    public C0397a(String str, File file, boolean z8) {
        Lock lock;
        this.f7593a = z8;
        this.f7594b = file != null ? new File(file, str.concat(".lck")) : null;
        HashMap map = f7592e;
        synchronized (map) {
            try {
                Object reentrantLock = map.get(str);
                if (reentrantLock == null) {
                    reentrantLock = new ReentrantLock();
                    map.put(str, reentrantLock);
                }
                lock = (Lock) reentrantLock;
            } catch (Throwable th) {
                throw th;
            }
        }
        this.f7595c = lock;
    }

    public final void a(boolean z8) {
        this.f7595c.lock();
        if (z8) {
            File file = this.f7594b;
            try {
                if (file == null) {
                    throw new IOException("No lock directory was provided.");
                }
                File parentFile = file.getParentFile();
                if (parentFile != null) {
                    parentFile.mkdirs();
                }
                FileChannel channel = new FileOutputStream(file).getChannel();
                channel.lock();
                this.f7596d = channel;
            } catch (IOException e8) {
                this.f7596d = null;
                Log.w("SupportSQLiteLock", "Unable to grab file lock.", e8);
            }
        }
    }

    public final void b() {
        try {
            FileChannel fileChannel = this.f7596d;
            if (fileChannel != null) {
                fileChannel.close();
            }
        } catch (IOException unused) {
        }
        this.f7595c.unlock();
    }
}
