aw.java 源代码


package com.inmobi.media;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.webkit.URLUtil;
import androidx.annotation.NonNull;
import com.anythink.core.api.ATAdConst;
import com.anythink.expressad.foundation.d.b;
import com.inmobi.media.al;
import com.inmobi.media.fd;
import com.inmobi.media.ff;
import com.inmobi.media.hj;
import com.squareup.picasso.Callback;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;

public final class aw implements ff.c {

    private static final String f14737b = "aw";

    private static final Object f14738m = new Object();

    public ExecutorService f14739a;

    private au f14740c;

    private fd.a f14741d;

    private fd.k f14742e;

    private ExecutorService f14743f;

    private a f14744g;

    private HandlerThread f14745h;

    private AtomicBoolean f14746i;

    private AtomicBoolean f14747j;

    private ConcurrentHashMap<String, al> f14748k;

    private hj.c f14749l;

    private List<am> f14750n;

    private final av f14751o;

    public static final class a extends Handler {

        private WeakReference<aw> f14761a;

        private final av f14762b;

        a(@NonNull Looper looper, @NonNull aw awVar) {
            super(looper);
            this.f14761a = new WeakReference<>(awVar);
            this.f14762b = new av() {
                @Override
                public final void a(gm gmVar, String str, al alVar) {
                    aw awVar2 = (aw) a.this.f14761a.get();
                    if (awVar2 != null) {
                        String unused = aw.f14737b;
                        al a7 = new al.a().a(alVar.f14667d, str, gmVar, awVar2.f14741d.maxRetries, awVar2.f14741d.timeToLive).a();
                        au unused2 = awVar2.f14740c;
                        au.b(a7);
                        a7.f14674k = alVar.f14674k;
                        a7.f14664a = alVar.f14664a;
                        awVar2.a(a7, (byte) 0);
                        a.this.a();
                        return;
                    }
                    String unused3 = aw.f14737b;
                }

                @Override
                public final void a(al alVar) {
                    aw awVar2 = (aw) a.this.f14761a.get();
                    if (awVar2 != null) {
                        String unused = aw.f14737b;
                        awVar2.c(alVar.f14667d);
                        int i6 = alVar.f14666c;
                        if (i6 <= 0) {
                            awVar2.a(alVar, alVar.f14675l);
                            a.this.a(alVar);
                            return;
                        }
                        alVar.f14666c = i6 - 1;
                        alVar.f14669f = System.currentTimeMillis();
                        au unused2 = awVar2.f14740c;
                        au.b(alVar);
                        a.this.b();
                        return;
                    }
                    String unused3 = aw.f14737b;
                }
            };
        }

        @Override
        public final void handleMessage(Message message) {
            try {
                aw awVar = this.f14761a.get();
                int i6 = message.what;
                if (i6 != 1) {
                    if (i6 != 2) {
                        if (i6 != 3) {
                            if (i6 != 4) {
                                return;
                            }
                            if (awVar != null) {
                                al alVar = (al) message.obj;
                                au unused = awVar.f14740c;
                                au.c(alVar);
                            }
                            b();
                            return;
                        }
                        b();
                        return;
                    }
                    if (awVar != null) {
                        String str = (String) message.obj;
                        au unused2 = awVar.f14740c;
                        al b6 = au.b(str);
                        if (b6 == null) {
                            b();
                            return;
                        }
                        if (b6.a()) {
                            String unused3 = aw.f14737b;
                            a();
                            awVar.a(b6, (byte) 0);
                            return;
                        }
                        fd.a unused4 = awVar.f14741d;
                        if (b6.f14666c == 0) {
                            b6.f14675l = (byte) 6;
                            awVar.a(b6, (byte) 6);
                            a(b6);
                            return;
                        } else if (!hf.a()) {
                            awVar.a(b6, b6.f14675l);
                            awVar.i();
                            return;
                        } else if (awVar.a(b6, this.f14762b)) {
                            String unused5 = aw.f14737b;
                            String unused6 = aw.f14737b;
                            return;
                        } else {
                            String unused7 = aw.f14737b;
                            b();
                            return;
                        }
                    }
                    return;
                }
                if (awVar != null) {
                    fd.a aVar = awVar.f14741d;
                    if (aVar == null) {
                        aVar = ((fd) ff.a("ads", gy.f(), null)).assetCache;
                    }
                    au unused8 = awVar.f14740c;
                    List<al> c6 = au.c();
                    if (c6.size() <= 0) {
                        String unused9 = aw.f14737b;
                        awVar.i();
                        return;
                    }
                    String unused10 = aw.f14737b;
                    al alVar2 = c6.get(0);
                    Iterator<al> it = c6.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            break;
                        }
                        al next = it.next();
                        if (!aw.b(awVar, alVar2)) {
                            alVar2 = next;
                            break;
                        }
                    }
                    Message obtain = Message.obtain();
                    obtain.what = 1;
                    long currentTimeMillis = System.currentTimeMillis() - alVar2.f14669f;
                    try {
                        int i7 = aVar.retryInterval;
                        if (currentTimeMillis < i7 * 1000) {
                            sendMessageDelayed(obtain, (i7 * 1000) - currentTimeMillis);
                            return;
                        }
                        if (!aw.b(awVar, alVar2)) {
                            String unused11 = aw.f14737b;
                            Message obtain2 = Message.obtain();
                            obtain2.what = 2;
                            obtain2.obj = alVar2.f14667d;
                            sendMessage(obtain2);
                            return;
                        }
                        sendMessageDelayed(obtain, aVar.retryInterval * 1000);
                    } catch (Exception unused12) {
                        String unused13 = aw.f14737b;
                    }
                }
            } catch (Exception e6) {
                String unused14 = aw.f14737b;
                fu.a().a(new gu(e6));
            }
        }

        public void b() {
            try {
                sendEmptyMessage(1);
            } catch (Exception unused) {
                String unused2 = aw.f14737b;
            }
        }

        public void a(al alVar) {
            try {
                Message obtain = Message.obtain();
                obtain.what = 4;
                obtain.obj = alVar;
                sendMessage(obtain);
            } catch (Exception unused) {
                String unused2 = aw.f14737b;
            }
        }

        public void a() {
            try {
                sendEmptyMessage(3);
            } catch (Exception unused) {
                String unused2 = aw.f14737b;
            }
        }
    }

    public static class b {

        static final aw f14764a = new aw(0);
    }

    public class c implements InvocationHandler {

        private CountDownLatch f14766b;

        private String f14767c;

        private long f14768d;

        private String f14769e;

        c(CountDownLatch countDownLatch, String str, long j6, String str2) {
            this.f14766b = countDownLatch;
            this.f14767c = str;
            this.f14768d = j6;
            this.f14769e = str2;
        }

        @Override
        public final Object invoke(Object obj, Method method, Object[] objArr) {
            String unused = aw.f14737b;
            if (method != null) {
                if ("onSuccess".equalsIgnoreCase(method.getName())) {
                    HashMap hashMap = new HashMap();
                    hashMap.put(com.umeng.analytics.pro.ai.aQ, Long.valueOf(SystemClock.elapsedRealtime() - this.f14768d));
                    hashMap.put(ATAdConst.NETWORK_REQUEST_PARAMS_KEY.BANNER_SIZE, 0);
                    hashMap.put("assetType", b.c.f3477e);
                    hashMap.put("networkType", hm.b());
                    hashMap.put("adType", this.f14769e);
                    gv.a().a("AssetDownloaded", hashMap);
                    aw.this.a(this.f14767c);
                    this.f14766b.countDown();
                    return null;
                }
                if ("onError".equalsIgnoreCase(method.getName())) {
                    aw.this.b(this.f14767c);
                    this.f14766b.countDown();
                    return null;
                }
                return null;
            }
            return null;
        }
    }

    aw(byte b6) {
        this();
    }

    @TargetApi(23)
    private void h() {
        hj.a().a("android.net.conn.CONNECTIVITY_CHANGE", this.f14749l);
        if (Build.VERSION.SDK_INT >= 23) {
            hj.a().a(this.f14749l);
        }
    }

    public void i() {
        synchronized (f14738m) {
            this.f14746i.set(false);
            this.f14748k.clear();
            HandlerThread handlerThread = this.f14745h;
            if (handlerThread != null) {
                handlerThread.getLooper().quit();
                this.f14745h.interrupt();
                this.f14745h = null;
                this.f14744g = null;
            }
        }
    }

    private aw() {
        this.f14746i = new AtomicBoolean(false);
        this.f14747j = new AtomicBoolean(false);
        this.f14750n = new ArrayList();
        this.f14751o = new av() {
            @Override
            public final void a(@NonNull gm gmVar, @NonNull String str, @NonNull al alVar) {
                String unused = aw.f14737b;
                al a7 = new al.a().a(alVar.f14667d, str, gmVar, aw.this.f14741d.maxRetries, aw.this.f14741d.timeToLive).a();
                au unused2 = aw.this.f14740c;
                au.b(a7);
                a7.f14674k = alVar.f14674k;
                a7.f14664a = alVar.f14664a;
                aw.this.a(a7, (byte) 0);
                try {
                    aw.c(aw.this);
                } catch (Exception e6) {
                    String unused3 = aw.f14737b;
                    fu.a().a(new gu(e6));
                }
            }

            @Override
            public final void a(@NonNull al alVar) {
                String unused = aw.f14737b;
                aw.this.c(alVar.f14667d);
                if (alVar.f14666c <= 0) {
                    String unused2 = aw.f14737b;
                    aw.this.a(alVar, alVar.f14675l);
                    au unused3 = aw.this.f14740c;
                    au.c(alVar);
                } else {
                    String unused4 = aw.f14737b;
                    alVar.f14669f = System.currentTimeMillis();
                    au unused5 = aw.this.f14740c;
                    au.b(alVar);
                    if (!hf.a()) {
                        aw.this.a(alVar, alVar.f14675l);
                    }
                }
                try {
                    aw.c(aw.this);
                } catch (Exception e6) {
                    String unused6 = aw.f14737b;
                    fu.a().a(new gu(e6));
                }
            }
        };
        fd fdVar = (fd) ff.a("ads", gy.f(), this);
        this.f14741d = fdVar.assetCache;
        this.f14742e = fdVar.vastVideo;
        this.f14740c = au.a();
        StringBuilder sb = new StringBuilder();
        String str = f14737b;
        sb.append(str);
        sb.append("-AP");
        this.f14739a = Executors.newCachedThreadPool(new hd(sb.toString()));
        this.f14743f = Executors.newFixedThreadPool(1, new hd(str + "-AD"));
        HandlerThread handlerThread = new HandlerThread("assetFetcher");
        this.f14745h = handlerThread;
        handlerThread.start();
        this.f14744g = new a(this.f14745h.getLooper(), this);
        this.f14749l = new hj.c() {
            @Override
            public final void a(boolean z6) {
                if (!z6) {
                    aw.this.i();
                } else {
                    aw.c(aw.this);
                }
            }
        };
        this.f14748k = new ConcurrentHashMap<>(2, 0.9f, 2);
    }

    public synchronized void b(String str) {
        boolean z6;
        for (int i6 = 0; i6 < this.f14750n.size(); i6++) {
            am amVar = this.f14750n.get(i6);
            Iterator<bd> it = amVar.f14685b.iterator();
            while (true) {
                if (it.hasNext()) {
                    if (it.next().f14835b.equals(str)) {
                        z6 = true;
                        break;
                    }
                } else {
                    z6 = false;
                    break;
                }
            }
            if (z6) {
                amVar.f14688e++;
            }
        }
    }

    public void c(String str) {
        this.f14748k.remove(str);
    }

    public synchronized void f() {
        ArrayList arrayList = new ArrayList();
        for (int i6 = 0; i6 < this.f14750n.size(); i6++) {
            am amVar = this.f14750n.get(i6);
            if (amVar.f14687d == amVar.f14685b.size()) {
                try {
                    ax a7 = amVar.a();
                    if (a7 != null) {
                        a7.a(amVar);
                    }
                    arrayList.add(amVar);
                } catch (Exception e6) {
                    fu.a().a(new gu(e6));
                }
            }
        }
        a(arrayList);
    }

    @TargetApi(23)
    private void g() {
        hj.a();
        hj.a(this.f14749l, "android.net.conn.CONNECTIVITY_CHANGE");
        if (Build.VERSION.SDK_INT >= 23) {
            hj.a();
            hj.b(this.f14749l);
        }
    }

    public final void c() {
        this.f14747j.set(true);
        i();
    }

    public final void d() {
        File[] listFiles;
        boolean z6;
        al b6;
        synchronized (f14738m) {
            List<al> d6 = au.d();
            if (d6.isEmpty()) {
                return;
            }
            Iterator<al> it = d6.iterator();
            while (true) {
                boolean z7 = true;
                if (!it.hasNext()) {
                    break;
                }
                al next = it.next();
                if (System.currentTimeMillis() <= next.f14671h) {
                    z7 = false;
                }
                if (z7) {
                    b(next);
                }
            }
            while (true) {
                Iterator<al> it2 = au.d().iterator();
                long j6 = 0;
                while (it2.hasNext()) {
                    j6 += new File(it2.next().f14668e).length();
                }
                if (j6 <= this.f14741d.maxCacheSize || (b6 = au.b()) == null) {
                    break;
                } else {
                    b(b6);
                }
            }
            File b7 = gy.b(gy.c());
            if (b7.exists() && (listFiles = b7.listFiles()) != null) {
                for (File file : listFiles) {
                    Iterator<al> it3 = d6.iterator();
                    while (true) {
                        if (it3.hasNext()) {
                            if (file.getAbsolutePath().equals(it3.next().f14668e)) {
                                z6 = true;
                                break;
                            }
                        } else {
                            z6 = false;
                            break;
                        }
                    }
                    if (!z6) {
                        file.getAbsolutePath();
                        file.delete();
                    }
                }
            }
        }
    }

    public void c(al alVar) {
        File file = new File(alVar.f14668e);
        long min = Math.min(System.currentTimeMillis() + (alVar.f14671h - alVar.f14669f), System.currentTimeMillis() + (this.f14741d.timeToLive * 1000));
        al.a aVar = new al.a();
        String str = alVar.f14667d;
        String str2 = alVar.f14668e;
        int i6 = this.f14741d.maxRetries;
        long j6 = alVar.f14672i;
        aVar.f14678c = str;
        aVar.f14679d = str2;
        aVar.f14677b = i6;
        aVar.f14682g = min;
        aVar.f14683h = j6;
        al a7 = aVar.a();
        a7.f14669f = System.currentTimeMillis();
        au.b(a7);
        long j7 = alVar.f14669f;
        a7.f14674k = an.a(alVar, file, j7, j7);
        a7.f14673j = true;
        a(a7, (byte) 0);
    }

    public static aw a() {
        return b.f14764a;
    }

    @Override
    public final void a(fe feVar) {
        fd fdVar = (fd) feVar;
        this.f14741d = fdVar.assetCache;
        this.f14742e = fdVar.vastVideo;
    }

    public final void b() {
        this.f14747j.set(false);
        if (!hf.a()) {
            g();
            h();
            return;
        }
        synchronized (f14738m) {
            if (this.f14746i.compareAndSet(false, true)) {
                if (this.f14745h == null) {
                    HandlerThread handlerThread = new HandlerThread("assetFetcher");
                    this.f14745h = handlerThread;
                    handlerThread.start();
                }
                if (this.f14744g == null) {
                    this.f14744g = new a(this.f14745h.getLooper(), this);
                }
                if (au.c().isEmpty()) {
                    i();
                } else {
                    g();
                    h();
                    this.f14744g.sendEmptyMessage(1);
                }
            }
        }
    }

    public synchronized void a(String str) {
        boolean z6;
        for (int i6 = 0; i6 < this.f14750n.size(); i6++) {
            am amVar = this.f14750n.get(i6);
            Set<bd> set = amVar.f14685b;
            Set<String> set2 = amVar.f14686c;
            Iterator<bd> it = set.iterator();
            while (true) {
                if (it.hasNext()) {
                    if (it.next().f14835b.equals(str)) {
                        z6 = true;
                        break;
                    }
                } else {
                    z6 = false;
                    break;
                }
            }
            if (z6 && !set2.contains(str)) {
                amVar.f14686c.add(str);
                amVar.f14687d++;
            }
        }
    }

    private synchronized void a(al alVar) {
        boolean z6;
        for (int i6 = 0; i6 < this.f14750n.size(); i6++) {
            am amVar = this.f14750n.get(i6);
            Iterator<bd> it = amVar.f14685b.iterator();
            while (true) {
                if (it.hasNext()) {
                    if (it.next().f14835b.equals(alVar.f14667d)) {
                        z6 = true;
                        break;
                    }
                } else {
                    z6 = false;
                    break;
                }
            }
            if (z6 && !amVar.f14684a.contains(alVar)) {
                amVar.f14684a.add(alVar);
            }
        }
    }

    private static void b(al alVar) {
        au.c(alVar);
        File file = new File(alVar.f14668e);
        if (file.exists()) {
            file.delete();
        }
    }

    static void c(aw awVar) {
        if (awVar.f14747j.get()) {
            return;
        }
        awVar.b();
    }

    static void b(aw awVar, final String str) {
        al a7 = au.a(str);
        if (a7 != null && a7.a()) {
            awVar.c(a7);
            return;
        }
        al.a aVar = new al.a();
        fd.a aVar2 = awVar.f14741d;
        al a8 = aVar.a(str, aVar2.maxRetries, aVar2.timeToLive).a();
        if (au.a(str) == null) {
            awVar.f14740c.a(a8);
        }
        awVar.f14743f.execute(new Runnable() {
            @Override
            public final void run() {
                au unused = aw.this.f14740c;
                al a9 = au.a(str);
                if (a9 != null) {
                    if (a9.a()) {
                        aw.this.c(a9);
                        return;
                    }
                    aw awVar2 = aw.this;
                    if (awVar2.a(a9, awVar2.f14751o)) {
                        String unused2 = aw.f14737b;
                    } else {
                        String unused3 = aw.f14737b;
                    }
                }
            }
        });
    }

    public synchronized void a(am amVar) {
        if (!this.f14750n.contains(amVar)) {
            this.f14750n.add(amVar);
        }
    }

    private synchronized void a(List<am> list) {
        int size = list.size();
        for (int i6 = 0; i6 < size; i6++) {
            this.f14750n.remove(list.get(i6));
        }
    }

    public boolean a(al alVar, av avVar) {
        an anVar;
        InputStream inputStream;
        byte b6;
        byte b7;
        byte b8;
        byte b9;
        byte b10;
        long elapsedRealtime;
        boolean z6;
        InputStream inputStream2;
        BufferedOutputStream bufferedOutputStream;
        BufferedOutputStream bufferedOutputStream2;
        long j6;
        if (this.f14748k.putIfAbsent(alVar.f14667d, alVar) != null) {
            return false;
        }
        anVar = new an(avVar);
        fd.k kVar = this.f14742e;
        long j7 = kVar.vastMaxAssetSize;
        List<String> list = kVar.allowedContentType;
        if (!hf.a()) {
            alVar.f14675l = (byte) 5;
            anVar.f14695a.a(alVar);
        } else if (!alVar.f14667d.equals("") && URLUtil.isValidUrl(alVar.f14667d)) {
            String[] strArr = (String[]) list.toArray(new String[list.size()]);
            BufferedOutputStream bufferedOutputStream3 = null;
            try {
                try {
                    try {
                        elapsedRealtime = SystemClock.elapsedRealtime();
                        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(alVar.f14667d).openConnection();
                        httpURLConnection.setRequestMethod("GET");
                        httpURLConnection.setConnectTimeout(com.anythink.expressad.foundation.f.a.S);
                        httpURLConnection.setReadTimeout(com.anythink.expressad.foundation.f.a.S);
                        if (httpURLConnection.getResponseCode() < 400) {
                            try {
                                String contentType = httpURLConnection.getContentType();
                                int length = strArr.length;
                                int i6 = 0;
                                while (true) {
                                    if (i6 >= length) {
                                        z6 = false;
                                        break;
                                    }
                                    String str = strArr[i6];
                                    if (contentType != null) {
                                        Locale locale = Locale.ENGLISH;
                                        if (str.toLowerCase(locale).equals(contentType.toLowerCase(locale))) {
                                            z6 = true;
                                            break;
                                        }
                                    }
                                    i6++;
                                }
                                if (!z6) {
                                    alVar.f14675l = (byte) 3;
                                    alVar.f14666c = 0;
                                    anVar.f14695a.a(alVar);
                                    hf.a((Closeable) null);
                                    hf.a((Closeable) null);
                                }
                            } catch (Throwable th) {
                                th = th;
                                inputStream = null;
                                hf.a(bufferedOutputStream3);
                                hf.a((Closeable) inputStream);
                                throw th;
                            }
                        }
                        long contentLength = httpURLConnection.getContentLength();
                        if (contentLength >= 0 && contentLength > j7) {
                            alVar.f14675l = (byte) 4;
                            alVar.f14666c = 0;
                            anVar.f14695a.a(alVar);
                            hf.a((Closeable) null);
                            hf.a((Closeable) null);
                        } else {
                            httpURLConnection.connect();
                            File a7 = gy.a(alVar.f14667d);
                            if (a7.exists()) {
                                a7.delete();
                            }
                            inputStream2 = httpURLConnection.getInputStream();
                            try {
                                bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(a7));
                                try {
                                    byte[] bArr = new byte[1024];
                                    j6 = 0;
                                    while (true) {
                                        int read = inputStream2.read(bArr);
                                        if (read <= 0) {
                                            break;
                                        }
                                        j6 += read;
                                        if (j6 > j7) {
                                            break;
                                        }
                                        bufferedOutputStream2 = bufferedOutputStream;
                                        try {
                                            bufferedOutputStream2.write(bArr, 0, read);
                                            bufferedOutputStream = bufferedOutputStream2;
                                        } catch (FileNotFoundException unused) {
                                            inputStream = inputStream2;
                                            bufferedOutputStream3 = bufferedOutputStream2;
                                            b10 = 2;
                                            alVar.f14675l = b10;
                                            anVar.f14695a.a(alVar);
                                            hf.a(bufferedOutputStream3);
                                            hf.a((Closeable) inputStream);
                                            return true;
                                        } catch (MalformedURLException unused2) {
                                            inputStream = inputStream2;
                                            bufferedOutputStream3 = bufferedOutputStream2;
                                            b9 = 1;
                                            alVar.f14675l = b9;
                                            anVar.f14695a.a(alVar);
                                            hf.a(bufferedOutputStream3);
                                            hf.a((Closeable) inputStream);
                                            return true;
                                        } catch (ProtocolException unused3) {
                                            inputStream = inputStream2;
                                            bufferedOutputStream3 = bufferedOutputStream2;
                                            b8 = 5;
                                            alVar.f14675l = b8;
                                            anVar.f14695a.a(alVar);
                                            hf.a(bufferedOutputStream3);
                                            hf.a((Closeable) inputStream);
                                            return true;
                                        } catch (SocketTimeoutException unused4) {
                                            inputStream = inputStream2;
                                            bufferedOutputStream3 = bufferedOutputStream2;
                                            b7 = 2;
                                            alVar.f14675l = b7;
                                            anVar.f14695a.a(alVar);
                                            hf.a(bufferedOutputStream3);
                                            hf.a((Closeable) inputStream);
                                            return true;
                                        } catch (IOException unused5) {
                                            inputStream = inputStream2;
                                            bufferedOutputStream3 = bufferedOutputStream2;
                                            b6 = 5;
                                            alVar.f14675l = b6;
                                            anVar.f14695a.a(alVar);
                                            hf.a(bufferedOutputStream3);
                                            hf.a((Closeable) inputStream);
                                            return true;
                                        } catch (Exception unused6) {
                                            inputStream = inputStream2;
                                            bufferedOutputStream3 = bufferedOutputStream2;
                                            alVar.f14675l = (byte) 0;
                                            anVar.f14695a.a(alVar);
                                            hf.a(bufferedOutputStream3);
                                            hf.a((Closeable) inputStream);
                                            return true;
                                        } catch (Throwable th2) {
                                            th = th2;
                                            inputStream = inputStream2;
                                            bufferedOutputStream3 = bufferedOutputStream2;
                                            hf.a(bufferedOutputStream3);
                                            hf.a((Closeable) inputStream);
                                            throw th;
                                        }
                                    }
                                } catch (FileNotFoundException unused7) {
                                    bufferedOutputStream2 = bufferedOutputStream;
                                } catch (MalformedURLException unused8) {
                                    bufferedOutputStream2 = bufferedOutputStream;
                                } catch (ProtocolException unused9) {
                                    bufferedOutputStream2 = bufferedOutputStream;
                                } catch (SocketTimeoutException unused10) {
                                    bufferedOutputStream2 = bufferedOutputStream;
                                } catch (IOException unused11) {
                                    bufferedOutputStream2 = bufferedOutputStream;
                                } catch (Exception unused12) {
                                    bufferedOutputStream2 = bufferedOutputStream;
                                } catch (Throwable th3) {
                                    th = th3;
                                    bufferedOutputStream2 = bufferedOutputStream;
                                }
                            } catch (FileNotFoundException unused13) {
                                inputStream = inputStream2;
                                b10 = 2;
                                bufferedOutputStream3 = null;
                            } catch (MalformedURLException unused14) {
                                inputStream = inputStream2;
                                b9 = 1;
                                bufferedOutputStream3 = null;
                            } catch (ProtocolException unused15) {
                                inputStream = inputStream2;
                                b8 = 5;
                                bufferedOutputStream3 = null;
                            } catch (SocketTimeoutException unused16) {
                                inputStream = inputStream2;
                                b7 = 2;
                                bufferedOutputStream3 = null;
                            } catch (IOException unused17) {
                                inputStream = inputStream2;
                                b6 = 5;
                                bufferedOutputStream3 = null;
                            } catch (Exception unused18) {
                                inputStream = inputStream2;
                                bufferedOutputStream3 = null;
                            } catch (Throwable th4) {
                                th = th4;
                                inputStream = inputStream2;
                                bufferedOutputStream3 = null;
                            }
                        }
                    } catch (Throwable th5) {
                        th = th5;
                        bufferedOutputStream3 = null;
                        inputStream = null;
                    }
                } catch (FileNotFoundException unused19) {
                    b10 = 2;
                    bufferedOutputStream3 = null;
                    inputStream = null;
                } catch (MalformedURLException unused20) {
                    b9 = 1;
                    bufferedOutputStream3 = null;
                    inputStream = null;
                } catch (ProtocolException unused21) {
                    b8 = 5;
                    bufferedOutputStream3 = null;
                    inputStream = null;
                } catch (SocketTimeoutException unused22) {
                    b7 = 2;
                    bufferedOutputStream3 = null;
                    inputStream = null;
                } catch (IOException unused23) {
                    b6 = 5;
                    bufferedOutputStream3 = null;
                    inputStream = null;
                } catch (Exception unused24) {
                    bufferedOutputStream3 = null;
                    inputStream = null;
                }
            } catch (Throwable th6) {
                th = th6;
            }
        } else {
            alVar.f14675l = (byte) 1;
            anVar.f14695a.a(alVar);
            return true;
        }
        return true;
        BufferedOutputStream bufferedOutputStream4 = bufferedOutputStream;
        an.a(elapsedRealtime, j6, SystemClock.elapsedRealtime());
        anVar.f14695a.a(alVar);
        hf.a(bufferedOutputStream4);
        hf.a((Closeable) inputStream2);
        return true;
    }

    static boolean b(aw awVar, al alVar) {
        return awVar.f14748k.containsKey(alVar.f14667d);
    }

    public synchronized void a(@NonNull al alVar, byte b6) {
        a(alVar);
        c(alVar.f14667d);
        if (b6 == 0) {
            a(alVar.f14667d);
            f();
        } else {
            b(alVar.f14667d);
            a(b6);
        }
    }

    public synchronized void a(byte b6) {
        ArrayList arrayList = new ArrayList();
        for (int i6 = 0; i6 < this.f14750n.size(); i6++) {
            am amVar = this.f14750n.get(i6);
            if (amVar.f14688e > 0) {
                try {
                    ax a7 = amVar.a();
                    if (a7 != null) {
                        a7.a(amVar, b6);
                    }
                    arrayList.add(amVar);
                } catch (Exception e6) {
                    fu.a().a(new gu(e6));
                }
            }
        }
        a(arrayList);
    }

    static void a(aw awVar, List list, String str) {
        CountDownLatch countDownLatch = new CountDownLatch(list.size());
        Iterator it = list.iterator();
        while (it.hasNext()) {
            String str2 = (String) it.next();
            try {
                cs.a(gy.c()).load(str2).fetch((Callback) cs.a(new c(countDownLatch, str2, SystemClock.elapsedRealtime(), str)));
            } catch (Exception unused) {
                countDownLatch.countDown();
            }
        }
        try {
            countDownLatch.await();
        } catch (InterruptedException unused2) {
        }
    }
}