@@ -970,7 +970,8 @@ public void handleMessage(Message msg) {
970970
971971 if (mShowDialogs) {
972972 Dialog d = new AppNotRespondingDialog(ActivityManagerService.this,
973- mContext, proc, (ActivityRecord)data.get("activity"));
973+ mContext, proc, (ActivityRecord)data.get("activity"),
974+ msg.arg1 != 0);
974975 d.show();
975976 proc.anrDialog = d;
976977 } else {
@@ -3247,7 +3248,7 @@ final void logAppTooSlow(ProcessRecord app, long startTime, String msg) {
32473248 }
32483249
32493250 final void appNotResponding(ProcessRecord app, ActivityRecord activity,
3250- ActivityRecord parent, final String annotation) {
3251+ ActivityRecord parent, boolean aboveSystem, final String annotation) {
32513252 ArrayList<Integer> firstPids = new ArrayList<Integer>(5);
32523253 SparseArray<Boolean> lastPids = new SparseArray<Boolean>(20);
32533254
@@ -3388,6 +3389,7 @@ final void appNotResponding(ProcessRecord app, ActivityRecord activity,
33883389 HashMap map = new HashMap();
33893390 msg.what = SHOW_NOT_RESPONDING_MSG;
33903391 msg.obj = map;
3392+ msg.arg1 = aboveSystem ? 1 : 0;
33913393 map.put("app", app);
33923394 if (activity != null) {
33933395 map.put("activity", activity);
@@ -7340,6 +7342,51 @@ public void requestBugReport() {
73407342 SystemProperties.set("ctl.start", "bugreport");
73417343 }
73427344
7345+ public long inputDispatchingTimedOut(int pid, boolean aboveSystem) {
7346+ if (checkCallingPermission(android.Manifest.permission.FILTER_EVENTS)
7347+ != PackageManager.PERMISSION_GRANTED) {
7348+ throw new SecurityException("Requires permission "
7349+ + android.Manifest.permission.FILTER_EVENTS);
7350+ }
7351+
7352+ ProcessRecord proc;
7353+
7354+ // TODO: Unify this code with ActivityRecord.keyDispatchingTimedOut().
7355+ synchronized (this) {
7356+ synchronized (mPidsSelfLocked) {
7357+ proc = mPidsSelfLocked.get(pid);
7358+ }
7359+ if (proc != null) {
7360+ if (proc.debugging) {
7361+ return -1;
7362+ }
7363+
7364+ if (mDidDexOpt) {
7365+ // Give more time since we were dexopting.
7366+ mDidDexOpt = false;
7367+ return -1;
7368+ }
7369+
7370+ if (proc.instrumentationClass != null) {
7371+ Bundle info = new Bundle();
7372+ info.putString("shortMsg", "keyDispatchingTimedOut");
7373+ info.putString("longMsg", "Timed out while dispatching key event");
7374+ finishInstrumentationLocked(proc, Activity.RESULT_CANCELED, info);
7375+ proc = null;
7376+ }
7377+ }
7378+ }
7379+
7380+ if (proc != null) {
7381+ appNotResponding(proc, null, null, aboveSystem, "keyDispatchingTimedOut");
7382+ if (proc.instrumentationClass != null || proc.usingWrapper) {
7383+ return INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT;
7384+ }
7385+ }
7386+
7387+ return KEY_DISPATCHING_TIMEOUT;
7388+ }
7389+
73437390 public void registerProcessObserver(IProcessObserver observer) {
73447391 enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER,
73457392 "registerProcessObserver()");
0 commit comments