diff options
| author | 2016-08-09 17:30:13 -0700 | |
|---|---|---|
| committer | 2016-08-09 17:30:13 -0700 | |
| commit | 83ea55a9c60ca52873ffc752d92fa3e05e5bd3ac (patch) | |
| tree | c53989bad92c2c81a847defd6cf2bede864edbc5 | |
| parent | 002dd297646b231c6569185ba4371cb47803309c (diff) | |
Fix setVrThread's exception handling.
Bug: 30746129
Change-Id: I49ee29f12b52c9f9f5f061508c5cc8c89fd1cd11
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index e336ed5e34ab..ee15cc88dead 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -12566,23 +12566,33 @@ public final class ActivityManagerService extends ActivityManagerNative synchronized (mPidsSelfLocked) { final int pid = Binder.getCallingPid(); proc = mPidsSelfLocked.get(pid); + if (proc != null && mInVrMode && tid >= 0) { // ensure the tid belongs to the process if (!Process.isThreadInProcess(pid, tid)) { throw new IllegalArgumentException("VR thread does not belong to process"); } - // reset existing VR thread to CFS - if (proc.vrThreadTid != 0) { - Process.setThreadScheduler(proc.vrThreadTid, Process.SCHED_OTHER, 0); + + // reset existing VR thread to CFS if this thread still exists and belongs to + // the calling process + if (proc.vrThreadTid != 0 + && Process.isThreadInProcess(pid, proc.vrThreadTid)) { + try { + Process.setThreadScheduler(proc.vrThreadTid, Process.SCHED_OTHER, 0); + } catch (IllegalArgumentException e) { + // Ignore this. Only occurs in race condition where previous VR thread + // was destroyed during this method call. + } } - // add check to guarantee that tid belongs to pid? + proc.vrThreadTid = tid; + // promote to FIFO now if the tid is non-zero - if (proc.curSchedGroup == ProcessList.SCHED_GROUP_TOP_APP && proc.vrThreadTid > 0) { - Process.setThreadScheduler(proc.vrThreadTid, Process.SCHED_FIFO | Process.SCHED_RESET_ON_FORK, 1); + if (proc.curSchedGroup == ProcessList.SCHED_GROUP_TOP_APP + && proc.vrThreadTid > 0) { + Process.setThreadScheduler(proc.vrThreadTid, + Process.SCHED_FIFO | Process.SCHED_RESET_ON_FORK, 1); } - } else { - //Slog.e("VR_FIFO", "Didn't set thread from setVrThread?"); } } } |