diff options
author | Pinyao Ting <pinyaoting@google.com> | 2022-06-29 17:05:23 -0700 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-07-29 22:35:35 +0000 |
commit | 9c2b2c7b2ca2d1eebea485d453460f3b7f9ccf68 (patch) | |
tree | cd6cf4507b1a6aa77815d4b37341003afcc325fb | |
parent | 07a5b5962779c4e8974c30c600427732b7799381 (diff) | |
download | base-9c2b2c7b2ca2d1eebea485d453460f3b7f9ccf68.tar.gz |
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
2 files changed, 2 insertions, 24 deletions
diff --git a/services/appprediction/java/com/android/server/appprediction/AppPredictionPerUserService.java b/services/appprediction/java/com/android/server/appprediction/AppPredictionPerUserService.java index 1af8ad344190..84707a8d9c00 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 @@ public class AppPredictionPerUserService extends 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 dcffc9e73c0e..f041fbd7bf90 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 @@ public class SmartspacePerUserService extends @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, |