(未完待续)

在Android中,对于App error有一个集中管理类:com.android.server.am.AppErrors

AppErrors.java

 // 处理ANR void handleShowAnrUi(Message msg)
 // 处理Crash void handleShowAppErrorUi(Message msg)
 boolean handleAppCrashLocked(ProcessRecord app, String reason, String shortMsg, String longMsg, String stackTrace, AppErrorDialog.Data data)

ANR调用顺序

InputManager.cpp

  status_t InputManager::start() {         status_t result = mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY);         // .......  }

InputDispatcher.cpp

  bool InputDispatcherThread::threadLoop() {      mDispatcher->dispatchOnce();      return true;  }

InputDispatcher.cpp

  void InputDispatcher::dispatchOnce() {         // .......         dispatchOnceInnerLocked(&nextWakeupTime);         // .......  }

InputDispatcher.cpp

  void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {         // .......         done = dispatchMotionLocked(currentTime, typedEntry,            &dropReason, nextWakeupTime);         // .......  }

InputDispatcher.cpp

  bool InputDispatcher::dispatchMotionLocked(nsecs_t currentTime, MotionEntry* entry,                          DropReason* dropReason, nsecs_t* nextWakeupTime) {         // .......         if (isPointerEvent) {               // Pointer event.  (eg. touchscreen)               injectionResult = findTouchedWindowTargetsLocked(currentTime, entry, inputTargets,                                  nextWakeupTime, &conflictingPointerActions);         } else {               // Non touch event.  (eg. trackball)               injectionResult = findFocusedWindowTargetsLocked(currentTime, entry, inputTargets,                                  nextWakeupTime);         }         // .......  }

InputDispatcher.cpp

  int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime, const EventEntry* entry,                     Vector& inputTargets, nsecs_t* nextWakeupTime) {         // .......         injectionResult = handleTargetsNotReadyLocked(currentTime, entry,                mFocusedApplicationHandle, NULL, nextWakeupTime,                "Waiting because no window has focus but there is a "                "focused application that may eventually add a window "                "when it finishes starting up.");         // .......         injectionResult = handleTargetsNotReadyLocked(currentTime, entry,            mFocusedApplicationHandle, mFocusedWindowHandle, nextWakeupTime, reason.string());         // ......  }  int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime,                 const MotionEntry* entry, Vector& inputTargets,                 nsecs_t* nextWakeupTime, bool* outConflictingPointerActions) {        // .......        injectionResult = handleTargetsNotReadyLocked(currentTime, entry,                    NULL, touchedWindow.windowHandle, nextWakeupTime, reason.string());        // .......  }

InputDispatcher.cpp

  int32_t InputDispatcher::handleTargetsNotReadyLocked(nsecs_t currentTime, const EventEntry* entry,                                const sp& applicationHandle,                                const sp& windowHandle,                                nsecs_t* nextWakeupTime, const char* reason) {        // ......        onANRLocked(currentTime, applicationHandle, windowHandle, entry->eventTime, mInputTargetWaitStartTime, reason);        // ......  }

InputDispatcher.cpp

  void InputDispatcher::onANRLocked(nsecs_t currentTime, const sp& applicationHandle,                const sp& windowHandle, nsecs_t eventTime,                 nsecs_t waitStartTime, const char* reason) {        // ......        CommandEntry* commandEntry = postCommandLocked(& InputDispatcher::doNotifyANRLockedInterruptible);        // ......  }

InputDispatcher.cpp

  void InputDispatcher::doNotifyANRLockedInterruptible(CommandEntry* commandEntry) {        // ......        nsecs_t newTimeout = mPolicy->notifyANR(commandEntry->inputApplicationHandle,                       commandEntry->inputWindowHandle, commandEntry->reason);        // ......  }

com_android_server_input_InputManagerService.cpp

  nsecs_t NativeInputManager::notifyANR(const sp& inputApplicationHandle,    const sp& inputWindowHandle, const String8& reason) {        // ......        jlong newTimeout = env->CallLongMethod(mServiceObj,            gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,            reasonObj);        // ......  }

InputManagerService.java

  private long notifyANR(InputApplicationHandle inputApplicationHandle,        InputWindowHandle inputWindowHandle, String reason) {        return mWindowManagerCallbacks.notifyANR(            inputApplicationHandle, inputWindowHandle, reason);  }

InputMonitor.java

  @Override  public long notifyANR(InputApplicationHandle inputApplicationHandle,        InputWindowHandle inputWindowHandle, String reason) {        // ......        long timeout = ActivityManagerNative.getDefault().inputDispatchingTimedOut(                    windowState.mSession.mPid, aboveSystem, reason);        // ......  }

ActivityManagerService.java

  @Override  public long inputDispatchingTimedOut(int pid, final boolean aboveSystem, String reason) {        // ......        if (!inputDispatchingTimedOut(proc, null, null, aboveSystem, reason)) {              return -1;        }        // ......  }

ActivityManagerService.java

  public boolean inputDispatchingTimedOut(final ProcessRecord proc,        final ActivityRecord activity, final ActivityRecord parent,        final boolean aboveSystem, String reason) {        // ......        mAppErrors.appNotResponding(proc, activity, parent, aboveSystem, annotation);        // ......  }

AppErrors.java

  final void appNotResponding(ProcessRecord app, ActivityRecord activity,         ActivityRecord parent, boolean aboveSystem, final String annotation) {        // ......        msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG;        msg.obj = map;        msg.arg1 = aboveSystem ? 1 : 0;        // ......        mService.mUiHandler.sendMessage(msg);  }

ActivityManagerService$UiHandler.java

  @Override  public void handleMessage(Message msg) {        switch (msg.what) {        // .......        case SHOW_NOT_RESPONDING_UI_MSG: {            mAppErrors.handleShowAnrUi(msg);            ensureBootCompleted();        } break;        // .......        }  }

AppErrors.java

  void handleShowAnrUi(Message msg) {        // .......  }

更多相关文章

  1. Android(安卓)代码片段---从相册或相机获取图片保存并处理
  2. android 调用系统自带录音实现,语音录制与播放
  3. android 横竖屏
  4. 分享一个Android日志记录的工具类
  5. Android(安卓)上实现微信微博上的应用语言切换
  6. Android标题栏(titlebar)显示进度条
  7. Android中调用摄像头并实现对焦拍照
  8. android proguard 错误处理
  9. API 23及之后版本关于用android studio 中LocationManager的方法

随机推荐

  1. Android中常见的内存泄漏之上下文对象
  2. [Android]反编译查看、修改源码、逆向分
  3. Android仿UC浏览器左右上下滚动功能(附源
  4. Android(安卓)如何正确使用我们的图片资
  5. Android学习笔记之界面控件大小dip及布局
  6. Android(安卓)Studio apk打包,keystore.jk
  7. Kotlin系列——在Android中使用协程以及
  8. AsyncTask的使用和原理探究(一)
  9. android解决屏幕适配问题
  10. 教你如何在Android(安卓)6.0上创建系统悬