package com.tencent.mm.plugin.appbrand.launching;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.appbrand.app.f;
import com.tencent.mm.plugin.appbrand.appcache.WxaPkgLoadProgress;
import com.tencent.mm.plugin.appbrand.appcache.WxaPkgWrappingInfo;
import com.tencent.mm.plugin.appbrand.appcache.as;
import com.tencent.mm.plugin.appbrand.appcache.at;
import com.tencent.mm.plugin.appbrand.appcache.az;
import com.tencent.mm.plugin.appbrand.appcache.j.a;
import com.tencent.mm.plugin.appbrand.r.j;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;

final class ah$b implements Callable<WxaPkgWrappingInfo> {
    final /* synthetic */ ah iiv;
    private final int iix;

    /* synthetic */ ah$b(ah ahVar, int i, byte b) {
        this(ahVar, i);
    }

    public final /* synthetic */ Object call() {
        AppMethodBeat.i(131966);
        WxaPkgWrappingInfo azZ = azZ();
        AppMethodBeat.o(131966);
        return azZ;
    }

    private ah$b(ah ahVar, int i) {
        this.iiv = ahVar;
        this.iix = i;
    }

    public final WxaPkgWrappingInfo azZ() {
        AppMethodBeat.i(131965);
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        final j jVar = new j();
        AnonymousClass1 anonymousClass1 = new t(this.iiv.har) {
            /* Access modifiers changed, original: final */
            public final String aHr() {
                AppMethodBeat.i(131961);
                String format = String.format(Locale.US, "NonIncremental %d", new Object[]{Integer.valueOf(ah$b.this.iix)});
                AppMethodBeat.o(131961);
                return format;
            }

            /* Access modifiers changed, original: final */
            public final void d(WxaPkgWrappingInfo wxaPkgWrappingInfo) {
                AppMethodBeat.i(131962);
                jVar.value = wxaPkgWrappingInfo;
                countDownLatch.countDown();
                AppMethodBeat.o(131962);
            }

            /* Access modifiers changed, original: protected|final */
            public final void b(WxaPkgLoadProgress wxaPkgLoadProgress) {
                AppMethodBeat.i(131963);
                ab.d("MicroMsg.AppBrand.PrepareStepCheckAppPkg", "hy: onPkgUpdateProgress %s", new Object[]{wxaPkgLoadProgress.toString()});
                if (wxaPkgLoadProgress.progress >= 100) {
                    AppMethodBeat.o(131963);
                    return;
                }
                ah$b.this.iiv.onDownloadProgress(wxaPkgLoadProgress.progress);
                AppMethodBeat.o(131963);
            }
        };
        ab.i("MicroMsg.AppBrand.PrepareStepCheckAppPkg", "tryDownload, not incremental before start appId(%s), type(%d), pkgVersion(%d)", new Object[]{this.iiv.appId, Integer.valueOf(this.iiv.har), Integer.valueOf(this.iix)});
        if (a.kR(this.iiv.har)) {
            final at a = f.auV().a(this.iiv.appId, this.iiv.har, new String[]{"versionMd5", "downloadURL"});
            if (a == null || bo.isNullOrNil(a.field_downloadURL)) {
                ab.e("MicroMsg.AppBrand.PrepareStepCheckAppPkg", "tryDownload, get EMPTY url appId(%s), type(%d), record(%s)", new Object[]{this.iiv.appId, Integer.valueOf(this.iiv.har), a});
                this.iiv.a(as.a.gUJ);
                AppMethodBeat.o(131965);
                return null;
            }
            this.iiv.hok = a.field_downloadURL;
            if (!az.a(this.iiv.appId, this.iiv.har, this.iiv.hok, anonymousClass1, new com.tencent.mm.plugin.appbrand.appcache.a.a.a() {
                public final String avJ() {
                    AppMethodBeat.i(131964);
                    String str = "_" + a.field_versionMd5;
                    AppMethodBeat.o(131964);
                    return str;
                }
            })) {
                ab.e("MicroMsg.AppBrand.PrepareStepCheckAppPkg", "tryDownload, not incremental FATAL ERROR appId(%s), type(%d), pkgVersion(%d)", new Object[]{this.iiv.appId, Integer.valueOf(this.iiv.har), Integer.valueOf(this.iix)});
                this.iiv.a(as.a.gUN);
                AppMethodBeat.o(131965);
                return null;
            }
        } else if (!az.a(this.iiv.appId, this.iiv.har, this.iix, this.iiv.hhO.him, this.iiv.hok, anonymousClass1)) {
            ab.e("MicroMsg.AppBrand.PrepareStepCheckAppPkg", "tryDownload, not incremental FATAL ERROR appId(%s), type(%d), pkgVersion(%d)", new Object[]{this.iiv.appId, Integer.valueOf(this.iiv.har), Integer.valueOf(this.iix)});
            this.iiv.a(as.a.gUN);
            AppMethodBeat.o(131965);
            return null;
        }
        try {
            countDownLatch.await();
        } catch (Exception e) {
            ab.printErrStackTrace("MicroMsg.AppBrand.PrepareStepCheckAppPkg", e, "downloadNonIncremental semaphore exp ", new Object[0]);
        }
        WxaPkgWrappingInfo wxaPkgWrappingInfo = (WxaPkgWrappingInfo) jVar.value;
        AppMethodBeat.o(131965);
        return wxaPkgWrappingInfo;
    }
}
