QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

以下内容为反编译后的 WormHoleManager.java 源代码,内容仅作参考


package com.tencent.mtt.hippy.qb.utils;

import android.os.Bundle;
import android.text.TextUtils;
import com.tencent.common.utils.StringUtils;
import com.tencent.common.wormhole.WormholeManager;
import com.tencent.mtt.base.functionwindow.ActivityHandler;
import com.tencent.mtt.base.stat.StatManager;
import com.tencent.mtt.base.wup.PreferenceData;
import com.tencent.mtt.hippy.HippyEngine;
import com.tencent.mtt.hippy.HippyRootView;
import com.tencent.mtt.hippy.qb.DestroyableObject;
import com.tencent.mtt.hippy.qb.DestroyableObjectCreator;
import com.tencent.mtt.hippy.qb.HippyEngineManager;
import com.tencent.mtt.hippy.qb.ModuleParams;
import com.tencent.mtt.hippy.qb.QBHippyWindow;
import com.tencent.mtt.hippy.qb.WindowEngineManager;
import com.tencent.mtt.hippy.qb.update.HippyUpdateConfig;
import com.tencent.mtt.log.access.Logs;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;

public class WormHoleManager {
    public static final String TAG = "WormHoleManager";
    private static CopyOnWriteArrayList<Integer> hostEngineIds = new CopyOnWriteArrayList<>();
    private static boolean isWormHoleLoaded = false;

    public static class CountReference {
        public int count = 0;
        DestroyableObjectCreator mCreator;
        DestroyableObject mDestroyable;

        public CountReference(DestroyableObjectCreator destroyableObjectCreator) {
            this.mCreator = destroyableObjectCreator;
        }

        public DestroyableObject create(WindowEngineManager windowEngineManager) {
            if (windowEngineManager != null && this.mCreator != null) {
                WormHoleManager.reportWormholeInitDt();
                if (this.mDestroyable == null) {
                    this.mDestroyable = this.mCreator.create(WindowEngineManager.getHippyEngineManager());
                }
                WormholeManager.a().a((Object) windowEngineManager.getEngine());
                if (WormHoleManager.hostEngineIds != null && windowEngineManager.getEngine() != null) {
                    WormHoleManager.hostEngineIds.add(Integer.valueOf(windowEngineManager.getEngine().getId()));
                }
                if (WormHoleManager.isWormHoleLoaded) {
                    windowEngineManager.sendEvent("@wormhole:create", WormHoleManager.access$200());
                }
                this.count++;
            }
            return this.mDestroyable;
        }

        public void release(HippyRootView hippyRootView) {
            if (this.count > 0) {
                if (hippyRootView != null) {
                    try {
                        WormholeManager.a().d(hippyRootView.getId());
                        if (hippyRootView.getEngineContext() != null && WormHoleManager.hostEngineIds != null) {
                            WormHoleManager.hostEngineIds.remove(Integer.valueOf(hippyRootView.getEngineContext().getEngineId()));
                        }
                    } catch (Exception e) {
                        WormHoleManager.errorReport(e);
                    }
                }
                this.count--;
                if (this.count == 0) {
                    WormholeManager.a().a((HippyEngine) null);
                    this.mDestroyable.destroy();
                    this.mDestroyable = null;
                }
            }
        }
    }

    public static class WormHoleCreatorImpl implements DestroyableObjectCreator {
        @Override
        public DestroyableObject create(HippyEngineManager hippyEngineManager) {
            ModuleParams build = new ModuleParams.Builder().setFrameworkType(1).setIsWormHole(true).setModuleName("TKDADwormhole").setDemotionUrl("https://m.qq.com").setDebug(false).setActivity(ActivityHandler.b().m().b()).setComponentName("TKDADwormhole").build();
            return new QBHippyWindow(build.mActivity, build, null, hippyEngineManager);
        }
    }

    static Bundle access$200() {
        return getWormholeBundle();
    }

    private static boolean canLoadWormhole(String str) {
        String a2 = PreferenceData.a("MTT_AD_WORMHOLE_MODULES");
        try {
            if (TextUtils.isEmpty(a2)) {
                return false;
            }
            return Arrays.asList(a2.split("\\|")).contains(str);
        } catch (Exception unused) {
            return false;
        }
    }

    public static void errorReport(Exception exc) {
        HashMap hashMap = new HashMap();
        hashMap.put("loadModule", "error release");
        StatManager.b().b("QB_WormHole_Start", hashMap);
    }

    private static Bundle getWormholeBundle() {
        Bundle bundle = new Bundle();
        bundle.putBoolean("wormholeEnabled", isEnableWormHoleFromCloud());
        bundle.putString("wormholeVersion", HippyUpdateConfig.getInstance().getModuleVersionName("TKDADwormhole", ""));
        return bundle;
    }

    public static boolean isEnableWormHoleFromCloud() {
        return StringUtils.b(PreferenceData.a("MTT_ENABLE_AD_WORMHOLE"), 0) == 1;
    }

    public static boolean needOpenWormhole(String str) {
        return !TextUtils.isEmpty(str) && canLoadWormhole(str) && isEnableWormHoleFromCloud();
    }

    public static void reportWormholeInitDt() {
        HashMap hashMap = new HashMap();
        hashMap.put("initEngine", "start");
        StatManager.b().b("QB_WormHole_Start", hashMap);
    }

    public static void sendRootDeleteMessageToClient(QBHippyWindow qBHippyWindow) {
        try {
            WormholeManager.a().d(qBHippyWindow.getHippyRootView().getId());
        } catch (Exception unused) {
            HashMap hashMap = new HashMap();
            hashMap.put("loadModule", "error delete");
            StatManager.b().b("QB_WormHole_Start", hashMap);
        }
    }

    public static void sendWormHoleLoadComplete() {
        CopyOnWriteArrayList<Integer> copyOnWriteArrayList = hostEngineIds;
        if (copyOnWriteArrayList == null) {
            return;
        }
        isWormHoleLoaded = true;
        try {
            Iterator<Integer> it = copyOnWriteArrayList.iterator();
            while (it.hasNext()) {
                QBHippyWindow.getViewByEngineID(it.next().intValue()).sendEvent("@wormhole:create", getWormholeBundle());
            }
        } catch (Exception e) {
            Logs.e(TAG, "sendWormHoleLoadComplete:" + e.getMessage());
        }
    }
}