前言
大家都知道组件的执行任务的时间过长可能会导致ANR,但具体是多久呢?源码里面都定义了宏,我们把它们找出来,做了记录
正文
Service Timeout
文件:ActiveServices.java
// How long we wait for a service to finish executing.
static final int SERVICE_TIMEOUT = 20*1000; // 前台
// How long we wait for a service to finish executing.
static final int SERVICE_BACKGROUND_TIMEOUT = SERVICE_TIMEOUT * 10; // 后台
broadcast Timeout
文件:ActivityManagerService.java
// How long we allow a receiver to run before giving up on it.
static final int BROADCAST_FG_TIMEOUT = 10*1000; // 前台
static final int BROADCAST_BG_TIMEOUT = 60*1000; // 后台
InputDispatching Timeout
文件:ActivityManagerService.java
// How long we wait until we timeout on key dispatching.
static final int KEY_DISPATCHING_TIMEOUT = 5*1000;
ContentProvider Timeout
文件:
// How long we wait for an attached process to publish its content providers
// before we decide it must be hung.
static final int CONTENT_PROVIDER_PUBLISH_TIMEOUT = 10*1000;
这个时间的统计区间是在System_Server进程调用startProcessLocked之后会调用AMS.attachApplicationLocked,以这为起点,一直到provider进程installProvider以及publishContentProviders,调用到AMS.publishContentProviders为止。超过了这个时间就会系统就会杀掉Provider进程