package com.tencent.mm.app;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.Application;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Build;
import android.os.Looper;
import android.os.Process;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ca.b;
import com.tencent.mm.ci.k;
import com.tencent.mm.cj.c;
import com.tencent.mm.kernel.a.a;
import com.tencent.mm.kernel.a.d;
import com.tencent.mm.kernel.b.h;
import com.tencent.mm.kernel.j;
import com.tencent.mm.kiss.a.b.1;
import com.tencent.mm.modelrecovery.PluginRecovery;
import com.tencent.mm.plugin.auth.PluginAuth;
import com.tencent.mm.plugin.bbom.PluginBigBallOfMud;
import com.tencent.mm.plugin.messenger.foundation.PluginMessengerFoundation;
import com.tencent.mm.plugin.messenger.foundation.a.p;
import com.tencent.mm.plugin.report.PluginReport;
import com.tencent.mm.plugin.zero.PluginZero;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.ak;
import com.tencent.mm.sdk.platformtools.al;
import com.tencent.mm.sdk.platformtools.f;
import com.tencent.mm.ui.v;
import com.tencent.mm.vfs.FileSystemManager;
import com.tencent.xweb.WebView;
import com.tencent.ytcommon.BuildConfig;

public final class g extends d {
    private static boolean cel = true;
    private k cej = new k();
    private volatile boolean cek = false;

    public g() {
        AppMethodBeat.i(137994);
        AppMethodBeat.o(137994);
    }

    static /* synthetic */ void Bh() {
        AppMethodBeat.i(138002);
        Bf();
        AppMethodBeat.o(138002);
    }

    public final void Bd() {
        AppMethodBeat.i(137995);
        super.Bd();
        a.k("Hello WeChat, DefaultBootStep load debugger and newInstance xlog...", new Object[0]);
        ah.getContext().getSystemService("audio");
        l.cT(((h) com.tencent.mm.kernel.g.RM().Rn()).eHT);
        q.G(com.tencent.mm.boot.a.a.class);
        q.cY("com.tencent.mm.boot");
        q.a(((h) com.tencent.mm.kernel.g.RM().Rn()).cc, ((h) com.tencent.mm.kernel.g.RM().Rn()).cc.getResources());
        if (ah.isAppBrandProcess()) {
            com.tencent.mm.k.a.a.a(new com.tencent.mm.k.a() {
                public final boolean Bi() {
                    AppMethodBeat.i(138006);
                    c.a(WebView.d.ANb);
                    boolean dPa = c.dPa();
                    AppMethodBeat.o(138006);
                    return dPa;
                }
            });
        }
        Application application = ((h) com.tencent.mm.kernel.g.RM().Rn()).cc;
        ah.f(b.a(application.getResources(), application));
        com.tencent.mm.ca.a.a(new com.tencent.mm.ca.a.a() {
            public final void Bj() {
                AppMethodBeat.i(138010);
                ActivityManager activityManager = (ActivityManager) ah.getContext().getSystemService("activity");
                int myPid = Process.myPid();
                int myUid = Process.myUid();
                for (RunningAppProcessInfo runningAppProcessInfo : activityManager.getRunningAppProcesses()) {
                    if (runningAppProcessInfo.uid == myUid && runningAppProcessInfo.pid != myPid) {
                        Process.killProcess(runningAppProcessInfo.pid);
                    }
                }
                Process.killProcess(myPid);
                AppMethodBeat.o(138010);
            }
        });
        AppMethodBeat.o(137995);
    }

    public final void Be() {
        AppMethodBeat.i(137996);
        com.tencent.mm.kernel.g.RL().eJD = com.tencent.mm.plugin.zero.a.d.class;
        Q(PluginZero.class);
        Q(PluginMessengerFoundation.class);
        Q(PluginReport.class);
        Q(PluginAuth.class);
        Q(PluginBigBallOfMud.class);
        Q(PluginRecovery.class);
        lO("com.tencent.mm.plugin.bbom.PluginCompatOldStructure");
        lO("com.tencent.mm.plugin.bbom.PluginBigBallOfMudAsync");
        lO("com.tencent.mm.plugin.avatar.PluginAvatar");
        lO("com.tencent.mm.plugin.comm.PluginComm");
        lO("com.tencent.mm.plugin.audio.PluginVoice");
        lO("com.tencent.mm.plugin.biz.PluginBiz");
        lP("com.tencent.mm.plugin.bizui.PluginBIZUI");
        lO("com.tencent.mm.plugin.brandservice.PluginBrandService");
        lO("com.tencent.mm.plugin.readerapp.PluginReaderApp");
        lO("com.tencent.mm.plugin.notification.PluginNotification");
        lO("com.tencent.mm.plugin.messenger.PluginMessenger");
        lO("com.tencent.mm.plugin.welab.PluginWelab");
        lO("com.tencent.mm.plugin.sport.PluginSport");
        lO("com.tencent.mm.plugin.fts.PluginFTS");
        lO("com.tencent.mm.openim.PluginOpenIM");
        lP("com.tencent.mm.plugin.misc.PluginMisc");
        lO("com.tencent.mm.openim.room.PluginOpenIMRoom");
        lO("com.tencent.mm.roomsdk.PluginRoomSdk");
        lO("com.tencent.mm.ipcinvoker.wx_extension.PluginIPC");
        lO("com.tencent.mm.plugin.abtest.PluginABTest");
        lO("com.tencent.mm.plugin.backup.PluginBackup");
        lO("com.tencent.mm.plugin.hardcoder.PluginHardcoder");
        lP("com.tencent.mm.plugin.performance.PluginPerformance");
        lP("com.tencent.mm.plugin.chatroom.PluginChatroom");
        lP("com.tencent.mm.PluginFunctionMsg");
        lP("com.tencent.mm.insane_statistic.PluginInsaneStatistic");
        lP("com.tencent.mm.plugin.appbrand.app.PluginAppBrand");
        lP("com.tencent.mm.plugin.appbrand.compat.PluginAppBrandCompat");
        lP("com.tencent.mm.plugin.choosemsgfile.PluginChooseMsgFile");
        lP("com.tencent.mm.plugin.uishow.PluginUIShow");
        lP("com.tencent.mm.plugin.emoji.PluginEmoji");
        lP("com.tencent.mm.chatroom.plugin.PluginChatroomUI");
        lP("com.tencent.mm.plugin.game.PluginGame");
        lP("com.tencent.mm.game.report.PluginGameReport");
        lP("com.tencent.mm.plugin.wepkg.PluginWePkg");
        lP("com.tencent.mm.plugin.game.commlib.PluginCommLib");
        lP("com.tencent.mm.plugin.video.PluginVideo");
        lP("com.tencent.mm.plugin.hardwareopt.PluginHardwareOpt");
        lP("com.tencent.mm.plugin.sns.PluginSns");
        lP("com.tencent.mm.plugin.downloader.PluginDownloader");
        lP("com.tencent.mm.plugin.fav.PluginFav");
        lP("com.tencent.mm.plugin.fav.ui.PluginFavUI");
        lP("com.tencent.mm.plugin.record.PluginRecord");
        lP("com.tencent.mm.plugin.music.PluginMusic");
        lP("com.tencent.mm.plugin.MMPhotoEditPlugin");
        lP("com.tencent.mm.plugin.account.PluginAccount");
        lP("com.tencent.mm.plugin.facedetect.PluginFace");
        lP("com.tencent.mm.plugin.soter.PluginSoter");
        lP("com.tencent.mm.plugin.walletlock.PluginWalletLock");
        lP("com.tencent.mm.plugin.wxpay.PluginWxPay");
        lP("com.tencent.mm.plugin.wxpaysdk.PluginWxPaySdk");
        lP("com.tencent.mm.plugin.wxpayapi.PluginWxPayApi");
        lP("com.tencent.mm.plugin.radar.PluginRadar");
        lP("com.tencent.mm.plugin.topstory.PluginTopStory");
        lP("com.tencent.mm.plugin.topstory.ui.PluginTopStoryUI");
        lP("com.tencent.mm.plugin.websearch.PluginWebSearch");
        lP("com.tencent.mm.plugin.fts.ui.PluginFTSUI");
        lP("com.tencent.mm.plugin.card.PluginCard");
        lP("com.tencent.mm.plugin.card.compat.PluginCardCompat");
        lP("com.tencent.mm.plugin.kitchen.PluginKitchen");
        lP("com.tencent.mm.plugin.expt.PluginExpt");
        lP("com.tencent.mm.plugin.forcenotify.PluginForceNotify");
        lP("com.tencent.mm.plugin.monitor.PluginMonitor");
        lP("com.tencent.mm.plugin.fcm.PluginFCM");
        lP("com.tencent.mm.plugin.emojicapture.model.PluginEmojiCapture");
        lP("com.tencent.mm.plugin.selectcontact.PluginSelectContact");
        lP("com.tencent.mm.plugin.cloudvoip.cloudvoice.PluginCloudVoice");
        lP("com.tencent.mm.plugin.webview.PluginWebView");
        lP("com.tencent.mm.plugin.priority.PluginPriority");
        lP("com.tencent.mm.plugin.mmsight.PluginMMSight");
        lP("com.tencent.mm.plugin.secinforeport.PluginSecInfoReport");
        lP("com.tencent.mm.plugin.normsg.PluginNormsg");
        lP("com.tencent.mm.plugin.netmock.PluginNetMock");
        if (f.xxZ.amr("ENABLE_STETHO")) {
            lP("com.tencent.mm.plugin.stetho.PluginStetho");
        }
        lP("com.tencent.mm.plugin.appbrand.functions.comm.preloader.PluginLFPreloader");
        lP("com.tencent.mm.plugin.boots.PluginBoots");
        lP("com.tencent.mm.plugin.downloader_app.PluginDownloaderApp");
        lP("com.tencent.mm.plugin.game.luggage.PluginLuggageGame");
        lP("com.tencent.mm.plugin.trafficmonitor.PluginTrafficMonitor");
        lP("com.tencent.mm.plugin.story.PluginStory");
        com.tencent.mm.kernel.a.b.g gVar = com.tencent.mm.kernel.a.c.Sa().eKU;
        com.tencent.mm.kernel.b.a M = com.tencent.mm.kernel.g.M(p.class);
        gVar.eMh.put(com.tencent.mm.kernel.api.c.class, M);
        AppMethodBeat.o(137996);
    }

    public final void a(final com.tencent.mm.kernel.b.g gVar) {
        AppMethodBeat.i(137997);
        FileSystemManager.rh(!gVar.SG());
        FileSystemManager.a(new 3(this));
        Bf();
        if (((h) com.tencent.mm.kernel.g.RM().Rn()).SG()) {
            new al("Startup-SideWork").aa(new Runnable() {
                public final void run() {
                    AppMethodBeat.i(137958);
                    LayoutInflater e;
                    Looper looper;
                    com.tencent.mm.kiss.a.b SM;
                    try {
                        e = g.this.cej;
                        byte[] bArr = e.eHH;
                        synchronized (bArr) {
                            looper = e.eHH;
                            g.this.cej.done();
                            ContextWrapper contextWrapper = new ContextWrapper(gVar.cc);
                            SM = com.tencent.mm.kiss.a.b.SM();
                            looper = com.tencent.mm.kiss.a.a.SL().eMJ.getLooper();
                            e = v.hu(contextWrapper);
                            boolean z = SM.eMP;
                            if (!z) {
                                SM.eMP = z;
                                SM.mInflater = e;
                                SM.eMN = looper;
                                SM.mMode = 2;
                                SM.eMO = new 1(SM, SM.eMN);
                                if (com.tencent.mm.compatible.util.d.fP(26)) {
                                    SM.eMR = new com.tencent.mm.kiss.a.b.b(looper);
                                }
                            }
                            com.tencent.mm.blink.a.HJ();
                            Context baseContext = ((h) com.tencent.mm.kernel.g.RM().Rn()).cc.getBaseContext();
                            boolean a = com.tencent.mm.kiss.a.b.SM().a("R.layout.actionbar_title_launcher", 1, 2130968619, new LinearLayout(baseContext), false, new int[0]);
                            z = true;
                            com.tencent.mm.kiss.a.b.SM().a("R.layout.main_tab", 1, 2130970021, new int[0]);
                            if (com.tencent.mm.bz.a.ga(baseContext)) {
                                com.tencent.mm.kiss.a.b.SM().a("R.layout.mm_bottom_tabitem_large", 4, 2130970103, new LinearLayout(baseContext), false, new int[0]);
                            } else {
                                z = true;
                                com.tencent.mm.kiss.a.b.SM().a("R.layout.mm_bottom_tabitem", 4, 2130970102, new LinearLayout(baseContext), false, new int[0]);
                            }
                            com.tencent.mm.kiss.a.b.SM().a("R.layout.mm_activity", 4, 2130970087, new int[0]);
                            if (!(Build.BRAND.equals("vivo") && com.tencent.mm.compatible.util.d.fP(20))) {
                                com.tencent.mm.kiss.a.b.SM().a("R.layout.main", 1, 2130970018, new int[0]);
                                com.tencent.mm.kiss.a.b.SM().a("R.layout.address", 1, 2130968638, new int[0]);
                                com.tencent.mm.kiss.a.b.SM().a("R.layout.mm_preference_fragment_list_content", 2, 2130970177, new int[0]);
                            }
                            z = true;
                            com.tencent.mm.kiss.a.b.SM().a("R.layout.actionview_with_dot_tips", 1, 2130968621, new int[0]);
                            if (com.tencent.mm.bz.a.ga(baseContext)) {
                                com.tencent.mm.kiss.a.b.SM().a("R.layout.conversation_item_with_cache_large", 8, 2130969244, null, false, new int[0]);
                            } else if (com.tencent.mm.bz.a.gc(baseContext)) {
                                com.tencent.mm.kiss.a.b.SM().a("R.layout.conversation_item_with_cache_small", 8, 2130969245, null, false, new int[0]);
                            } else {
                                com.tencent.mm.kiss.a.b.SM().a("R.layout.conversation_item_with_cache", 8, 2130969243, null, false, new int[0]);
                            }
                            if (a) {
                                com.tencent.mm.kiss.a.b SM2 = com.tencent.mm.kiss.a.b.SM();
                                SM2.eMO.post(new com.tencent.mm.blink.c.1());
                            }
                            g.this.cej.done();
                            AppMethodBeat.o(137958);
                        }
                    } catch (Exception e2) {
                        e = e2;
                        try {
                            String str = "MicroMsg.DefaultBootStep";
                            looper = BuildConfig.FLAVOR;
                            g.this.cej.done();
                            AppMethodBeat.o(137958);
                        } catch (Throwable th) {
                            g.this.cej.done();
                            AppMethodBeat.o(137958);
                        }
                    } finally {
                        while (true) {
                        }
                        SM = 137958;
                        AppMethodBeat.o(137958);
                    }
                }
            });
        }
        if (gVar.SG()) {
            FileSystemManager dMv = FileSystemManager.dMv();
            dMv.zZk = false;
            FileSystemManager.a dMx = dMv.dMx();
            dMx.zYT.clear();
            dMx.zYU.clear();
            dMx.zYW.clear();
            dMx.zZn = null;
            dMx.zZo = true;
            dMx.commit();
        }
        super.a(gVar);
        AppMethodBeat.o(137997);
    }

    private static void Bf() {
        AppMethodBeat.i(137998);
        long currentTimeMillis = System.currentTimeMillis();
        q.Bz();
        com.tencent.mm.blink.a.s(4, System.currentTimeMillis() - currentTimeMillis);
        com.tencent.mm.blink.a.s(5, 1);
        ab.i("MicroMsg.DefaultBootStep", "SVG newInstance done, spent %s", new Object[]{Long.valueOf(currentTimeMillis)});
        AppMethodBeat.o(137998);
    }

    public final void b(com.tencent.mm.kernel.b.g gVar) {
        AppMethodBeat.i(137999);
        if (((h) com.tencent.mm.kernel.g.RM().Rn()).SG()) {
            k kVar = this.cej;
            synchronized (kVar.eHH) {
                try {
                    if (kVar.eHH[0] == (byte) -1) {
                        j.i("MicroMsg.WxWaitingLock", "waiting %s", new Object[]{kVar});
                        kVar.eHH.wait();
                        j.i("MicroMsg.WxWaitingLock", "after waiting %s", new Object[]{kVar});
                    }
                } catch (InterruptedException e) {
                    ab.printErrStackTrace("MicroMsg.WxWaitingLock", e, BuildConfig.FLAVOR, new Object[0]);
                } catch (Throwable th) {
                    AppMethodBeat.o(137999);
                }
            }
            if (this.cek) {
                ab.e("MicroMsg.DefaultBootStep", "SVG still failed!");
            }
        }
        super.b(gVar);
        AppMethodBeat.o(137999);
    }

    public final boolean Bg() {
        AppMethodBeat.i(138000);
        if (cel) {
            AppMethodBeat.o(138000);
            return true;
        } else if (((h) com.tencent.mm.kernel.g.RM().Rn()).SG()) {
            com.tencent.mm.kernel.g.RN();
            if (com.tencent.mm.kernel.a.QX() && com.tencent.mm.kernel.g.RN().QY()) {
                if (com.tencent.mm.splash.h.xGC.size() == 1) {
                    if (ah.doy().equals(com.tencent.mm.splash.h.an((Activity) com.tencent.mm.splash.h.xGC.get(0)))) {
                        ab.i("MicroMsg.DefaultBootStep", "Found LauncherUI only.");
                        AppMethodBeat.o(138000);
                        return false;
                    }
                }
                AppMethodBeat.o(138000);
                return true;
            }
            AppMethodBeat.o(138000);
            return true;
        } else {
            AppMethodBeat.o(138000);
            return true;
        }
    }

    static /* synthetic */ void a(g gVar, com.tencent.mm.kernel.b.g gVar2) {
        AppMethodBeat.i(138001);
        new 5(gVar, gVar2).b(new ak(Looper.getMainLooper()));
        AppMethodBeat.o(138001);
    }
}
