package com.bytedance.router.route;

import X.0HH;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.router.RouteIntent;
import com.bytedance.router.RouteManager;
import com.bytedance.router.listener.RouteCallbackProxy;
import com.bytedance.router.monitor.RouterMonitor;
import com.bytedance.router.util.Logger;

public abstract class SysComponentRoute extends BaseRoute {
    static {
        Covode.recordClassIndex(37259);
    }

    public abstract void openComponent(Context context, Intent intent);

    public Intent getComponent(Context context) {
        ComponentName componentName;
        RouteIntent routeIntent = getRouteIntent();
        Class<?> cls = null;
        if (routeIntent == null) {
            RouteCallbackProxy routeCallbackProxy = RouteManager.getInstance().getRouteCallbackProxy();
            throw new NullPointerException("getOriginUrl");
        }
        String targetClass = getTargetClass();
        if (TextUtils.isEmpty(targetClass)) {
            RouteManager.getInstance().getRouteCallbackProxy().onFail(routeIntent.getOriginUrl(), "ClassPath is null");
            Logger.e("SysComponentRoute open routeIntent but the classPath is null!!!");
            return null;
        }
        Intent extra = routeIntent.getExtra();
        if (extra == null) {
            RouteManager.getInstance().getRouteCallbackProxy().onFail(routeIntent.getOriginUrl(), "Intent is null");
            Logger.e("SysComponentRoute open routeIntent but the intent is null!!!");
            return null;
        }
        try {
            cls = Class.forName(targetClass);
        } catch (ClassNotFoundException e) {
            0HH.LIZ(e);
        }
        if (cls != null) {
            componentName = new ComponentName(context, cls);
        } else {
            componentName = new ComponentName(context.getPackageName(), targetClass);
        }
        extra.setComponent(componentName);
        extra.setPackage(context.getPackageName());
        return extra;
    }

    public void open(Context context) {
        String str;
        Intent component = getComponent(context);
        if (component != null) {
            if (getRouteIntent() != null) {
                str = getRouteIntent().getHost() + getRouteIntent().getPath();
            } else {
                str = "";
            }
            RouterMonitor.INSTANCE.markRouterJump(component, str);
            RouteManager.getInstance().getRouteCallbackProxy().onOpen(component);
            openComponent(context, component);
            RouteManager.getInstance().getRouteCallbackProxy().onSuccess(component);
        }
    }
}
