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;

/* JADX INFO: renamed from: ᵰˊˌ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4363 extends AbstractC0824 {

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public long f16578;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public boolean f16579;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public RandomAccessFile f16580;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public Uri f16581;

    @Override // defpackage.InterfaceC1070
    public final void close() {
        this.f16581 = null;
        try {
            try {
                RandomAccessFile randomAccessFile = this.f16580;
                if (randomAccessFile != null) {
                    randomAccessFile.close();
                }
            } catch (IOException e) {
                throw new FileDataSource$FileDataSourceException(2000, e);
            }
        } finally {
            this.f16580 = null;
            if (this.f16579) {
                this.f16579 = false;
                m2945();
            }
        }
    }

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

    @Override // defpackage.InterfaceC1070
    /* JADX INFO: renamed from: ᵯᵷʽ */
    public final Uri mo1307() {
        return this.f16581;
    }

    @Override // defpackage.InterfaceC1070
    /* JADX INFO: renamed from: ᵵᵽ */
    public final long mo1308(C0084 c0084) throws FileDataSource$FileDataSourceException {
        Uri uri = c0084.f1291;
        long j = c0084.f1290;
        this.f16581 = uri;
        m2948();
        try {
            String path = uri.getPath();
            path.getClass();
            RandomAccessFile randomAccessFile = new RandomAccessFile(path, "r");
            this.f16580 = randomAccessFile;
            try {
                randomAccessFile.seek(j);
                long length = c0084.f1294;
                if (length == -1) {
                    length = this.f16580.length() - j;
                }
                this.f16578 = length;
                if (length < 0) {
                    throw new FileDataSource$FileDataSourceException(null, null, 2008);
                }
                this.f16579 = true;
                m2947(c0084);
                return this.f16578;
            } 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 sbM8226 = AbstractC3653.m8226("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=");
            sbM8226.append(fragment);
            throw new FileDataSource$FileDataSourceException(sbM8226.toString(), e2, 1004);
        } catch (SecurityException e3) {
            throw new FileDataSource$FileDataSourceException(2006, e3);
        } catch (RuntimeException e4) {
            throw new FileDataSource$FileDataSourceException(2000, e4);
        }
    }
}
