package defpackage;

import android.net.Uri;
import android.system.ErrnoException;
import android.system.OsConstants;
import android.text.TextUtils;
import androidx.media3.datasource.FileDataSource$FileDataSourceException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/* renamed from: ʽˁˇ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C0087 extends AbstractC1628 {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public long f1335;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public boolean f1336;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public Uri f1337;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public RandomAccessFile f1338;

    @Override // defpackage.InterfaceC2569
    public final void close() {
        this.f1337 = null;
        try {
            try {
                RandomAccessFile randomAccessFile = this.f1338;
                if (randomAccessFile != null) {
                    randomAccessFile.close();
                }
            } catch (IOException e) {
                throw new FileDataSource$FileDataSourceException(2000, e);
            }
        } finally {
            this.f1338 = null;
            if (this.f1336) {
                this.f1336 = false;
                m4667();
            }
        }
    }

    @Override // defpackage.InterfaceC1463
    public final int read(byte[] bArr, int i, int i2) throws IOException {
        if (i2 == 0) {
            return 0;
        }
        long j = this.f1335;
        if (j == 0) {
            return -1;
        }
        try {
            RandomAccessFile randomAccessFile = this.f1338;
            String str = AbstractC3558.f13329;
            int i3 = randomAccessFile.read(bArr, i, (int) Math.min(j, i2));
            if (i3 > 0) {
                this.f1335 -= i3;
                m4668(i3);
            }
            return i3;
        } catch (IOException e) {
            throw new FileDataSource$FileDataSourceException(2000, e);
        }
    }

    @Override // defpackage.InterfaceC2569
    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final long mo1165(C4179 c4179) throws IOException {
        Uri uri = c4179.f15620;
        long j = c4179.f15616;
        this.f1337 = uri;
        m4666();
        try {
            String path = uri.getPath();
            path.getClass();
            RandomAccessFile randomAccessFile = new RandomAccessFile(path, "r");
            this.f1338 = randomAccessFile;
            try {
                randomAccessFile.seek(j);
                long length = c4179.f15618;
                if (length == -1) {
                    length = this.f1338.length() - j;
                }
                this.f1335 = length;
                if (length < 0) {
                    throw new FileDataSource$FileDataSourceException(null, null, 2008);
                }
                this.f1336 = true;
                m4669(c4179);
                return this.f1335;
            } catch (IOException e) {
                throw new FileDataSource$FileDataSourceException(2000, e);
            }
        } catch (FileNotFoundException e2) {
            if (TextUtils.isEmpty(uri.getQuery()) && TextUtils.isEmpty(uri.getFragment())) {
                throw new FileDataSource$FileDataSourceException(((e2.getCause() instanceof ErrnoException) && ((ErrnoException) e2.getCause()).errno == OsConstants.EACCES) ? 2006 : 2005, e2);
            }
            String path2 = uri.getPath();
            String query = uri.getQuery();
            String fragment = uri.getFragment();
            StringBuilder sbM4104 = AbstractC1327.m4104("uri has query and/or fragment, which are not supported. Did you call Uri.parse() on a string containing '?' or '#'? Use Uri.fromFile(new File(path)) to avoid this. path=", path2, ",query=", query, ",fragment=");
            sbM4104.append(fragment);
            throw new FileDataSource$FileDataSourceException(sbM4104.toString(), e2, 1004);
        } catch (SecurityException e3) {
            throw new FileDataSource$FileDataSourceException(2006, e3);
        } catch (RuntimeException e4) {
            throw new FileDataSource$FileDataSourceException(2000, e4);
        }
    }

    @Override // defpackage.InterfaceC2569
    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final Uri mo1166() {
        return this.f1337;
    }
}
