zoukankan      html  css  js  c++  java
  • 启动检测

    目的:检测启动阶段耗时

    应用启动时,会直接对ActivityThread类hook

    public class Hacker {
    private static final String TAG = "Matrix.Hacker";
    public static boolean isEnterAnimationComplete = false;
    public static long sApplicationCreateBeginTime = 0L;
    public static int sApplicationCreateBeginMethodIndex = 0;
    public static long sApplicationCreateEndTime = 0L;
    public static int sApplicationCreateEndMethodIndex = 0;
    public static int sApplicationCreateScene = -100;

    public static void hackSysHandlerCallback() {
    try {
    //这个类被加载的时间,认为是整个App的启动开始时间
    sApplicationCreateBeginTime = System.currentTimeMillis();
    sApplicationCreateBeginMethodIndex = MethodBeat.getCurIndex();
    Class<?> forName = Class.forName("android.app.ActivityThread");
    Field field = forName.getDeclaredField("sCurrentActivityThread");
    field.setAccessible(true);
    Object activityThreadValue = field.get(forName);
    Field mH = forName.getDeclaredField("mH");
    mH.setAccessible(true);
    Object handler = mH.get(activityThreadValue);
    Class<?> handlerClass = handler.getClass().getSuperclass();
    Field callbackField = handlerClass.getDeclaredField("mCallback");
    callbackField.setAccessible(true);
    Handler.Callback originalCallback = (Handler.Callback) callbackField.get(handler);
    HackCallback callback = new HackCallback(originalCallback);
    callbackField.set(handler, callback);
    MatrixLog.i(TAG, "hook system handler completed. start:%s", sApplicationCreateBeginTime);
    } catch (Exception e) {
    MatrixLog.e(TAG, "hook system handler err! %s", e.getCause().toString());
    }
    }

  • 相关阅读:
    51Nod——T 1242 斐波那契数列的第N项
    51Nod——T 1113 矩阵快速幂
    第二课 eclipse安装
    第一课 JDK环境变量配置
    浅谈hibernate的sessionFactory和session
    hibernate配置文件
    eclipse的new server里tomcat7.0根本选不上解决方法
    CATALINA_BASE与CATALINA_HOME的区别
    Tomcat的overview界面浅析
    Win10系统 Eclipse 下'Publishing to Tomcat'has encountered a problem解决办法
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11295904.html
Copyright © 2011-2022 走看看