From 000b8e8255dae886cadaddbc58c33824b8456cf1 Mon Sep 17 00:00:00 2001 From: Jing Ji Date: Mon, 14 Feb 2022 17:06:25 -0800 Subject: [PATCH] Safe guard the service type in the app fgs tracker. Bug: 219542109 Test: Manual - start an instant app with FGS. Change-Id: I1715bf18462c7a02233cfe662be0a74abf6a8bcd --- .../com/android/server/am/AppFGSTracker.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/am/AppFGSTracker.java b/services/core/java/com/android/server/am/AppFGSTracker.java index 5ac5a70ccf74e..075402f108821 100644 --- a/services/core/java/com/android/server/am/AppFGSTracker.java +++ b/services/core/java/com/android/server/am/AppFGSTracker.java @@ -560,20 +560,22 @@ final class AppFGSTracker extends BaseAppStateDurationsTracker(); - } - if (!isActive(i)) { - mEvents[i].add(new BaseTimeEvent(now)); - notifyListenersOnStateChangeIfNecessary(true, now, serviceType); - } - } else { - // Stop this type. - if (mEvents[i] != null && isActive(i)) { - mEvents[i].add(new BaseTimeEvent(now)); - notifyListenersOnStateChangeIfNecessary(false, now, serviceType); + if (i < mEvents.length) { + if ((serviceTypes & serviceType) != 0) { + // Start this type. + if (mEvents[i] == null) { + mEvents[i] = new LinkedList<>(); + } + if (!isActive(i)) { + mEvents[i].add(new BaseTimeEvent(now)); + notifyListenersOnStateChangeIfNecessary(true, now, serviceType); + } + } else { + // Stop this type. + if (mEvents[i] != null && isActive(i)) { + mEvents[i].add(new BaseTimeEvent(now)); + notifyListenersOnStateChangeIfNecessary(false, now, serviceType); + } } } changes &= ~serviceType;