Tag some "new Binder()" instances to detect leaks.

We've seen evidence of a Binder leak, and our hunch is that it's
caused by one of these anonymous "new Binder()" sites.  Adding
descriptors will help us identify the leak cause.

Bug: 192415943
Test: atest BluetoothInstrumentationTests
Change-Id: I30cd15f084cf50f67edd833b27b853c4b22e1db1
This commit is contained in:
Jeff Sharkey
2021-07-07 17:17:04 -06:00
parent 5f5e03d3ef
commit 79b834d47c
2 changed files with 7 additions and 4 deletions

View File

@@ -120,6 +120,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
*/
public final class BluetoothAdapter {
private static final String TAG = "BluetoothAdapter";
private static final String DESCRIPTOR = "android.bluetooth.BluetoothAdapter";
private static final boolean DBG = true;
private static final boolean VDBG = false;
@@ -805,7 +806,7 @@ public final class BluetoothAdapter {
mManagerService = Objects.requireNonNull(managerService);
mAttributionSource = Objects.requireNonNull(attributionSource);
mLeScanClients = new HashMap<LeScanCallback, ScanCallback>();
mToken = new Binder();
mToken = new Binder(DESCRIPTOR);
}
/**

View File

@@ -86,6 +86,8 @@ import java.util.Set;
*/
@Immutable
public final class AttributionSource implements Parcelable {
private static final String DESCRIPTOR = "android.content.AttributionSource";
private final @NonNull AttributionSourceState mAttributionSourceState;
private @Nullable AttributionSource mNextCached;
@@ -95,7 +97,7 @@ public final class AttributionSource implements Parcelable {
@TestApi
public AttributionSource(int uid, @Nullable String packageName,
@Nullable String attributionTag) {
this(uid, packageName, attributionTag, new Binder());
this(uid, packageName, attributionTag, new Binder(DESCRIPTOR));
}
/** @hide */
@@ -130,7 +132,7 @@ public final class AttributionSource implements Parcelable {
AttributionSource(int uid, @Nullable String packageName, @Nullable String attributionTag,
@Nullable String[] renouncedPermissions, @Nullable AttributionSource next) {
this(uid, packageName, attributionTag, new Binder(), renouncedPermissions, next);
this(uid, packageName, attributionTag, new Binder(DESCRIPTOR), renouncedPermissions, next);
}
AttributionSource(int uid, @Nullable String packageName, @Nullable String attributionTag,
@@ -541,7 +543,7 @@ public final class AttributionSource implements Parcelable {
if ((mBuilderFieldsSet & 0x10) == 0) {
mAttributionSourceState.next = null;
}
mAttributionSourceState.token = new Binder();
mAttributionSourceState.token = new Binder(DESCRIPTOR);
if (mAttributionSourceState.next == null) {
// The NDK aidl backend doesn't support null parcelable arrays.
mAttributionSourceState.next = new AttributionSourceState[0];