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

import a.f.b.j;
import a.l;
import a.y;
import android.os.Looper;
import android.support.v7.h.d;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.kernel.b.e;
import com.tencent.mm.kernel.c.a;
import com.tencent.mm.kernel.c.b;
import com.tencent.mm.plugin.appbrand.app.f;
import com.tencent.mm.pointers.PInt;
import com.tencent.mm.protocal.protobuf.cdb;
import com.tencent.mm.protocal.protobuf.dk;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ap;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

@l(dWo = {1, 1, 13}, dWp = {"\u0000V\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0007\b\u0007\u0018\u0000 #2\u00020\u00012\u00020\u0002:\u0002#$B\u0005¢\u0006\u0002\u0010\u0003J=\u0010\t\u001a\u00020\n2\u0006\u0010\u000b\u001a\u00020\f2\f\u0010\r\u001a\b\u0012\u0004\u0012\u00020\u000f0\u000e2\f\u0010\u0010\u001a\b\u0012\u0004\u0012\u00020\u000f0\u000e2\n\b\u0002\u0010\u0011\u001a\u0004\u0018\u00010\u0012H\u0000¢\u0006\u0002\b\u0013J\b\u0010\u0014\u001a\u00020\u0015H\u0002J\u0014\u0010\u0016\u001a\u0004\u0018\u00010\u00172\b\u0010\u0018\u001a\u0004\u0018\u00010\u000fH\u0002J\b\u0010\u0019\u001a\u00020\u0015H\u0016J\b\u0010\u001a\u001a\u00020\u0015H\u0016J\u0018\u0010\u001b\u001a\u00020\u00152\u0006\u0010\u001c\u001a\u00020\u00062\b\b\u0002\u0010\u001d\u001a\u00020\u001eJ\b\u0010\u001f\u001a\u00020\u0015H\u0002J\u000e\u0010 \u001a\u00020\u00152\u0006\u0010\u001d\u001a\u00020\u001eJ\u0016\u0010!\u001a\u00020\u00152\f\u0010\"\u001a\b\u0012\u0004\u0012\u00020\u00060\u000eH\u0002R\u0014\u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0007\u001a\u00020\bX\u0004¢\u0006\u0002\n\u0000¨\u0006%"}, dWq = {"Lcom/tencent/mm/plugin/appbrand/appusage/AppBrandCollectionModifyQueue;", "Lcom/tencent/mm/kernel/service/IService;", "Lcom/tencent/mm/kernel/service/IServiceLifeCycle;", "()V", "memoryQueue", "Ljava/util/LinkedList;", "Lcom/tencent/mm/protocal/protobuf/StarWxaSortOperation;", "timeoutOpTimer", "Lcom/tencent/mm/sdk/platformtools/MTimerHandler;", "applyDiff", "", "diff", "Landroid/support/v7/util/DiffUtil$DiffResult;", "oldList", "", "Lcom/tencent/mm/plugin/appbrand/appusage/LocalUsageInfo;", "newList", "callback", "Lcom/tencent/mm/plugin/appbrand/appusage/AppBrandCollectionModifyQueue$OnModifiedCallback;", "applyDiff$plugin_appbrand_integration_release", "deserializeFromDisk", "", "modelClient2Server", "Lcom/tencent/mm/protocal/protobuf/StarWxaInfo;", "clientUse", "onRegister", "onUnregister", "push", "op", "reason", "Lcom/tencent/mm/plugin/appbrand/appusage/CgiUpdateWxaStarRecord$UpdateReason;", "serializeToDisk", "triggerRequest", "writeBackQueue", "queue", "Companion", "OnModifiedCallback", "plugin-appbrand-integration_release"})
@e(com.tencent.mm.plugin.appbrand.a.c.class)
public final class c implements a, b {
    public static final a gYK = new a((byte) 0);
    private final LinkedList<cdb> gYI = new LinkedList();
    private final ap gYJ = new ap(Looper.getMainLooper(), (ap.a) new d(this), false);

    static {
        AppMethodBeat.i(134503);
        AppMethodBeat.o(134503);
    }

    public c() {
        AppMethodBeat.i(134502);
        AppMethodBeat.o(134502);
    }

    public final boolean a(android.support.v7.h.c.b bVar, List<? extends LocalUsageInfo> list, List<? extends LocalUsageInfo> list2, b bVar2) {
        AppMethodBeat.i(134498);
        j.p(bVar, "diff");
        j.p(list, "oldList");
        j.p(list2, "newList");
        ArrayList arrayList = new ArrayList();
        arrayList.addAll(list);
        PInt pInt = new PInt(0);
        synchronized (this.gYI) {
            try {
                bVar.a((d) new c(this, bVar, pInt, list2, bVar2, arrayList));
                y yVar = y.AUy;
            } finally {
                AppMethodBeat.o(134498);
            }
        }
        if (pInt.value > 0) {
            return true;
        }
        AppMethodBeat.o(134498);
        return false;
    }

    public final void a(cdb cdb, z.b bVar) {
        AppMethodBeat.i(134499);
        j.p(cdb, "op");
        j.p(bVar, "reason");
        synchronized (this.gYI) {
            try {
                this.gYI.addLast(cdb);
                y yVar = y.AUy;
            } finally {
                AppMethodBeat.o(134499);
            }
        }
        switch (d.eQZ[bVar.ordinal()]) {
            case 1:
                this.gYJ.ms(30000);
                AppMethodBeat.o(134499);
                return;
            default:
                a(bVar);
                break;
        }
        AppMethodBeat.o(134499);
    }

    public final void a(z.b bVar) {
        AppMethodBeat.i(134501);
        j.p(bVar, "reason");
        ab.i("MicroMsg.AppBrandCollectionModifyQueue[collection]", "triggerRequest reason = " + bVar.name());
        this.gYJ.stopTimer();
        LinkedList linkedList = new LinkedList();
        synchronized (this.gYI) {
            try {
                linkedList.addAll(this.gYI);
                this.gYI.clear();
                y yVar = y.AUy;
            } catch (Throwable th) {
                AppMethodBeat.o(134501);
            }
        }
        if (linkedList.isEmpty()) {
            ab.i("MicroMsg.AppBrandCollectionModifyQueue[collection]", "triggerRequest reason=[" + bVar.intValue + "], queue empty");
            if (bVar == z.b.ClosePullDown || bVar == z.b.CloseCollectionList) {
                ae.a aVar = ae.haH;
                ae.a.cQ(2, 2);
            }
            AppMethodBeat.o(134501);
            return;
        }
        ab.i("MicroMsg.AppBrandCollectionModifyQueue[collection]", "run cgi reason=[" + bVar.intValue + "], queue_size=" + linkedList.size());
        new z(linkedList, bVar.intValue).acy().j((com.tencent.mm.vending.c.a) new e(this, bVar, linkedList));
        AppMethodBeat.o(134501);
    }

    /* JADX WARNING: No exception handlers in catch block: Catch:{  } */
    public final void SH() {
        /*
        r4 = this;
        r3 = 134496; // 0x20d60 float:1.88469E-40 double:6.645E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r3);
        r0 = com.tencent.mm.plugin.appbrand.app.f.auZ();
        r1 = "AppBrandCollectionModifyQueue";
        r1 = r0.DH(r1);
        if (r1 == 0) goto L_0x0060;
    L_0x0013:
        r0 = r1.length;
        if (r0 != 0) goto L_0x003f;
    L_0x0016:
        r0 = 1;
    L_0x0017:
        if (r0 != 0) goto L_0x005c;
    L_0x0019:
        r0 = com.tencent.mm.plugin.appbrand.app.f.auZ();
        r2 = "AppBrandCollectionModifyQueue";
        r0.clear(r2);
        r0 = new com.tencent.mm.protocal.protobuf.dk;	 Catch:{ Exception -> 0x004a }
        r0.<init>();	 Catch:{ Exception -> 0x004a }
        r0.parseFrom(r1);	 Catch:{ Exception -> 0x004a }
        r1 = r4.gYI;	 Catch:{ Exception -> 0x004a }
        monitor-enter(r1);	 Catch:{ Exception -> 0x004a }
        r2 = r4.gYI;	 Catch:{ all -> 0x0041 }
        r0 = r0.eow;	 Catch:{ all -> 0x0041 }
        r0 = (java.util.Collection) r0;	 Catch:{ all -> 0x0041 }
        r2.addAll(r0);	 Catch:{ all -> 0x0041 }
        monitor-exit(r1);	 Catch:{ Exception -> 0x004a }
        r0 = 134496; // 0x20d60 float:1.88469E-40 double:6.645E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r0);	 Catch:{ Exception -> 0x004a }
    L_0x003e:
        return;
    L_0x003f:
        r0 = 0;
        goto L_0x0017;
    L_0x0041:
        r0 = move-exception;
        monitor-exit(r1);	 Catch:{ Exception -> 0x004a }
        r1 = 134496; // 0x20d60 float:1.88469E-40 double:6.645E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);	 Catch:{ Exception -> 0x004a }
        throw r0;	 Catch:{ Exception -> 0x004a }
    L_0x004a:
        r0 = move-exception;
        r1 = "MicroMsg.AppBrandCollectionModifyQueue[collection]";
        r2 = "deserializeFromDisk, read kv failed, e = ";
        r0 = java.lang.String.valueOf(r0);
        r0 = r2.concat(r0);
        com.tencent.mm.sdk.platformtools.ab.e(r1, r0);
    L_0x005c:
        com.tencent.matrix.trace.core.AppMethodBeat.o(r3);
        goto L_0x003e;
    L_0x0060:
        com.tencent.matrix.trace.core.AppMethodBeat.o(r3);
        goto L_0x003e;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.plugin.appbrand.appusage.c.SH():void");
    }

    public final void SI() {
        AppMethodBeat.i(134497);
        dk dkVar = new dk();
        synchronized (this.gYI) {
            try {
                dkVar.eow.addAll(this.gYI);
            } finally {
                AppMethodBeat.o(134497);
            }
        }
        if (!dkVar.eow.isEmpty()) {
            try {
                f.auZ().s("AppBrandCollectionModifyQueue", dkVar.toByteArray());
                return;
            } catch (Exception e) {
                ab.e("MicroMsg.AppBrandCollectionModifyQueue[collection]", "serializeToDisk, write kv failed, e = ".concat(String.valueOf(e)));
            }
        }
        AppMethodBeat.o(134497);
    }
}
