OSDN Git Service

Fix NPE in ActivityRecord
authorCharles Chen <charlesccchen@google.com>
Fri, 29 Mar 2019 07:18:45 +0000 (15:18 +0800)
committerCharles Chen <charlesccchen@google.com>
Tue, 9 Apr 2019 07:11:30 +0000 (15:11 +0800)
This issue happened when we get null ActivityRecord.
Add a null check to prevent.

Also fix typo in ActivityStack.

Test: atest ActivityRecordTest
Fix: 129485624

Change-Id: I93b7dda1577b34f58fb5daed201404de4cfbad2e

services/core/java/com/android/server/wm/ActivityRecord.java
services/core/java/com/android/server/wm/ActivityStack.java

index 91ec4a0..3aeb0b4 100644 (file)
@@ -863,7 +863,7 @@ final class ActivityRecord extends ConfigurationContainer {
             name = intent.getComponent().flattenToShortString();
         }
 
-        private static ActivityRecord tokenToActivityRecordLocked(Token token) {
+        private static @Nullable ActivityRecord tokenToActivityRecordLocked(Token token) {
             if (token == null) {
                 return null;
             }
@@ -891,7 +891,7 @@ final class ActivityRecord extends ConfigurationContainer {
         }
     }
 
-    static ActivityRecord forTokenLocked(IBinder token) {
+    static @Nullable ActivityRecord forTokenLocked(IBinder token) {
         try {
             return Token.tokenToActivityRecordLocked((Token)token);
         } catch (ClassCastException e) {
@@ -2127,10 +2127,13 @@ final class ActivityRecord extends ConfigurationContainer {
     static void activityResumedLocked(IBinder token) {
         final ActivityRecord r = ActivityRecord.forTokenLocked(token);
         if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
-        if (r != null) {
-            r.icicle = null;
-            r.haveState = false;
+        if (r == null) {
+            // If an app reports resumed after a long delay, the record on server side might have
+            // been removed (e.g. destroy timeout), so the token could be null.
+            return;
         }
+        r.icicle = null;
+        r.haveState = false;
 
         final ActivityDisplay display = r.getDisplay();
         if (display != null) {
index 6bc9fc8..736df56 100644 (file)
@@ -1804,7 +1804,7 @@ class ActivityStack extends ConfigurationContainer {
             if (prev.finishing) {
                 if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev);
                 prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false,
-                        "completedPausedLocked");
+                        "completePausedLocked");
             } else if (prev.hasProcess()) {
                 if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev
                         + " wasStopping=" + wasStopping + " visible=" + prev.visible);