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

  • 相关阅读:
    scla-基础-函数-元组(0)
    scala-基础-映射(1)
    Scala-基础-数组(1)
    Scala-基础-函数(2)
    Scala-基础-函数(1)
    Scala-基础-流程控制语句
    Scala-基础-运算符
    机器猫工作笔记(持续更新中...)
    收集的URL
    苹果审核指南(中文)
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11295904.html
Copyright © 2011-2022 走看看