OSDN Git Service

Fix: WindowManagerGlobal#setStoppedState failed by IOOBE
authorTetsutoki Shiozawa <tetsutoki.shiozawa@sony.com>
Wed, 1 Nov 2017 02:38:34 +0000 (11:38 +0900)
committerTakamasa Kuramitsu <takamasa.kuramitsu@sony.com>
Wed, 8 Nov 2017 07:46:09 +0000 (16:46 +0900)
Symptom:
An application crashed due to IndexOutOfBoundsException.
The exception was thrown at WindowManagerGlobal#setStoppedState.

Root cause:
setStoppedState invokes setWindowStopped for each ViewRoot by
ascending order. If an application removes its view within the
loop, loop index exceeds the number of items.

Solution:
Loop in descending order.

Bug: 69018607
Change-Id: I7e20282dc99b767912be4e00d81ffb49fe6c7ac0

core/java/android/view/WindowManagerGlobal.java

index c7e8dee..cca66d6 100644 (file)
@@ -605,9 +605,10 @@ public final class WindowManagerGlobal {
     public void setStoppedState(IBinder token, boolean stopped) {
         synchronized (mLock) {
             int count = mViews.size();
-            for (int i = 0; i < count; i++) {
+            for (int i = count - 1; i >= 0; i--) {
                 if (token == null || mParams.get(i).token == token) {
                     ViewRootImpl root = mRoots.get(i);
+                    // Client might remove the view by "stopped" event.
                     root.setWindowStopped(stopped);
                 }
             }