Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7dd5bb18 authored by Michael Wright's avatar Michael Wright
Browse files

Unify inputDispatchingTimedOut with keyDispatchingTimedOut

Bug: 8194916
Change-Id: Iac40108d848bcca77f49a7a49c57a095b3dbe9c9
parent 5633e23c
Loading
Loading
Loading
Loading
+43 −16
Original line number Diff line number Diff line
@@ -7234,29 +7234,63 @@ public final class ActivityManagerService extends ActivityManagerNative
        SystemProperties.set("ctl.start", "bugreport");
    }
    public static long getInputDispatchingTimeoutLocked(ActivityRecord r) {
        return r != null ? getInputDispatchingTimeoutLocked(r.app) : KEY_DISPATCHING_TIMEOUT;
    }
    public static long getInputDispatchingTimeoutLocked(ProcessRecord r) {
        if (r != null && (r.instrumentationClass != null || r.usingWrapper)) {
            return INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT;
        }
        return KEY_DISPATCHING_TIMEOUT;
    }
    public long inputDispatchingTimedOut(int pid, final boolean aboveSystem) {
        if (checkCallingPermission(android.Manifest.permission.FILTER_EVENTS)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires permission "
                    + android.Manifest.permission.FILTER_EVENTS);
        }
        ProcessRecord proc;
        // TODO: Unify this code with ActivityRecord.keyDispatchingTimedOut().
        long timeout;
        synchronized (this) {
            synchronized (mPidsSelfLocked) {
                proc = mPidsSelfLocked.get(pid);
            }
            timeout = getInputDispatchingTimeoutLocked(proc);
        }
        if (!inputDispatchingTimedOut(proc, null, null, aboveSystem)) {
            return -1;
        }
        return timeout;
    }
    /**
     * Handle input dispatching timeouts.
     * Returns whether input dispatching should be aborted or not.
     */
    public boolean inputDispatchingTimedOut(final ProcessRecord proc,
            final ActivityRecord activity, final ActivityRecord parent,
            final boolean aboveSystem) {
        if (checkCallingPermission(android.Manifest.permission.FILTER_EVENTS)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Requires permission "
                    + android.Manifest.permission.FILTER_EVENTS);
        }
        if (proc != null) {
            synchronized (this) {
                if (proc.debugging) {
                    return -1;
                    return false;
                }
                if (mDidDexOpt) {
                    // Give more time since we were dexopting.
                    mDidDexOpt = false;
                    return -1;
                    return false;
                }
                if (proc.instrumentationClass != null) {
@@ -7264,25 +7298,18 @@ public final class ActivityManagerService extends ActivityManagerNative
                    info.putString("shortMsg", "keyDispatchingTimedOut");
                    info.putString("longMsg", "Timed out while dispatching key event");
                    finishInstrumentationLocked(proc, Activity.RESULT_CANCELED, info);
                    proc = null;
                }
                    return true;
                }
            }
        if (proc != null) {
            final ProcessRecord pr = proc;
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    appNotResponding(pr, null, null, aboveSystem, "keyDispatchingTimedOut");
                    appNotResponding(proc, activity, parent, aboveSystem, "keyDispatchingTimedOut");
                }
            });
            if (proc.instrumentationClass != null || proc.usingWrapper) {
                return INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT;
            }
        }
        return KEY_DISPATCHING_TIMEOUT;
        return true;
    }
    public Bundle getTopActivityExtras(int requestType) {
+4 −35
Original line number Diff line number Diff line
@@ -871,51 +871,20 @@ final class ActivityRecord {
    }

    public boolean keyDispatchingTimedOut() {
        // TODO: Unify this code with ActivityManagerService.inputDispatchingTimedOut().
        ActivityRecord r;
        ProcessRecord anrApp = null;
        ProcessRecord anrApp;
        synchronized(service) {
            r = getWaitingHistoryRecordLocked();
            if (r != null && r.app != null) {
                if (r.app.debugging) {
                    return false;
                }
                
                if (service.mDidDexOpt) {
                    // Give more time since we were dexopting.
                    service.mDidDexOpt = false;
                    return false;
                }
                
                if (r.app.instrumentationClass == null) { 
                    anrApp = r.app;
                } else {
                    Bundle info = new Bundle();
                    info.putString("shortMsg", "keyDispatchingTimedOut");
                    info.putString("longMsg", "Timed out while dispatching key event");
                    service.finishInstrumentationLocked(
                            r.app, Activity.RESULT_CANCELED, info);
                }
            anrApp = r != null ? r.app : null;
        }
        }
        
        if (anrApp != null) {
            service.appNotResponding(anrApp, r, this, false, "keyDispatchingTimedOut");
        }
        
        return true;
        return service.inputDispatchingTimedOut(anrApp, r, this, false);
    }
    
    /** Returns the key dispatching timeout for this application token. */
    public long getKeyDispatchingTimeout() {
        synchronized(service) {
            ActivityRecord r = getWaitingHistoryRecordLocked();
            if (r != null && r.app != null
                    && (r.app.instrumentationClass != null || r.app.usingWrapper)) {
                return ActivityManagerService.INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT;
            }

            return ActivityManagerService.KEY_DISPATCHING_TIMEOUT;
            return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
        }
    }