package defpackage;

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;

/* renamed from: ˏٴᵸ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1855 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public static final HashMap f7535 = new HashMap();

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final Lock f7536;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final boolean f7537;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final File f7538;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public FileChannel f7539;

    public C1855(String str, File file, boolean z) {
        Lock lock;
        this.f7537 = z;
        this.f7538 = file != null ? new File(file, str.concat(".lck")) : null;
        HashMap map = f7535;
        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.f7536 = lock;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m5251(boolean z) throws IOException {
        this.f7536.lock();
        if (z) {
            File file = this.f7538;
            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.f7539 = channel;
            } catch (IOException unused) {
                this.f7539 = null;
            }
        }
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final void m5252() throws IOException {
        try {
            FileChannel fileChannel = this.f7539;
            if (fileChannel != null) {
                fileChannel.close();
            }
        } catch (IOException unused) {
        }
        this.f7536.unlock();
    }
}
