导航菜单

页面标题

页面副标题

万能钥匙 v1.1.23 - ComponentManager.java 源代码

正在查看: 万能钥匙 v1.1.23 应用的 ComponentManager.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.tide.protocol.managers;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.text.TextUtils;
import com.meituan.robust.ChangeQuickRedirect;
import com.meituan.robust.PatchProxy;
import com.meituan.robust.PatchProxyResult;
import com.tide.protocol.bridge.TideProtocolBridge;
import com.tide.protocol.host.IHostApp;
import com.tide.protocol.util.TdLogUtils;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class ComponentManager {
    public static final String COMPONENT_CLASS_PATH = "COMPONENT_CLASS_PATH";
    public static final String PLUGIN_NAME = "PLUGIN_NAME";
    private static final String TAG = "ComponentManager";
    public static ChangeQuickRedirect changeQuickRedirect;
    private IHostApp hostApp = (IHostApp) TideProtocolBridge.getService(IHostApp.class);
    private static final ComponentManager sInstance = new ComponentManager();
    private static final List<ComponentOccupier> COMPONENT_OCCUPIERS = new CopyOnWriteArrayList();

    public static class ComponentOccupier {
        public String hostClassName;
        public String pluginClassName;
        public String pluginName;
    }

    private ComponentManager() {
    }

    private Intent createProxyIntent(Context context, Class<?> cls, String str, String str2, Intent intent) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context, cls, str, str2, intent}, this, changeQuickRedirect, false, 1398, new Class[]{Context.class, Class.class, String.class, String.class, Intent.class}, Intent.class);
        if (proxy.isSupported) {
            return (Intent) proxy.result;
        }
        if (intent != null) {
            intent.setComponent(new ComponentName(context, cls));
        } else {
            intent = new Intent(context, cls);
        }
        intent.putExtra(PLUGIN_NAME, str);
        intent.putExtra(COMPONENT_CLASS_PATH, str2);
        return intent;
    }

    private Intent createProxyServiceIntent(Context context, Intent intent) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context, intent}, this, changeQuickRedirect, false, 1401, new Class[]{Context.class, Intent.class}, Intent.class);
        if (proxy.isSupported) {
            return (Intent) proxy.result;
        }
        if (this.hostApp == null) {
            this.hostApp = (IHostApp) TideProtocolBridge.getService(IHostApp.class);
        }
        String str = TAG;
        TdLogUtils.log(str, "hostApp:" + this.hostApp);
        if (this.hostApp != null && intent != null) {
            String stringExtra = intent.getStringExtra(PLUGIN_NAME);
            String stringExtra2 = intent.getStringExtra(COMPONENT_CLASS_PATH);
            if (TextUtils.isEmpty(stringExtra) || TextUtils.isEmpty(stringExtra2)) {
                TdLogUtils.error(str, "Missing plugin name or component class path in Intent.");
            } else {
                String proxyServiceClass = this.hostApp.getProxyServiceClass(stringExtra, stringExtra2);
                TdLogUtils.log(str, "pluginServiceName:" + stringExtra2 + " proxyServiceName:" + proxyServiceClass);
                try {
                    Class<?> cls = Class.forName(proxyServiceClass);
                    TdLogUtils.log(str, "proxyServiceClz:" + cls);
                    intent.setComponent(new ComponentName(context, cls));
                    return intent;
                } catch (Throwable th) {
                    TdLogUtils.error(TAG, "startServiceWithPlugin error " + th.getMessage());
                }
            }
        }
        return null;
    }

    public static ComponentManager getInstance() {
        return sInstance;
    }

    public void addComponentOccupier(String str, String str2, String str3) {
        if (PatchProxy.proxy(new Object[]{str, str2, str3}, this, changeQuickRedirect, false, 1402, new Class[]{String.class, String.class, String.class}, Void.TYPE).isSupported) {
            return;
        }
        try {
            List<ComponentOccupier> list = COMPONENT_OCCUPIERS;
            if (list != null && !TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2) && !TextUtils.isEmpty(str3)) {
                ComponentOccupier componentOccupier = new ComponentOccupier();
                componentOccupier.pluginName = str;
                componentOccupier.hostClassName = str2;
                componentOccupier.pluginClassName = str3;
                list.add(componentOccupier);
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }

    public boolean bindServiceWithPlugin(Context context, Intent intent, ServiceConnection serviceConnection, int i) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context, intent, serviceConnection, new Integer(i)}, this, changeQuickRedirect, false, 1400, new Class[]{Context.class, Intent.class, ServiceConnection.class, Integer.TYPE}, Boolean.TYPE);
        if (proxy.isSupported) {
            return ((Boolean) proxy.result).booleanValue();
        }
        Intent createProxyServiceIntent = createProxyServiceIntent(context, intent);
        if (createProxyServiceIntent == null || context == null) {
            return false;
        }
        return context.bindService(createProxyServiceIntent, serviceConnection, i);
    }

    public ComponentOccupier getComponentOccupier(String str) {
        List<ComponentOccupier> list;
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{str}, this, changeQuickRedirect, false, 1403, new Class[]{String.class}, ComponentOccupier.class);
        if (proxy.isSupported) {
            return (ComponentOccupier) proxy.result;
        }
        if (!TextUtils.isEmpty(str) && (list = COMPONENT_OCCUPIERS) != null && !list.isEmpty()) {
            for (ComponentOccupier componentOccupier : list) {
                if (componentOccupier != null && TextUtils.equals(str, componentOccupier.hostClassName)) {
                    return componentOccupier;
                }
            }
        }
        return null;
    }

    public void startActivityFromOut(Context context, String str, String str2) {
        if (PatchProxy.proxy(new Object[]{context, str, str2}, this, changeQuickRedirect, false, 1396, new Class[]{Context.class, String.class, String.class}, Void.TYPE).isSupported) {
            return;
        }
        if (this.hostApp == null) {
            this.hostApp = (IHostApp) TideProtocolBridge.getService(IHostApp.class);
        }
        IHostApp iHostApp = this.hostApp;
        if (iHostApp != null) {
            try {
                context.startActivity(createProxyIntent(context, Class.forName(iHostApp.getProxyActivityClass(str, str2)), str, str2, null));
            } catch (Throwable th) {
                TdLogUtils.error(TAG, "ClassNotFoundException " + th.getMessage());
            }
        }
    }

    public void startActivityWithPlugin(Context context, Intent intent) {
        if (PatchProxy.proxy(new Object[]{context, intent}, this, changeQuickRedirect, false, 1397, new Class[]{Context.class, Intent.class}, Void.TYPE).isSupported) {
            return;
        }
        if (this.hostApp == null) {
            this.hostApp = (IHostApp) TideProtocolBridge.getService(IHostApp.class);
        }
        if (this.hostApp == null || intent == null) {
            return;
        }
        String stringExtra = intent.getStringExtra(PLUGIN_NAME);
        String stringExtra2 = intent.getStringExtra(COMPONENT_CLASS_PATH);
        if (TextUtils.isEmpty(stringExtra) || TextUtils.isEmpty(stringExtra2)) {
            TdLogUtils.error(TAG, "Missing plugin name or component class path in Intent.");
            return;
        }
        try {
            Intent createProxyIntent = createProxyIntent(context, Class.forName(this.hostApp.getProxyActivityClass(stringExtra, stringExtra2)), stringExtra, stringExtra2, intent);
            if (!(context instanceof Activity)) {
                createProxyIntent.addFlags(268435456);
            }
            context.startActivity(createProxyIntent);
        } catch (ClassNotFoundException e) {
            TdLogUtils.error(TAG, "ClassNotFoundException " + e.getMessage());
        }
    }

    public void startServiceWithPlugin(Context context, Intent intent) {
        Intent createProxyServiceIntent;
        if (PatchProxy.proxy(new Object[]{context, intent}, this, changeQuickRedirect, false, 1399, new Class[]{Context.class, Intent.class}, Void.TYPE).isSupported || (createProxyServiceIntent = createProxyServiceIntent(context, intent)) == null || context == null) {
            return;
        }
        context.startService(createProxyServiceIntent);
    }
}