博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
打印日志
阅读量:4281 次
发布时间:2019-05-27

本文共 2788 字,大约阅读时间需要 9 分钟。

ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startActivity:1005 android.app.ContextImpl.startActivity:994 android.content.ContextWrapper.startActivity:403 应用的包名和类名:116

Android中的ContextImpl竟然打印了Service和BroadcastReceiver的调用栈

看源码:

根据“Calling a method in the system process without”查找代码。

1.ContextImpl.java

frameworks/base/core/java/android/app/ContextImpl.java

在startActivity的时候调用了warnIfCallingFromSystemProcess方法,,warnIfCallingFromSystemProcess会通过Debug.getCallers(5)来打印当前应用的任务栈

991      @Override992      public void startActivity(Intent intent) {993          warnIfCallingFromSystemProcess();994          startActivity(intent, null);995      }

 

2239      private void warnIfCallingFromSystemProcess() {2240          if (Process.myUid() == Process.SYSTEM_UID) {2241              Slog.w(TAG, "Calling a method in the system process without a qualified user: "2242                      + Debug.getCallers(5));2243          }2244      }

2.Deubug

frameworks/base/core/java/android/os/Debug.java

2470      /**2471       * Return a String describing the calling method and location at a particular stack depth.2472       * @param callStack the Thread stack2473       * @param depth the depth of stack to return information for.2474       * @return the String describing the caller at that depth.2475       */2476      private static String getCaller(StackTraceElement callStack[], int depth) {2477          // callStack[4] is the caller of the method that called getCallers()2478          if (4 + depth >= callStack.length) {2479              return "
";2480 }2481 StackTraceElement caller = callStack[4 + depth];2482 return caller.getClassName() + "." + caller.getMethodName() + ":" + caller.getLineNumber();2483 }2484 2485 /**2486 * Return a string consisting of methods and locations at multiple call stack levels.2487 * @param depth the number of levels to return, starting with the immediate caller.2488 * @return a string describing the call stack.2489 * {@hide}2490 */2491 @UnsupportedAppUsage2492 public static String getCallers(final int depth) {2493 final StackTraceElement[] callStack = Thread.currentThread().getStackTrace();2494 StringBuffer sb = new StringBuffer();2495 for (int i = 0; i < depth; i++) {2496 sb.append(getCaller(callStack, i)).append(" ");2497 }2498 return sb.toString();2499 }
主要代码就是:Thread获取当前线程的堆栈元素
final StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
StackTraceElement caller = callStack[4 + depth];2482          return caller.getClassName() + "." + caller.getMethodName() + ":" + caller.getLineNumber();

StackTraceElement 打印主要信息

 

 

 

 

转载地址:http://jbfgi.baihongyu.com/

你可能感兴趣的文章
gcc编译器简介
查看>>
《C专家编程》阅读笔记
查看>>
C语言指针5分钟教程
查看>>
c/c++常见关键字
查看>>
C++内存地址分配和内存区划分简介
查看>>
C++数值交换
查看>>
指针数组、数组指针、函数指针、指针函数
查看>>
float,double在内存中的存储方式
查看>>
int main(int argc,char* argv[])详解
查看>>
C++打印地址
查看>>
ARM处理器比较:A8/A9
查看>>
ARM处理器工作模式
查看>>
ARM处理器寄存器
查看>>
汇编语言学习
查看>>
ARM寻址方式
查看>>
ARM伪指令
查看>>
协处理器
查看>>
ARM处理器启动流程
查看>>
链接地址和存储地址
查看>>
uboot工作流程分析
查看>>