Fix AppPrediction/Smartspace leak

AppPrediction and Smartspace session info are associated with two types of Binder objects: one maps to the client object (i.e. AppPredictor/SmartspaceSession) that represents the session itself, the other one maps to the callback functions that handles incoming update at the client side.

The death recipient of the former performs the clean-up which removes
the session info object from system process followed by calling a destroy on the session info object, while the other one simply calls destroy.

Unfortunately upon destroy of the session info object, we unlink the
former from its death recipient, which means if the callback function
objects died before the session object in the client process, the death recipient is unlinked, therefore the clean-up will not be performed.

Both the callback function object and the session info object lives in the same process, when the process dies, both object dies, so there's no reason to having cleanup logic in both places.

This CL removes the death recipient associated with the callback in favor of the one associated with the session since the later provides more coverage, e.g. in case the process died before it start listening to prediction updates.

Bug: 230696939
Test: manual
Change-Id: I27641d347c2b436eaafba306842854a97a440f7a
(cherry picked from commit f9ba3f64c07fd5fc6b93523e78751dbe26a93400)
Merged-In: I27641d347c2b436eaafba306842854a97a440f7a
diff --git a/services/appprediction/java/com/android/server/appprediction/AppPredictionPerUserService.java b/services/appprediction/java/com/android/server/appprediction/AppPredictionPerUserService.java
index 1af8ad3..84707a8 100644
--- a/services/appprediction/java/com/android/server/appprediction/AppPredictionPerUserService.java
+++ b/services/appprediction/java/com/android/server/appprediction/AppPredictionPerUserService.java
@@ -398,18 +398,7 @@
         final IBinder.DeathRecipient mDeathRecipient;
 
         private final RemoteCallbackList<IPredictionCallback> mCallbacks =
-                new RemoteCallbackList<IPredictionCallback>() {
-                    @Override
-                    public void onCallbackDied(IPredictionCallback callback) {
-                        if (DEBUG) {
-                            Slog.d(TAG, "Binder died for session Id=" + mSessionId
-                                    + " and callback=" + callback.asBinder());
-                        }
-                        if (mCallbacks.getRegisteredCallbackCount() == 0) {
-                            destroy();
-                        }
-                    }
-                };
+                new RemoteCallbackList<>();
 
         AppPredictionSessionInfo(
                 @NonNull final AppPredictionSessionId id,
diff --git a/services/smartspace/java/com/android/server/smartspace/SmartspacePerUserService.java b/services/smartspace/java/com/android/server/smartspace/SmartspacePerUserService.java
index dcffc9e..f041fbd 100644
--- a/services/smartspace/java/com/android/server/smartspace/SmartspacePerUserService.java
+++ b/services/smartspace/java/com/android/server/smartspace/SmartspacePerUserService.java
@@ -334,18 +334,7 @@
         @NonNull
         private final SmartspaceConfig mSmartspaceConfig;
         private final RemoteCallbackList<ISmartspaceCallback> mCallbacks =
-                new RemoteCallbackList<ISmartspaceCallback>() {
-                    @Override
-                    public void onCallbackDied(ISmartspaceCallback callback) {
-                        if (DEBUG) {
-                            Slog.d(TAG, "Binder died for session Id=" + mSessionId
-                                    + " and callback=" + callback.asBinder());
-                        }
-                        if (mCallbacks.getRegisteredCallbackCount() == 0) {
-                            destroy();
-                        }
-                    }
-                };
+                new RemoteCallbackList<>();
 
         SmartspaceSessionInfo(
                 @NonNull final SmartspaceSessionId id,