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());
    }
    }

  • 相关阅读:
    Web API 跨域问题
    找不到System.Web.Optimization命名空间
    IIS7配置rewriter
    Windows server 2008 R2实现多用户远程连接 (转)
    DatabaseGenerated(转)
    SQL、LINQ、Lambda 三种用法(转)
    Mvcpager以下各节已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“Scripts”。
    15-07-16 数据库--增删改查
    看名字测缘分
    String类
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11295904.html
Copyright © 2011-2022 走看看