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
diff --git a/services/core/java/com/android/server/am/TaskChangeNotificationController.java b/services/core/java/com/android/server/am/TaskChangeNotificationController.java
index 5a7e7ce..7896e2d 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 @@
     };
 
     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 @@
     /** 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();
     }