Search in sources :

Example 1 with PluginInstrumentation

use of com.morgoo.droidplugin.hook.handle.PluginInstrumentation in project DroidPlugin by DroidPluginTeam.

the class InstrumentationHook method onInstall.

@Override
protected void onInstall(ClassLoader classLoader) throws Throwable {
    Object target = ActivityThreadCompat.currentActivityThread();
    Class ActivityThreadClass = ActivityThreadCompat.activityThreadClass();
    /*替换ActivityThread.mInstrumentation,拦截组件调度消息*/
    Field mInstrumentationField = FieldUtils.getField(ActivityThreadClass, "mInstrumentation");
    Instrumentation mInstrumentation = (Instrumentation) FieldUtils.readField(mInstrumentationField, target);
    if (!PluginInstrumentation.class.isInstance(mInstrumentation)) {
        PluginInstrumentation pit = new PluginInstrumentation(mHostContext, mInstrumentation);
        pit.setEnable(isEnable());
        mPluginInstrumentations.add(pit);
        FieldUtils.writeField(mInstrumentationField, target, pit);
        Log.i(TAG, "Install Instrumentation Hook old=%s,new=%s", mInstrumentationField, pit);
    } else {
        Log.i(TAG, "Instrumentation has installed,skip");
    }
}
Also used : Field(java.lang.reflect.Field) Instrumentation(android.app.Instrumentation) PluginInstrumentation(com.morgoo.droidplugin.hook.handle.PluginInstrumentation) PluginInstrumentation(com.morgoo.droidplugin.hook.handle.PluginInstrumentation)

Aggregations

Instrumentation (android.app.Instrumentation)1 PluginInstrumentation (com.morgoo.droidplugin.hook.handle.PluginInstrumentation)1 Field (java.lang.reflect.Field)1