package com.ss.android.ugc.aweme.childhook;

import X.0HH;
import X.AnonymousClass7eY;
import X.AnonymousClass7eZ;
import X.C03817ek;
import X.C24208cV;
import android.app.Activity;
import android.app.Application;
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.IBinder;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.deeplink.DeepLinkServiceImpl;
import java.lang.reflect.Method;

public class ChildActivityInstrumentation extends Instrumentation {
    public static final String APPLINK = DeepLinkServiceImpl.LJIIJ().LIZLLL();
    public static final String DEEPLINK = DeepLinkServiceImpl.LJIIJ().LIZJ();
    public final Instrumentation mBaseInstrumentation;

    static {
        Covode.recordClassIndex(55912);
    }

    public ChildActivityInstrumentation(Instrumentation instrumentation) {
        this.mBaseInstrumentation = instrumentation;
    }

    public void callActivityOnDestroy(Activity activity) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnDestroy(activity);
        } else {
            super.callActivityOnDestroy(activity);
        }
    }

    public void callActivityOnPause(Activity activity) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnPause(activity);
        } else {
            super.callActivityOnPause(activity);
        }
    }

    public void callActivityOnRestart(Activity activity) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnRestart(activity);
        } else {
            super.callActivityOnRestart(activity);
        }
    }

    public void callActivityOnResume(Activity activity) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnResume(activity);
        } else {
            super.callActivityOnResume(activity);
        }
    }

    public void callActivityOnStart(Activity activity) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnStart(activity);
        } else {
            super.callActivityOnStart(activity);
        }
    }

    public void callActivityOnStop(Activity activity) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnStop(activity);
        } else {
            super.callActivityOnStop(activity);
        }
    }

    public void callActivityOnUserLeaving(Activity activity) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnUserLeaving(activity);
        } else {
            super.callActivityOnUserLeaving(activity);
        }
    }

    public void callApplicationOnCreate(Application application) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callApplicationOnCreate(application);
        } else {
            super.callApplicationOnCreate(application);
        }
    }

    public void callActivityOnCreate(Activity activity, Bundle bundle) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnCreate(activity, bundle);
        } else {
            super.callActivityOnCreate(activity, bundle);
        }
    }

    public void callActivityOnNewIntent(Activity activity, Intent intent) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnNewIntent(activity, intent);
        } else {
            super.callActivityOnNewIntent(activity, intent);
        }
    }

    public void callActivityOnRestoreInstanceState(Activity activity, Bundle bundle) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnRestoreInstanceState(activity, bundle);
        } else {
            super.callActivityOnRestoreInstanceState(activity, bundle);
        }
    }

    public void callActivityOnSaveInstanceState(Activity activity, Bundle bundle) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            instrumentation.callActivityOnSaveInstanceState(activity, bundle);
        } else {
            super.callActivityOnSaveInstanceState(activity, bundle);
        }
    }

    public boolean onException(Object obj, Throwable th) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            return instrumentation.onException(obj, th);
        }
        return super.onException(obj, th);
    }

    public Application newApplication(ClassLoader classLoader, String str, Context context) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        if (instrumentation != null) {
            return instrumentation.newApplication(classLoader, str, context);
        }
        return super.newApplication(classLoader, str, context);
    }

    public Activity newActivity(ClassLoader classLoader, String str, Intent intent) {
        if (str.equals("com.ss.android.ugc.aweme.main.MainActivity")) {
            AnonymousClass7eZ r0 = AnonymousClass7eY.LIZ;
            if (r0 == null || (str = r0.LIZ) == null) {
                str = "";
            }
        } else if (str.equals(DEEPLINK) || str.equals(APPLINK)) {
            str = "com.ss.android.ugc.aweme.kids.homepage.deeplink.KidsDeepLinkHandlerActivity";
        } else if (!C03817ek.LIZ.LIZ(intent)) {
            str = "com.ss.android.ugc.aweme.child.ChildEmptyFinishActivity";
        }
        return this.mBaseInstrumentation.newActivity(classLoader, str, intent);
    }

    public Instrumentation.ActivityResult execStartActivity(Context context, IBinder iBinder, IBinder iBinder2, Activity activity, Intent intent, int i, Bundle bundle) {
        Intent intent2 = intent;
        if (!C03817ek.LIZ.LIZ(intent2)) {
            return new Instrumentation.ActivityResult(0, new Intent());
        }
        Class<Instrumentation> cls = Instrumentation.class;
        try {
            Method declaredMethod = cls.getDeclaredMethod("execStartActivity", new Class[]{Context.class, IBinder.class, IBinder.class, Activity.class, Intent.class, Integer.TYPE, Bundle.class});
            declaredMethod.setAccessible(true);
            try {
                return (Instrumentation.ActivityResult) declaredMethod.invoke(this.mBaseInstrumentation, new Object[]{context, iBinder, iBinder2, activity, intent2, Integer.valueOf(i), bundle});
            } catch (Exception e) {
                e = e;
                0HH.LIZ(e);
                C24208cV.LIZ((Throwable) e, "execStartActivity");
                return new Instrumentation.ActivityResult(0, new Intent());
            }
        } catch (Exception e2) {
            e = e2;
            0HH.LIZ(e);
            C24208cV.LIZ((Throwable) e, "execStartActivity");
            return new Instrumentation.ActivityResult(0, new Intent());
        }
    }

    public Activity newActivity(Class<?> cls, Context context, IBinder iBinder, Application application, Intent intent, ActivityInfo activityInfo, CharSequence charSequence, Activity activity, String str, Object obj) {
        Instrumentation instrumentation = this.mBaseInstrumentation;
        ActivityInfo activityInfo2 = activityInfo;
        Intent intent2 = intent;
        Application application2 = application;
        IBinder iBinder2 = iBinder;
        String str2 = str;
        Context context2 = context;
        Object obj2 = obj;
        Activity activity2 = activity;
        Class<?> cls2 = cls;
        CharSequence charSequence2 = charSequence;
        if (instrumentation != null) {
            return instrumentation.newActivity(cls2, context2, iBinder2, application2, intent2, activityInfo2, charSequence2, activity2, str2, obj2);
        }
        return super.newActivity(cls2, context2, iBinder2, application2, intent2, activityInfo2, charSequence2, activity2, str2, obj2);
    }
}
