package com.tencent.mm.plugin.expt.c;

import android.app.Activity;
import android.app.Application.ActivityLifecycleCallbacks;
import android.os.Bundle;
import android.os.Process;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.g.a.k;
import com.tencent.mm.g.b.a.q;
import com.tencent.mm.g.b.a.w;
import com.tencent.mm.ipcinvoker.f;
import com.tencent.mm.kernel.api.c;
import com.tencent.mm.kernel.e;
import com.tencent.mm.kernel.g;
import com.tencent.mm.plugin.expt.a.a$a;
import com.tencent.mm.plugin.expt.a.c.a;
import com.tencent.mm.plugin.expt.hellhound.a.a.b;
import com.tencent.mm.plugin.report.service.h;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.as;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.storage.ac;
import com.tencent.ytcommon.BuildConfig;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import org.xwalk.core.XWalkFeature;

public final class d implements ActivityLifecycleCallbacks, c, com.tencent.mm.plugin.expt.a.c {
    private static int[] lNU = new int[]{10, XWalkFeature.INTERFACE_GEO_LOCATION_PERMISSION, 10000, 100000};
    private static boolean lNV = false;
    private static d lNW;
    private boolean lNX = false;
    private boolean lNY = false;
    private String lNZ = BuildConfig.FLAVOR;
    private HashSet<String> lOa = new HashSet();
    private com.tencent.mm.sdk.b.c<k> lOb = new 2(this);
    private com.tencent.mm.sdk.b.c lOc = new 3(this);

    private d() {
        AppMethodBeat.i(73537);
        if (!ah.bqo()) {
            lNV = true;
        }
        AppMethodBeat.o(73537);
    }

    private static void reset() {
        lNU = new int[]{10, XWalkFeature.INTERFACE_GEO_LOCATION_PERMISSION, 10000, 100000};
        lNV = false;
    }

    public static d brb() {
        AppMethodBeat.i(73538);
        if (lNW == null) {
            lNW = new d();
        }
        d dVar = lNW;
        AppMethodBeat.o(73538);
        return dVar;
    }

    private String aZm() {
        AppMethodBeat.i(73539);
        String str = hashCode();
        AppMethodBeat.o(73539);
        return str;
    }

    private void a(Activity activity, a aVar) {
        AppMethodBeat.i(73540);
        if (activity != null) {
            a(activity.getComponentName().getClassName(), aVar, activity.hashCode());
        }
        AppMethodBeat.o(73540);
    }

    public final void logout() {
        AppMethodBeat.i(73541);
        lNV = false;
        b.s(106, null, null);
        b.bqF();
        com.tencent.mm.plugin.expt.hellhound.a.a.a.uY(8);
        com.tencent.mm.plugin.expt.hellhound.core.v2.activity.a.uX(8);
        com.tencent.mm.plugin.expt.hellhound.a.a.a.gR(true);
        ab.i("MicroMsg.MMPageFlowService", "habbyge-mali, MMPageFlowService: logout补偿上报");
        AppMethodBeat.o(73541);
    }

    public static boolean brc() {
        return lNV;
    }

    private void a(String str, a aVar, int i, int i2, long j) {
        AppMethodBeat.i(73542);
        long yz = bo.yz();
        if (!ah.bqo()) {
            if (c.lNS == null) {
                c.lNS = new c();
            }
            c cVar = c.lNS;
            ab.i("MicroMsg.MMPageFlowSenderByIPCInvoker", "%s send page flow [%s-%d-%d] [%s]", new Object[]{cVar.hashCode(), str, Integer.valueOf(i), Long.valueOf(j), aVar});
            Bundle bundle = new Bundle();
            bundle.putInt("key_page_flow_type", aVar.value);
            bundle.putString("key_page_flow_name", str);
            bundle.putInt("key_page_flow_hashcode", i);
            bundle.putLong("key_page_flow_time_stamp", j);
            h.pYm.a(932, 100, 1, false);
            String string = bundle.getString("key_page_flow_name");
            int i3 = bundle.getInt("key_page_flow_type");
            int i4 = bundle.getInt("key_page_flow_hashcode", 0);
            long j2 = bundle.getLong("key_page_flow_time_stamp", 0);
            String str2 = (i4 + "_" + j2).hashCode();
            q qVar = new q();
            qVar.cWU = (long) i4;
            q eN = qVar.eN(string);
            eN.cWS = (long) i3;
            eN.aP(j2);
            b bqZ = b.bqZ();
            String Fj = qVar.Fj();
            as bra = bqZ.bra();
            if (bra != null) {
                bra.putString(str2, Fj);
            }
            f.a("com.tencent.mm", bundle, c.a.class, null);
            ab.d("MicroMsg.MMPageFlowService", "reportPageFlow: mm-process NOT");
            lNV = true;
        }
        if (lNV) {
            ab.d("MicroMsg.MMPageFlowService", "reportPageFlow: mm-process YES");
            if (ah.bqo()) {
                brd();
            }
            a(str, aVar, i, j, i2);
            ab.v("MicroMsg.MMPageFlowService", "report page Flow cost[%d]", new Object[]{Long.valueOf(bo.az(yz))});
            AppMethodBeat.o(73542);
            return;
        }
        ab.e("MicroMsg.MMPageFlowService", "reportPageFlow: mm-process isAccReady = FALSE");
        AppMethodBeat.o(73542);
    }

    public final void a(String str, a aVar, int i) {
        AppMethodBeat.i(73543);
        a(str, aVar, i, Process.myPid(), System.currentTimeMillis());
        AppMethodBeat.o(73543);
    }

    /* Access modifiers changed, original: protected|final */
    public final void brd() {
        AppMethodBeat.i(73544);
        if (ah.bqo()) {
            long yz = bo.yz();
            String[] allKeys = b.bqZ().allKeys();
            ArrayList<q> arrayList = new ArrayList();
            if (allKeys != null && allKeys.length > 0) {
                for (Object obj : allKeys) {
                    if (!this.lOa.contains(obj)) {
                        String str = b.bqZ().get(obj, BuildConfig.FLAVOR);
                        if (!bo.isNullOrNil(str)) {
                            q qVar = new q(str);
                            if (qVar.cWU > 0 && qVar.cWT > 0) {
                                arrayList.add(new q(str));
                                this.lOa.add(obj);
                            }
                            b.bqZ().remove(obj);
                        }
                    }
                    b.bqZ().remove(obj);
                }
            }
            if (!arrayList.isEmpty()) {
                Collections.sort(arrayList, new 1(this));
                for (q qVar2 : arrayList) {
                    a(qVar2.cWR, a.uW((int) qVar2.cWS), (int) qVar2.cWU, qVar2.cWT);
                }
                h.pYm.a(932, 102, (long) arrayList.size(), false);
                ab.i("MicroMsg.MMPageFlowService", "check mmkv list[%d] cost[%d]", new Object[]{Integer.valueOf(arrayList.size()), Long.valueOf(bo.az(yz))});
            }
            ab.d("MicroMsg.MMPageFlowService", "check mm kv cost[%d]", new Object[]{Long.valueOf(bo.az(yz))});
            AppMethodBeat.o(73544);
            return;
        }
        AppMethodBeat.o(73544);
    }

    private void a(String str, a aVar, int i, long j, int i2) {
        AppMethodBeat.i(73545);
        if (str.contains("WeChatSplashActivity") || str.contains("FakeSwitchAccountUI")) {
            AppMethodBeat.o(73545);
            return;
        }
        int i3;
        if (aVar.value <= 2) {
            i3 = 0;
        } else if (aVar.value <= 4) {
            i3 = 1;
        } else if (aVar.value <= 6) {
            i3 = 2;
        } else {
            i3 = 3;
        }
        if (aVar == a.lMc) {
            this.lNY = true;
        }
        if (aVar == a.lMd) {
            this.lNY = false;
        }
        w wVar = new w();
        wVar.cWc = i2;
        w eT = wVar.eS(((com.tencent.mm.kernel.b.h) g.RM().Rn()).eHT).eT(str);
        int[] iArr = lNU;
        int i4 = iArr[i3];
        iArr[i3] = i4 + 1;
        eT.cYc = (long) i4;
        eT.cWS = (long) aVar.value;
        eT = eT.aQ(j);
        eT.cWU = (long) i;
        e.brf().a(eT);
        ab.d("MicroMsg.MMPageFlowService", "%s pure report [%s]", new Object[]{aZm(), eT.Fk()});
        if (aVar == a.lMc || aVar == a.lMd) {
            ab.i("MicroMsg.MMPageFlowService", "habbyge-mali, %s frontback-pure-report [%s]", new Object[]{aZm(), eT.Fk()});
        }
        if (ah.bqo() && (aVar == a.lMc || aVar == a.lMd)) {
            q(j, this.lNY);
            com.tencent.mm.plugin.expt.hellhound.core.a.b.putInt("page_hell_seq_mmkv_key", lNU[3]);
        }
        AppMethodBeat.o(73545);
    }

    public final void a(String str, a aVar, int i, long j) {
        AppMethodBeat.i(73546);
        a(str, aVar, i, j, Process.myPid());
        AppMethodBeat.o(73546);
    }

    public final void onAccountInitialized(e.c cVar) {
        boolean z = true;
        AppMethodBeat.i(73547);
        reset();
        lNV = true;
        com.tencent.mm.plugin.expt.e.c.bru();
        if (bo.getInt(com.tencent.mm.plugin.expt.e.c.a(a$a.clicfg_weixin_register_mm_app_active_event, BuildConfig.FLAVOR, false), 0) <= 0) {
            z = false;
        }
        if (z) {
            com.tencent.mm.sdk.b.a.xxA.b(this.lOb);
        }
        com.tencent.mm.sdk.b.a.xxA.b(this.lOc);
        AppMethodBeat.o(73547);
    }

    public final void onAccountRelease() {
        AppMethodBeat.i(73548);
        reset();
        com.tencent.mm.sdk.b.a.xxA.d(this.lOb);
        com.tencent.mm.sdk.b.a.xxA.d(this.lOc);
        this.lNX = false;
        AppMethodBeat.o(73548);
    }

    public final void onActivityCreated(Activity activity, Bundle bundle) {
    }

    public final void onActivityStarted(Activity activity) {
    }

    public final void onActivityResumed(Activity activity) {
        AppMethodBeat.i(73549);
        a(activity, a.lLY);
        AppMethodBeat.o(73549);
    }

    public final void onActivityPaused(Activity activity) {
        AppMethodBeat.i(73550);
        a(activity, a.lLZ);
        AppMethodBeat.o(73550);
    }

    public final void onActivityStopped(Activity activity) {
    }

    public final void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
    }

    public final void onActivityDestroyed(Activity activity) {
        AppMethodBeat.i(73551);
        String className = activity.getComponentName().getClassName();
        if (lNV && "com.tencent.mm.ui.LauncherUI".equals(className) && this.lNY) {
            String str = "MicroMsg.MMPageFlowService";
            String str2 = "%s launcher ui ondestroyed but wechat in foreground hashcode[%d]";
            Object[] objArr = new Object[2];
            objArr[0] = aZm();
            objArr[1] = Integer.valueOf(activity != null ? activity.hashCode() : -1);
            ab.i(str, str2, objArr);
        }
        AppMethodBeat.o(73551);
    }

    private void q(long j, boolean z) {
        AppMethodBeat.i(73552);
        if (lNV) {
            int a = ((com.tencent.mm.plugin.expt.a.a) g.K(com.tencent.mm.plugin.expt.a.a.class)).a(a$a.clicfg_weixin_unread_records_rpt_time, 0);
            if (a <= 0) {
                AppMethodBeat.o(73552);
                return;
            }
            if (bo.anT() - g.RP().Ry().a(ac.a.xWI, 0) < ((long) a)) {
                AppMethodBeat.o(73552);
                return;
            }
            com.tencent.mm.sdk.g.d.xDG.remove("calc_unread_task");
            com.tencent.mm.sdk.g.d.xDG.b(new 4(this, j, z), "calc_unread_task", 5000);
            AppMethodBeat.o(73552);
            return;
        }
        AppMethodBeat.o(73552);
    }
}
