package com.tencent.mm.model.d;

import android.content.Context;
import android.content.pm.IPackageStatsObserver;
import android.content.pm.PackageManager;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.kernel.g;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import java.io.File;

public class b$1 implements Runnable {
    final /* synthetic */ b fpv;

    public b$1(b bVar) {
        this.fpv = bVar;
    }

    public final void run() {
        AppMethodBeat.i(16391);
        File file = new File(b.access$000() + "MMSQL.trace");
        if (!file.exists()) {
            ab.w("MicroMsg.SQLTraceManager", "SqlTrace file is not  exists");
            AppMethodBeat.o(16391);
        } else if (g.RN().QY()) {
            long currentTimeMillis = System.currentTimeMillis();
            long bO = b.bO(ah.getContext());
            boolean z = false;
            if (bO > currentTimeMillis) {
                z = true;
            } else if (currentTimeMillis - bO > 86400000) {
                z = true;
            } else if (currentTimeMillis - bO > b.a(this.fpv) && b.b(this.fpv)) {
                z = true;
            }
            ab.i("MicroMsg.SQLTraceManager", "check need upload ,file size is %d,time out  %b", new Object[]{Long.valueOf(file.length()), Boolean.valueOf(z)});
            if (z && r2 > b.c(this.fpv)) {
                b bVar = this.fpv;
                Context context = ah.getContext();
                String packageName = ah.getContext().getPackageName();
                try {
                    PackageManager.class.getMethod("getPackageSizeInfo", new Class[]{String.class, IPackageStatsObserver.class}).invoke(context.getPackageManager(), new Object[]{packageName, new b$2(bVar)});
                } catch (Exception e) {
                    bVar.ceM[0] = -1;
                    bVar.ceM[1] = -1;
                    bVar.ceM[2] = -1;
                }
                if (b.d(this.fpv)[1] != 0 || b.e(this.fpv) > 1) {
                    ab.i("MicroMsg.SQLTraceManager", "start file upload ,file length is %d ", new Object[]{Long.valueOf(file.length())});
                    if (file.length() > b.f(this.fpv)) {
                        ab.e("MicroMsg.SQLTraceManager", "log file invaild format");
                    } else {
                        String ph = b.ph(b.access$000() + "MMSQL.trace");
                        ab.i("MicroMsg.SQLTraceManager", "read content success");
                        this.fpv.pg(ph);
                    }
                    ab.i("MicroMsg.SQLTraceManager", "set last Upload Time %d ", new Object[]{Long.valueOf(System.currentTimeMillis())});
                    b.a(this.fpv, file);
                    b.g(this.fpv);
                    b.h(this.fpv);
                    b.c(ah.getContext(), System.currentTimeMillis());
                    AppMethodBeat.o(16391);
                    return;
                }
                ab.i("MicroMsg.SQLTraceManager", "wait for get packageStats");
                b.i(this.fpv);
            }
            AppMethodBeat.o(16391);
        } else {
            ab.w("MicroMsg.SQLTraceManager", "acc not ready ");
            AppMethodBeat.o(16391);
        }
    }
}
