package com.tencent.mm.plugin.brandservice.ui.timeline.preload;

import a.f.b.j;
import a.l;
import com.google.android.gms.common.internal.ImagesContract;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.brandservice.ui.timeline.preload.g.a;
import com.tencent.mm.protocal.protobuf.ef;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.as;
import java.io.IOException;

@l(dWo = {1, 1, 13}, dWp = {"\u0000,\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0006\n\u0002\u0010\u0002\n\u0000\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u001a\u0010\u0005\u001a\u00020\u00062\b\u0010\u0007\u001a\u0004\u0018\u00010\b2\u0006\u0010\t\u001a\u00020\nH\u0002J\u0006\u0010\u000b\u001a\u00020\u0006J\u0013\u0010\f\u001a\u0004\u0018\u00010\b2\u0006\u0010\r\u001a\u00020\u0004H\u0002J\u0016\u0010\u000e\u001a\u00020\u00062\u0006\u0010\r\u001a\u00020\u00042\u0006\u0010\u000f\u001a\u00020\nJ\u0018\u0010\u0010\u001a\u00020\u00112\u0006\u0010\r\u001a\u00020\u00042\b\u0010\u0007\u001a\u0004\u0018\u00010\bR\u000e\u0010\u0003\u001a\u00020\u0004XD¢\u0006\u0002\n\u0000¨\u0006\u0012"}, dWq = {"Lcom/tencent/mm/plugin/brandservice/ui/timeline/preload/PreloadLogic$AppMsgContextCache;", "", "()V", "TAG", "", "checkValid", "", "appMsgContext", "Lcom/tencent/mm/protocal/protobuf/AppMsgContext;", "lowerVersion", "", "clear", "get", "url", "has", "tmplType", "save", "", "plugin-brandservice_release"})
public final class PreloadLogic$a {
    private final String TAG = "MicroMsg.Preload.BizAppMsgContextCache";

    public final boolean bK(String str, int i) {
        AppMethodBeat.i(14860);
        j.p(str, ImagesContract.URL);
        ef FP = FP(str);
        if (FP == null) {
            AppMethodBeat.o(14860);
            return false;
        }
        PreloadLogic preloadLogic = PreloadLogic.jSS;
        int sn = PreloadLogic.sn((FP != null ? Integer.valueOf(FP.vGc) : null).intValue());
        if (sn != -1) {
            i = sn;
        }
        preloadLogic = PreloadLogic.jSS;
        boolean a = a(FP, PreloadLogic.so(i));
        if (!a) {
            ab.d(this.TAG, "init valid:" + b.FI(str));
        }
        AppMethodBeat.o(14860);
        return a;
    }

    public final ef FP(String str) {
        AppMethodBeat.i(14861);
        j.p(str, ImagesContract.URL);
        String FI = b.FI(str);
        as FL = b.FL(FI);
        if (FL != null) {
            ef efVar = new ef();
            try {
                efVar.parseFrom(FL.decodeBytes(FI));
                efVar.Url = str;
                ab.i(this.TAG, "found:" + FI + " last modify:" + efVar.vFW);
                AppMethodBeat.o(14861);
                return efVar;
            } catch (IOException e) {
                ab.printErrStackTrace(this.TAG, e, "get:".concat(String.valueOf(FI)), new Object[0]);
            }
        }
        ab.i(this.TAG, "not found:".concat(String.valueOf(FI)));
        AppMethodBeat.o(14861);
        return null;
    }

    private final boolean a(ef efVar, int i) {
        AppMethodBeat.i(14862);
        if (efVar == null) {
            ab.v(this.TAG, "checkValid: null");
            AppMethodBeat.o(14862);
            return false;
        } else if (efVar.vFY == 0 || efVar.vFY >= i) {
            a aVar = g.jSD;
            if (a.aXh()) {
                ab.i(this.TAG, "checkValid: debug to expire");
            } else {
                boolean a;
                String str = efVar.Url;
                j.o(str, "appMsgContext.Url");
                str = b.FK(str);
                as FL = b.FL(str);
                if (FL != null) {
                    a = d.a(FL, str, ((long) efVar.vFU) * 1000);
                } else {
                    a = true;
                }
                if (a) {
                    ab.i(this.TAG, "checkValid: expire for " + efVar.vFU);
                    AppMethodBeat.o(14862);
                    return false;
                }
            }
            AppMethodBeat.o(14862);
            return true;
        } else {
            ab.v(this.TAG, "checkValid: lower version:data(" + efVar.vFY + ") < require(" + i + ')');
            AppMethodBeat.o(14862);
            return false;
        }
    }

    public final void a(String str, ef efVar) {
        byte[] bArr = null;
        AppMethodBeat.i(14863);
        j.p(str, ImagesContract.URL);
        if (efVar == null) {
            ab.e(this.TAG, "save fail, appMsgContext is null");
            AppMethodBeat.o(14863);
            return;
        }
        String FI = b.FI(str);
        as aWO = b.aWO();
        String str2 = efVar.ncM;
        try {
            bArr = efVar.toByteArray();
            ef efVar2 = new ef();
            efVar2.parseFrom(bArr);
            efVar2.ncM = null;
            bArr = efVar2.toByteArray();
        } catch (IOException e) {
            ab.printErrStackTrace(this.TAG, e, "save ".concat(String.valueOf(FI)), new Object[0]);
        }
        if (bArr != null) {
            aWO.encode(FI, bArr);
            if (str2 != null) {
                aWO.putString(b.FJ(str), str2);
            }
            d.a(aWO, b.FK(str));
        }
        ab.i(this.TAG, "save " + FI + " last modify:" + efVar.vFW);
        AppMethodBeat.o(14863);
    }
}
