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

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.appbrand.app.f;
import com.tencent.mm.sdk.platformtools.bo;

public final class g {
    private static final byte[] gSj = new byte[0];

    public static void an(String str, int i) {
        AppMethodBeat.i(129331);
        if (bo.isNullOrNil(str)) {
            AppMethodBeat.o(129331);
            return;
        }
        f fVar = (f) f.E(f.class);
        if (fVar == null) {
            AppMethodBeat.o(129331);
            return;
        }
        synchronized (gSj) {
            try {
                h hVar = new h();
                hVar.field_appId = str;
                hVar.field_version = i;
                if (fVar.b(hVar, h.gSr)) {
                    hVar.field_hit++;
                    hVar.field_hitTimeMS = bo.anU();
                    fVar.c(hVar, h.gSr);
                } else {
                    hVar.field_hit = 1;
                    hVar.field_hitTimeMS = bo.anU();
                    fVar.b(hVar);
                }
            } finally {
                AppMethodBeat.o(129331);
            }
        }
    }

    /* JADX WARNING: Missing block: B:66:0x0215, code skipped:
            r4 = r2;
     */
    public static com.tencent.mm.plugin.appbrand.appcache.g.b a(long r14, com.tencent.mm.plugin.appbrand.appcache.g.a r16) {
        /*
        r0 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r0);
        r0 = 0;
        r0 = (r14 > r0 ? 1 : (r14 == r0 ? 0 : -1));
        if (r0 > 0) goto L_0x0015;
    L_0x000c:
        r0 = com.tencent.mm.plugin.appbrand.appcache.g.b.gSn;
        r1 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
    L_0x0014:
        return r0;
    L_0x0015:
        r0 = new android.os.StatFs;
        r1 = com.tencent.mm.plugin.appbrand.appcache.ap.avY();
        r0.<init>(r1);
        r1 = r0.getAvailableBlocks();
        r2 = (long) r1;
        r0 = r0.getBlockSize();
        r0 = (long) r0;
        r0 = r0 * r2;
        r2 = 0;
        r2 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1));
        if (r2 < 0) goto L_0x0033;
    L_0x002f:
        r0 = (r0 > r14 ? 1 : (r0 == r14 ? 0 : -1));
        if (r0 <= 0) goto L_0x003c;
    L_0x0033:
        r0 = com.tencent.mm.plugin.appbrand.appcache.g.b.gSn;
        r1 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        goto L_0x0014;
    L_0x003c:
        r0 = com.tencent.mm.plugin.appbrand.appcache.f.class;
        r0 = com.tencent.mm.plugin.appbrand.app.f.E(r0);
        r9 = r0;
        r9 = (com.tencent.mm.plugin.appbrand.appcache.f) r9;
        if (r9 != 0) goto L_0x0063;
    L_0x0047:
        r0 = "MicroMsg.AppBrand.CodeLibPruneLRULogic";
        r1 = "trimBy %d, lruStorage NULL";
        r2 = 1;
        r2 = new java.lang.Object[r2];
        r3 = 0;
        r4 = java.lang.Long.valueOf(r14);
        r2[r3] = r4;
        com.tencent.mm.sdk.platformtools.ab.e(r0, r1, r2);
        r0 = com.tencent.mm.plugin.appbrand.appcache.g.b.gSp;
        r1 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        goto L_0x0014;
    L_0x0063:
        r0 = java.util.Locale.US;
        r1 = " %s, %s ASC";
        r2 = 2;
        r2 = new java.lang.Object[r2];
        r3 = 0;
        r4 = "hit";
        r2[r3] = r4;
        r3 = 1;
        r4 = "hitTimeMS";
        r2[r3] = r4;
        r7 = java.lang.String.format(r0, r1, r2);
        r10 = new java.util.LinkedList;
        r10.<init>();
        r11 = gSj;
        monitor-enter(r11);
        r0 = r9.bSd;	 Catch:{ all -> 0x012e }
        r1 = "CodeLibUsageLRURecord";
        r2 = 2;
        r2 = new java.lang.String[r2];	 Catch:{ all -> 0x012e }
        r3 = 0;
        r4 = "appId";
        r2[r3] = r4;	 Catch:{ all -> 0x012e }
        r3 = 1;
        r4 = "version";
        r2[r3] = r4;	 Catch:{ all -> 0x012e }
        r3 = 0;
        r4 = 0;
        r5 = 0;
        r6 = 0;
        r8 = 2;
        r1 = r0.a(r1, r2, r3, r4, r5, r6, r7, r8);	 Catch:{ all -> 0x012e }
        if (r1 != 0) goto L_0x00ad;
    L_0x00a2:
        r0 = com.tencent.mm.plugin.appbrand.appcache.g.b.gSp;	 Catch:{ all -> 0x012e }
        monitor-exit(r11);	 Catch:{ all -> 0x012e }
        r1 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        goto L_0x0014;
    L_0x00ad:
        r0 = r1.moveToFirst();	 Catch:{ all -> 0x012e }
        if (r0 != 0) goto L_0x00c1;
    L_0x00b3:
        r1.close();	 Catch:{ all -> 0x012e }
        r0 = com.tencent.mm.plugin.appbrand.appcache.g.b.gSp;	 Catch:{ all -> 0x012e }
        monitor-exit(r11);	 Catch:{ all -> 0x012e }
        r1 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        goto L_0x0014;
    L_0x00c1:
        r0 = 0;
        r0 = r1.getString(r0);	 Catch:{ Exception -> 0x011a }
        r2 = 1;
        r2 = r1.getInt(r2);	 Catch:{ Exception -> 0x011a }
        r2 = java.lang.Integer.valueOf(r2);	 Catch:{ Exception -> 0x011a }
        r0 = android.util.Pair.create(r0, r2);	 Catch:{ Exception -> 0x011a }
        r10.add(r0);	 Catch:{ Exception -> 0x011a }
        r0 = r1.moveToNext();	 Catch:{ Exception -> 0x011a }
        if (r0 != 0) goto L_0x00c1;
    L_0x00dc:
        r1.close();	 Catch:{ all -> 0x012e }
    L_0x00df:
        monitor-exit(r11);	 Catch:{ all -> 0x012e }
        r0 = "MicroMsg.AppBrand.CodeLibPruneLRULogic";
        r1 = "codelib size:%d";
        r2 = 1;
        r2 = new java.lang.Object[r2];
        r3 = 0;
        r4 = r10.size();
        r4 = java.lang.Integer.valueOf(r4);
        r2[r3] = r4;
        com.tencent.mm.sdk.platformtools.ab.i(r0, r1, r2);
        r7 = com.tencent.mm.plugin.appbrand.app.f.auV();
        if (r7 != 0) goto L_0x0142;
    L_0x00fd:
        r0 = "MicroMsg.AppBrand.CodeLibPruneLRULogic";
        r1 = "trimBy %d, pkgStorage NULL";
        r2 = 1;
        r2 = new java.lang.Object[r2];
        r3 = 0;
        r4 = java.lang.Long.valueOf(r14);
        r2[r3] = r4;
        com.tencent.mm.sdk.platformtools.ab.e(r0, r1, r2);
        r0 = com.tencent.mm.plugin.appbrand.appcache.g.b.gSp;
        r1 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        goto L_0x0014;
    L_0x011a:
        r0 = move-exception;
        r2 = "MicroMsg.AppBrand.CodeLibPruneLRULogic";
        r3 = "trimBy, read from cursor e = %s";
        r4 = 1;
        r4 = new java.lang.Object[r4];	 Catch:{ all -> 0x0137 }
        r5 = 0;
        r4[r5] = r0;	 Catch:{ all -> 0x0137 }
        com.tencent.mm.sdk.platformtools.ab.e(r2, r3, r4);	 Catch:{ all -> 0x0137 }
        r1.close();	 Catch:{ all -> 0x012e }
        goto L_0x00df;
    L_0x012e:
        r0 = move-exception;
        monitor-exit(r11);	 Catch:{ all -> 0x012e }
        r1 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        throw r0;
    L_0x0137:
        r0 = move-exception;
        r1.close();	 Catch:{ all -> 0x012e }
        r1 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);	 Catch:{ all -> 0x012e }
        throw r0;	 Catch:{ all -> 0x012e }
    L_0x0142:
        r0 = 0;
        r2 = 0;
        a(r16);
        r8 = r10.iterator();
        r4 = r0;
        r6 = r2;
    L_0x014e:
        r0 = r8.hasNext();
        if (r0 == 0) goto L_0x0218;
    L_0x0154:
        r0 = r8.next();
        r0 = (android.util.Pair) r0;
        r1 = r0.first;
        r1 = (java.lang.String) r1;
        r2 = r0.second;
        r2 = (java.lang.Integer) r2;
        r2 = r2.intValue();
        r3 = com.tencent.mm.plugin.appbrand.appcache.ax.a.gVm;
        r10 = 1;
        r10 = new java.lang.String[r10];
        r11 = 0;
        r12 = "pkgPath";
        r10[r11] = r12;
        r1 = r7.b(r1, r2, r3, r10);
        r10 = r1.iterator();
        r2 = r4;
    L_0x017a:
        r1 = r10.hasNext();
        if (r1 == 0) goto L_0x0215;
    L_0x0180:
        r1 = r10.next();
        r1 = (com.tencent.mm.plugin.appbrand.appcache.at) r1;
        r4 = r1.field_pkgPath;
        r4 = com.tencent.mm.a.e.cs(r4);
        r4 = (long) r4;
        r4 = r4 + r2;
        r2 = "MicroMsg.AppBrand.CodeLibPruneLRULogic";
        r3 = "wxapkg appid:%s,delete path:%s";
        r11 = 2;
        r11 = new java.lang.Object[r11];
        r12 = 0;
        r13 = r1.field_appId;
        r11[r12] = r13;
        r12 = 1;
        r13 = r1.field_pkgPath;
        r11[r12] = r13;
        com.tencent.mm.sdk.platformtools.ab.i(r2, r3, r11);
        r2 = r1.field_pkgPath;
        com.tencent.mm.a.e.deleteFile(r2);
        r2 = r1.field_appId;
        r1 = r1.field_version;
        r3 = com.tencent.mm.sdk.platformtools.bo.isNullOrNil(r2);
        if (r3 == 0) goto L_0x01f7;
    L_0x01b3:
        r1 = "MicroMsg.AppBrand.CodeLibPruneLRULogic";
        r2 = "removeCodeCache appId null or nil!";
        com.tencent.mm.sdk.platformtools.ab.e(r1, r2);
    L_0x01bc:
        r6 = r6 + 1;
        r1 = r0.first;
        r1 = (java.lang.String) r1;
        r2 = r0.second;
        r2 = (java.lang.Integer) r2;
        r2 = r2.intValue();
        r9.am(r1, r2);
        a(r16);
        r1 = (r4 > r14 ? 1 : (r4 == r14 ? 0 : -1));
        if (r1 < 0) goto L_0x0212;
    L_0x01d4:
        r2 = new com.tencent.mm.g.b.a.bo;
        r2.<init>();
        r0 = 4;
        r2.dcY = r0;
        r0 = (long) r6;
        r2.ddb = r0;
        r0 = com.tencent.mm.plugin.appbrand.appcache.r.avH();
        if (r0 == 0) goto L_0x020f;
    L_0x01e6:
        r0 = 1;
    L_0x01e8:
        r2.dcW = r0;
        r2.ajK();
        r0 = com.tencent.mm.plugin.appbrand.appcache.g.b.gSo;
        r1 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        goto L_0x0014;
    L_0x01f7:
        r3 = 0;
        r11 = "$";
        r11 = r2.indexOf(r11);
        r2 = r2.substring(r3, r11);
        com.tencent.mm.plugin.appbrand.app.f.avc();
        r3 = new com.tencent.mm.plugin.appbrand.appcache.g$1;
        r3.<init>(r2, r1);
        com.tencent.mm.plugin.appbrand.appcache.am.a(r3);
        goto L_0x01bc;
    L_0x020f:
        r0 = 0;
        goto L_0x01e8;
    L_0x0212:
        r2 = r4;
        goto L_0x017a;
    L_0x0215:
        r4 = r2;
        goto L_0x014e;
    L_0x0218:
        r0 = com.tencent.mm.plugin.appbrand.appcache.g.b.gSp;
        r1 = 129332; // 0x1f934 float:1.81233E-40 double:6.38985E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        goto L_0x0014;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.plugin.appbrand.appcache.g.a(long, com.tencent.mm.plugin.appbrand.appcache.g$a):com.tencent.mm.plugin.appbrand.appcache.g$b");
    }

    private static void a(a aVar) {
        AppMethodBeat.i(129333);
        if (aVar == null || !aVar.avo()) {
            AppMethodBeat.o(129333);
            return;
        }
        InterruptedException interruptedException = new InterruptedException();
        AppMethodBeat.o(129333);
        throw interruptedException;
    }
}
