From 8dc35ad2b179ad35eee6206c340e0874b45aaba3 Mon Sep 17 00:00:00 2001 From: Pinyao Ting Date: Thu, 28 Jul 2022 15:26:24 -0700 Subject: [PATCH] Include descriptor in Binder token for AppPredictor Adding a descriptor in Binder token can help us identifying potential binder proxy leaks in the future. This CL also made the Binder token static. Binder token serves as an indicator of the termination of a process, there's no reason in making multiple Binder token since when the process dies, they all dies. Bug: 240329370 Test: manual Change-Id: I26969395d704aa6518ef9d834951f856d74924b7 --- core/java/android/app/prediction/AppPredictor.java | 13 +++++++++---- .../android/app/smartspace/SmartspaceSession.java | 11 +++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core/java/android/app/prediction/AppPredictor.java b/core/java/android/app/prediction/AppPredictor.java index db3a1921c1ba1..2581daa2f68bb 100644 --- a/core/java/android/app/prediction/AppPredictor.java +++ b/core/java/android/app/prediction/AppPredictor.java @@ -74,7 +74,6 @@ public final class AppPredictor { private static final String TAG = AppPredictor.class.getSimpleName(); - private final IPredictionManager mPredictionManager; private final CloseGuard mCloseGuard = CloseGuard.get(); private final AtomicBoolean mIsClosed = new AtomicBoolean(false); @@ -82,8 +81,6 @@ public final class AppPredictor { private final AppPredictionSessionId mSessionId; private final ArrayMap mRegisteredCallbacks = new ArrayMap<>(); - private final IBinder mToken = new Binder(); - /** * Creates a new Prediction client. *

@@ -99,7 +96,7 @@ public final class AppPredictor { mSessionId = new AppPredictionSessionId( context.getPackageName() + ":" + UUID.randomUUID().toString(), context.getUserId()); try { - mPredictionManager.createPredictionSession(predictionContext, mSessionId, mToken); + mPredictionManager.createPredictionSession(predictionContext, mSessionId, getToken()); } catch (RemoteException e) { Log.e(TAG, "Failed to create predictor", e); e.rethrowAsRuntimeException(); @@ -324,4 +321,12 @@ public final class AppPredictor { } } } + + private static class Token { + static final IBinder sBinder = new Binder(TAG); + } + + private static IBinder getToken() { + return Token.sBinder; + } } diff --git a/core/java/android/app/smartspace/SmartspaceSession.java b/core/java/android/app/smartspace/SmartspaceSession.java index b523be2cc7e91..3658ffc374fc2 100644 --- a/core/java/android/app/smartspace/SmartspaceSession.java +++ b/core/java/android/app/smartspace/SmartspaceSession.java @@ -83,7 +83,6 @@ public final class SmartspaceSession implements AutoCloseable { private final SmartspaceSessionId mSessionId; private final ArrayMap mRegisteredCallbacks = new ArrayMap<>(); - private final IBinder mToken = new Binder(); /** * Creates a new Smartspace ui client. @@ -101,7 +100,7 @@ public final class SmartspaceSession implements AutoCloseable { mSessionId = new SmartspaceSessionId( context.getPackageName() + ":" + UUID.randomUUID().toString(), context.getUser()); try { - mInterface.createSmartspaceSession(smartspaceConfig, mSessionId, mToken); + mInterface.createSmartspaceSession(smartspaceConfig, mSessionId, getToken()); } catch (RemoteException e) { Log.e(TAG, "Failed to create Smartspace session", e); e.rethrowFromSystemServer(); @@ -283,4 +282,12 @@ public final class SmartspaceSession implements AutoCloseable { } } } + + private static class Token { + static final IBinder sBinder = new Binder(TAG); + } + + private static IBinder getToken() { + return Token.sBinder; + } }