From b7cf0638b9a65d8531a7113dae90191c08ce561e Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Tue, 7 Nov 2017 13:20:53 -0800 Subject: [PATCH] Fix NPE notifyActivityPinned It is possible an activity is removed from it task before the notifyActivityPinned call is processed. To avoid this we now add the relevant information to the message before posting. Change-Id: Ib65dee1db3033568d2385703edc92ca4bfd12549 Fixes: 68918788 Test: go/wm-smoke --- .../com/android/server/am/TaskChangeNotificationController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/am/TaskChangeNotificationController.java b/services/core/java/com/android/server/am/TaskChangeNotificationController.java index 5a7e7ced930c..7896e2dd9883 100644 --- a/services/core/java/com/android/server/am/TaskChangeNotificationController.java +++ b/services/core/java/com/android/server/am/TaskChangeNotificationController.java @@ -95,8 +95,8 @@ class TaskChangeNotificationController { }; private final TaskStackConsumer mNotifyActivityPinned = (l, m) -> { - final ActivityRecord r = (ActivityRecord) m.obj; - l.onActivityPinned(r.packageName, r.userId, r.getTask().taskId, r.getStackId()); + l.onActivityPinned((String) m.obj /* packageName */, m.sendingUid /* userId */, + m.arg1 /* taskId */, m.arg2 /* stackId */); }; private final TaskStackConsumer mNotifyActivityUnpinned = (l, m) -> { @@ -281,7 +281,9 @@ class TaskChangeNotificationController { /** Notifies all listeners when an Activity is pinned. */ void notifyActivityPinned(ActivityRecord r) { mHandler.removeMessages(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG); - final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG, r); + final Message msg = mHandler.obtainMessage(NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG, + r.getTask().taskId, r.getStackId(), r.packageName); + msg.sendingUid = r.userId; forAllLocalListeners(mNotifyActivityPinned, msg); msg.sendToTarget(); } -- 2.11.0