package androidx.recyclerview.widget;

import android.content.Context;
import com.bytedance.sdk.component.ro.fm.fhx;
import com.bytedance.sdk.component.ro.fm.lb;
import com.bytedance.sdk.component.ro.fm.onz;
import com.bytedance.sdk.component.ro.fm.ro;
import com.google.android.datatransport.runtime.firebase.transport.LogEventDropped$Reason;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import xyz.stream.utils.glide.UnsafeOkHttpGlideModule;

/* JADX INFO: loaded from: classes.dex */
public final class d implements lb, w8.e, d5.a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f3687a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public long f3688b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Object f3689c;

    public /* synthetic */ d(Object obj, long j10, int i10) {
        this.f3687a = i10;
        this.f3689c = obj;
        this.f3688b = j10;
    }

    public final void a(int i10) {
        if (i10 < 64) {
            this.f3688b &= ~(1 << i10);
            return;
        }
        Object obj = this.f3689c;
        if (((d) obj) != null) {
            ((d) obj).a(i10 - 64);
        }
    }

    public final int b(int i10) {
        Object obj = this.f3689c;
        if (((d) obj) == null) {
            return i10 >= 64 ? Long.bitCount(this.f3688b) : Long.bitCount(this.f3688b & ((1 << i10) - 1));
        }
        if (i10 < 64) {
            return Long.bitCount(this.f3688b & ((1 << i10) - 1));
        }
        return Long.bitCount(this.f3688b) + ((d) obj).b(i10 - 64);
    }

    @Override // d5.a
    public final d5.c build() {
        File file = new File(((Context) this.f3689c).getCacheDir(), "image_manager_disk_cache");
        UnsafeOkHttpGlideModule.G(this.f3688b);
        file.getAbsolutePath();
        long j10 = this.f3688b;
        x4.d dVar = new x4.d();
        dVar.f34724e = new xyz.stream.utils.f(7);
        dVar.f34723d = file;
        dVar.f34720a = j10;
        dVar.f34722c = new com.google.android.gms.internal.atv_ads_framework.d1(7);
        return new com.google.android.gms.measurement.internal.n(dVar, file, this.f3688b);
    }

    public final void c() {
        if (((d) this.f3689c) == null) {
            this.f3689c = new d(0);
        }
    }

    public final boolean d(int i10) {
        if (i10 < 64) {
            return (this.f3688b & (1 << i10)) != 0;
        }
        c();
        return ((d) this.f3689c).d(i10 - 64);
    }

    public final void e(int i10, boolean z10) {
        if (i10 >= 64) {
            c();
            ((d) this.f3689c).e(i10 - 64, z10);
            return;
        }
        long j10 = this.f3688b;
        boolean z11 = (Long.MIN_VALUE & j10) != 0;
        long j11 = (1 << i10) - 1;
        this.f3688b = ((j10 & (~j11)) << 1) | (j10 & j11);
        if (z10) {
            h(i10);
        } else {
            a(i10);
        }
        if (z11 || ((d) this.f3689c) != null) {
            c();
            ((d) this.f3689c).e(0, z11);
        }
    }

    public final boolean f(int i10) {
        if (i10 >= 64) {
            c();
            return ((d) this.f3689c).f(i10 - 64);
        }
        long j10 = 1 << i10;
        long j11 = this.f3688b;
        boolean z10 = (j11 & j10) != 0;
        long j12 = j11 & (~j10);
        this.f3688b = j12;
        long j13 = j10 - 1;
        this.f3688b = (j12 & j13) | Long.rotateRight((~j13) & j12, 1);
        Object obj = this.f3689c;
        if (((d) obj) != null) {
            if (((d) obj).d(0)) {
                h(63);
            }
            ((d) this.f3689c).f(0);
        }
        return z10;
    }

    @Override // com.bytedance.sdk.component.ro.fm.lb
    public final void fm(ro roVar, IOException iOException) {
        Object obj = this.f3689c;
        f6.b.b((f6.b) obj, ((f6.b) obj).f25945b, 601, iOException.getMessage());
        f6.a.a(((f6.b) this.f3689c).f25945b);
    }

    public final void g() {
        this.f3688b = 0L;
        Object obj = this.f3689c;
        if (((d) obj) != null) {
            ((d) obj).g();
        }
    }

    public final void h(int i10) {
        if (i10 < 64) {
            this.f3688b |= 1 << i10;
        } else {
            c();
            ((d) this.f3689c).h(i10 - 64);
        }
    }

    @Override // w8.e
    public final void onFailure(Exception exc) {
        com.google.android.gms.measurement.internal.o0 o0Var = (com.google.android.gms.measurement.internal.o0) this.f3689c;
        o0Var.f21806c.set(this.f3688b);
    }

    public final String toString() {
        switch (this.f3687a) {
            case 0:
                if (((d) this.f3689c) == null) {
                    return Long.toBinaryString(this.f3688b);
                }
                return ((d) this.f3689c).toString() + "xx" + Long.toBinaryString(this.f3688b);
            default:
                return super.toString();
        }
    }

    public d(i8.c cVar) {
        this.f3687a = 4;
        com.google.android.gms.common.internal.w.checkNotNull(cVar);
        this.f3689c = cVar;
    }

    public d(Context context, long j10) {
        this.f3687a = 5;
        this.f3689c = context.getApplicationContext();
        this.f3688b = j10;
    }

    /* JADX WARN: Code restructure failed: missing block: B:34:0x00fa, code lost:
    
        r0 = r20.f3689c;
        r3 = (f6.b) r0;
        r0 = ((f6.b) r0).f25945b;
        r4 = r22.lb();
        r3.getClass();
     */
    /* JADX WARN: Code restructure failed: missing block: B:35:0x010c, code lost:
    
        monitor-enter(y5.a.class);
     */
    /* JADX WARN: Code restructure failed: missing block: B:36:0x010d, code lost:
    
        r3 = r3.f25949f.iterator();
     */
    /* JADX WARN: Code restructure failed: missing block: B:38:0x0117, code lost:
    
        if (r3.hasNext() == false) goto L123;
     */
    /* JADX WARN: Code restructure failed: missing block: B:39:0x0119, code lost:
    
        r6 = (y5.a) r3.next();
     */
    /* JADX WARN: Code restructure failed: missing block: B:40:0x011f, code lost:
    
        if (r6 == null) goto L126;
     */
    /* JADX WARN: Code restructure failed: missing block: B:41:0x0121, code lost:
    
        r6.ro(r0, r4);
     */
    /* JADX WARN: Code restructure failed: missing block: B:42:0x0125, code lost:
    
        r0 = move-exception;
     */
    /* JADX WARN: Code restructure failed: missing block: B:44:0x0127, code lost:
    
        monitor-exit(y5.a.class);
     */
    /* JADX WARN: Code restructure failed: missing block: B:45:0x0128, code lost:
    
        f6.b.c((f6.b) r20.f3689c, r13);
        f6.b.c((f6.b) r20.f3689c, r10);
        f6.b.c((f6.b) r20.f3689c, r7);
        f6.b.c((f6.b) r20.f3689c, r22);
        ((f6.b) r20.f3689c).f25945b.irt();
        ((f6.b) r20.f3689c).f25945b.ajl();
        f6.a.a(((f6.b) r20.f3689c).f25945b);
     */
    /* JADX WARN: Code restructure failed: missing block: B:46:0x015f, code lost:
    
        return;
     */
    /* JADX WARN: Code restructure failed: missing block: B:48:0x0161, code lost:
    
        throw r0;
     */
    /* JADX WARN: Removed duplicated region for block: B:86:0x023f A[Catch: all -> 0x0244, TryCatch #3 {all -> 0x0244, blocks: (B:82:0x0223, B:84:0x0234, B:86:0x023f, B:89:0x0246), top: B:100:0x0223 }] */
    @Override // com.bytedance.sdk.component.ro.fm.lb
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void fm(ro roVar, onz onzVar) {
        int iLb;
        InputStream inputStreamLb;
        RandomAccessFile randomAccessFile;
        fhx fhxVarAjl;
        long jFm;
        int i10;
        long j10 = this.f3688b;
        Closeable closeable = null;
        if (onzVar != null) {
            try {
                boolean zYz = onzVar.yz();
                if (!zYz) {
                    Object obj = this.f3689c;
                    f6.b.b((f6.b) obj, ((f6.b) obj).f25945b, onzVar.lb(), onzVar.jnr());
                    f6.b.c((f6.b) this.f3689c, null);
                    f6.b.c((f6.b) this.f3689c, null);
                    f6.b.c((f6.b) this.f3689c, null);
                    f6.b.c((f6.b) this.f3689c, onzVar);
                    ((f6.b) this.f3689c).f25945b.irt();
                    ((f6.b) this.f3689c).f25945b.ajl();
                    f6.a.a(((f6.b) this.f3689c).f25945b);
                    return;
                }
                fhxVarAjl = onzVar.ajl();
                try {
                    fhxVarAjl = onzVar.ajl();
                    if (!zYz || fhxVarAjl == null) {
                        inputStreamLb = null;
                        jFm = 0;
                    } else {
                        jFm = this.f3688b + fhxVarAjl.fm();
                        inputStreamLb = fhxVarAjl.lb();
                    }
                    try {
                        if (inputStreamLb == null) {
                            Object obj2 = this.f3689c;
                            f6.b.b((f6.b) obj2, ((f6.b) obj2).f25945b, onzVar.lb(), onzVar.jnr());
                            f6.b.c((f6.b) this.f3689c, null);
                            f6.b.c((f6.b) this.f3689c, inputStreamLb);
                            f6.b.c((f6.b) this.f3689c, fhxVarAjl);
                            f6.b.c((f6.b) this.f3689c, onzVar);
                            ((f6.b) this.f3689c).f25945b.irt();
                            ((f6.b) this.f3689c).f25945b.ajl();
                            f6.a.a(((f6.b) this.f3689c).f25945b);
                            return;
                        }
                        randomAccessFile = new RandomAccessFile(((f6.b) this.f3689c).f25947d, "rw");
                        try {
                            int i11 = o6.b.f31433j;
                            byte[] bArr = new byte[i11];
                            int i12 = 0;
                            long j11 = 0;
                            while (true) {
                                int i13 = inputStreamLb.read(bArr, i12, i11 - i12);
                                if (i13 != -1) {
                                    if (((f6.b) this.f3689c).f25946c) {
                                        break;
                                    }
                                    i12 += i13;
                                    j11 += (long) i13;
                                    if (j11 % ((long) i11) == 0 || j11 == jFm - this.f3688b) {
                                        int iIntValue = Long.valueOf(j10).intValue();
                                        ((f6.b) this.f3689c).f25945b.qhl();
                                        try {
                                            randomAccessFile.seek(iIntValue);
                                            i10 = 0;
                                            try {
                                                randomAccessFile.write(bArr, 0, i12);
                                            } catch (Throwable unused) {
                                            }
                                        } catch (Throwable unused2) {
                                            i10 = 0;
                                        }
                                        j10 += (long) i12;
                                        i12 = i10;
                                    }
                                } else {
                                    if (((f6.b) this.f3689c).f25945b.dsz() && jFm == ((f6.b) this.f3689c).f25947d.length()) {
                                        f6.b.e((f6.b) this.f3689c);
                                    }
                                    Object obj3 = this.f3689c;
                                    ((f6.b) obj3).a(((f6.b) obj3).f25945b, onzVar.lb());
                                    closeable = randomAccessFile;
                                }
                            }
                        } catch (Throwable th) {
                            th = th;
                            closeable = fhxVarAjl;
                            iLb = 601;
                            try {
                                f6.b bVar = (f6.b) this.f3689c;
                                bVar.getClass();
                                try {
                                    bVar.f25948e.delete();
                                    bVar.f25947d.delete();
                                } catch (Throwable unused3) {
                                }
                                Object obj4 = this.f3689c;
                                f6.b bVar2 = (f6.b) obj4;
                                com.bykv.vk.openvk.fm.fm.fm.lb.lb lbVar = ((f6.b) obj4).f25945b;
                                if (onzVar != null) {
                                    iLb = onzVar.lb();
                                }
                                f6.b.b(bVar2, lbVar, iLb, th.getMessage());
                                f6.b.c((f6.b) this.f3689c, randomAccessFile);
                                f6.b.c((f6.b) this.f3689c, inputStreamLb);
                                f6.b.c((f6.b) this.f3689c, closeable);
                                f6.b.c((f6.b) this.f3689c, onzVar);
                                ((f6.b) this.f3689c).f25945b.irt();
                                ((f6.b) this.f3689c).f25945b.ajl();
                                f6.a.a(((f6.b) this.f3689c).f25945b);
                            } catch (Throwable th2) {
                                f6.b.c((f6.b) this.f3689c, randomAccessFile);
                                f6.b.c((f6.b) this.f3689c, inputStreamLb);
                                f6.b.c((f6.b) this.f3689c, closeable);
                                f6.b.c((f6.b) this.f3689c, onzVar);
                                ((f6.b) this.f3689c).f25945b.irt();
                                ((f6.b) this.f3689c).f25945b.ajl();
                                f6.a.a(((f6.b) this.f3689c).f25945b);
                                throw th2;
                            }
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        randomAccessFile = null;
                    }
                } catch (Throwable th4) {
                    th = th4;
                    inputStreamLb = null;
                    randomAccessFile = null;
                }
            } catch (Throwable th5) {
                th = th5;
                inputStreamLb = null;
                randomAccessFile = null;
            }
        } else {
            try {
                Object obj5 = this.f3689c;
                iLb = 601;
                try {
                    f6.b.b((f6.b) obj5, ((f6.b) obj5).f25945b, 601, "Network link failed.");
                    fhxVarAjl = null;
                    inputStreamLb = null;
                    f6.b.c((f6.b) this.f3689c, closeable);
                    f6.b.c((f6.b) this.f3689c, inputStreamLb);
                    f6.b.c((f6.b) this.f3689c, fhxVarAjl);
                    f6.b.c((f6.b) this.f3689c, onzVar);
                    ((f6.b) this.f3689c).f25945b.irt();
                    ((f6.b) this.f3689c).f25945b.ajl();
                    f6.a.a(((f6.b) this.f3689c).f25945b);
                } catch (Throwable th6) {
                    th = th6;
                    inputStreamLb = null;
                    randomAccessFile = null;
                    f6.b bVar3 = (f6.b) this.f3689c;
                    bVar3.getClass();
                    bVar3.f25948e.delete();
                    bVar3.f25947d.delete();
                    Object obj42 = this.f3689c;
                    f6.b bVar22 = (f6.b) obj42;
                    com.bykv.vk.openvk.fm.fm.fm.lb.lb lbVar2 = ((f6.b) obj42).f25945b;
                    if (onzVar != null) {
                    }
                    f6.b.b(bVar22, lbVar2, iLb, th.getMessage());
                    f6.b.c((f6.b) this.f3689c, randomAccessFile);
                    f6.b.c((f6.b) this.f3689c, inputStreamLb);
                    f6.b.c((f6.b) this.f3689c, closeable);
                    f6.b.c((f6.b) this.f3689c, onzVar);
                    ((f6.b) this.f3689c).f25945b.irt();
                    ((f6.b) this.f3689c).f25945b.ajl();
                    f6.a.a(((f6.b) this.f3689c).f25945b);
                }
            } catch (Throwable th7) {
                th = th7;
                iLb = 601;
            }
        }
    }

    public d(int i10) {
        this.f3687a = i10;
        if (i10 != 2) {
            this.f3688b = 0L;
        } else {
            this.f3688b = 0L;
            this.f3689c = LogEventDropped$Reason.REASON_UNKNOWN;
        }
    }
}
