From 978e7f87cc0c1d2ff140694ec150c8eca10bfee6 Mon Sep 17 00:00:00 2001 From: Tetsutoki Shiozawa Date: Wed, 1 Nov 2017 11:38:34 +0900 Subject: Fix: WindowManagerGlobal#setStoppedState failed by IOOBE 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core/java/android/view/WindowManagerGlobal.java') diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java index c7e8dee3da83..cca66d6b8ae0 100644 --- a/core/java/android/view/WindowManagerGlobal.java +++ b/core/java/android/view/WindowManagerGlobal.java @@ -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); } } -- cgit v1.2.3