Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e212fa00 authored by David Duarte's avatar David Duarte
Browse files

Bluetooth{Sap,Map}: Index cache over IBinder instead of stub

Stubs are light wrappers over a Binder, index the cache over
the underlying Binder instead of the wrapper.

Bug: 310039151
Test: atest BluetoothSapTest
Change-Id: I5e2acecd1e0db8bd4a6011f60779e21b847d4b01
parent 6e5ce3cb
Loading
Loading
Loading
Loading
+35 −29
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.Context;
import android.os.Build;
import android.os.IBinder;
import android.os.IpcDataCache;
import android.os.RemoteException;
import android.util.CloseGuard;
@@ -377,21 +378,26 @@ public final class BluetoothMap implements BluetoothProfile, AutoCloseable {
        IpcDataCache.invalidateCache(IpcDataCache.MODULE_BLUETOOTH, api);
    }

    private static final IpcDataCache
            .QueryHandler<Pair<IBluetoothMap, Pair<AttributionSource, BluetoothDevice>>, Integer>
            sBluetoothConnectionQuery = new IpcDataCache.QueryHandler<>() {
    private static final IpcDataCache.QueryHandler<
                    Pair<IBinder, Pair<AttributionSource, BluetoothDevice>>, Integer>
            sBluetoothConnectionQuery =
                    new IpcDataCache.QueryHandler<>() {
                        @RequiresBluetoothConnectPermission
                        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
                        @Override
                public Integer apply(Pair<IBluetoothMap,
                        Pair<AttributionSource, BluetoothDevice>> pairQuery) {
                    IBluetoothMap service = pairQuery.first;
                        public Integer apply(
                                Pair<IBinder, Pair<AttributionSource, BluetoothDevice>> pairQuery) {
                            IBluetoothMap service = IBluetoothMap.Stub.asInterface(pairQuery.first);
                            AttributionSource source = pairQuery.second.first;
                            BluetoothDevice device = pairQuery.second.second;
                            if (DBG) {
                        log("getConnectionState(" + device.getAnonymizedAddress() + ") uncached");
                                log(
                                        "getConnectionState("
                                                + device.getAnonymizedAddress()
                                                + ") uncached");
                            }
                    final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
                            final SynchronousResultReceiver<Integer> recv =
                                    SynchronousResultReceiver.get();
                            try {
                                service.getConnectionState(device, source, recv);
                                return recv.awaitResultNoInterrupt(getSyncTimeout())
@@ -404,10 +410,10 @@ public final class BluetoothMap implements BluetoothProfile, AutoCloseable {

    private static final String GET_CONNECTION_STATE_API = "BluetoothMap_getConnectionState";

    private static final
            BluetoothCache<Pair<IBluetoothMap, Pair<AttributionSource, BluetoothDevice>>, Integer>
            sBluetoothConnectionCache = new BluetoothCache<>(GET_CONNECTION_STATE_API,
                sBluetoothConnectionQuery);
    private static final BluetoothCache<
                    Pair<IBinder, Pair<AttributionSource, BluetoothDevice>>, Integer>
            sBluetoothConnectionCache =
                    new BluetoothCache<>(GET_CONNECTION_STATE_API, sBluetoothConnectionQuery);

    /**
     * Get connection state of device
@@ -426,7 +432,7 @@ public final class BluetoothMap implements BluetoothProfile, AutoCloseable {
        } else if (isEnabled() && isValidDevice(device)) {
            try {
                return sBluetoothConnectionCache.query(
                        new Pair<>(service, new Pair<>(mAttributionSource, device)));
                        new Pair<>(service.asBinder(), new Pair<>(mAttributionSource, device)));
            } catch (RuntimeException e) {
                if (!(e.getCause() instanceof TimeoutException)
                        && !(e.getCause() instanceof RemoteException)) {
+35 −29
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.Context;
import android.os.Build;
import android.os.IBinder;
import android.os.IpcDataCache;
import android.os.RemoteException;
import android.util.CloseGuard;
@@ -374,21 +375,26 @@ public final class BluetoothSap implements BluetoothProfile, AutoCloseable {
        IpcDataCache.invalidateCache(IpcDataCache.MODULE_BLUETOOTH, api);
    }

    private static final IpcDataCache
            .QueryHandler<Pair<IBluetoothSap, Pair<AttributionSource, BluetoothDevice>>, Integer>
            sBluetoothConnectionQuery = new IpcDataCache.QueryHandler<>() {
    private static final IpcDataCache.QueryHandler<
                    Pair<IBinder, Pair<AttributionSource, BluetoothDevice>>, Integer>
            sBluetoothConnectionQuery =
                    new IpcDataCache.QueryHandler<>() {
                        @RequiresBluetoothConnectPermission
                        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
                        @Override
                public Integer apply(Pair<IBluetoothSap,
                        Pair<AttributionSource, BluetoothDevice>> pairQuery) {
                    IBluetoothSap service = pairQuery.first;
                        public Integer apply(
                                Pair<IBinder, Pair<AttributionSource, BluetoothDevice>> pairQuery) {
                            IBluetoothSap service = IBluetoothSap.Stub.asInterface(pairQuery.first);
                            AttributionSource source = pairQuery.second.first;
                            BluetoothDevice device = pairQuery.second.second;
                            if (DBG) {
                        log("getConnectionState(" + device.getAnonymizedAddress() + ") uncached");
                                log(
                                        "getConnectionState("
                                                + device.getAnonymizedAddress()
                                                + ") uncached");
                            }
                    final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
                            final SynchronousResultReceiver<Integer> recv =
                                    SynchronousResultReceiver.get();
                            try {
                                service.getConnectionState(device, source, recv);
                                return recv.awaitResultNoInterrupt(getSyncTimeout())
@@ -401,10 +407,10 @@ public final class BluetoothSap implements BluetoothProfile, AutoCloseable {

    private static final String GET_CONNECTION_STATE_API = "BluetoothSap_getConnectionState";

    private static final
            BluetoothCache<Pair<IBluetoothSap, Pair<AttributionSource, BluetoothDevice>>, Integer>
            sBluetoothConnectionCache = new BluetoothCache<>(GET_CONNECTION_STATE_API,
                sBluetoothConnectionQuery);
    private static final BluetoothCache<
                    Pair<IBinder, Pair<AttributionSource, BluetoothDevice>>, Integer>
            sBluetoothConnectionCache =
                    new BluetoothCache<>(GET_CONNECTION_STATE_API, sBluetoothConnectionQuery);

    /**
     * Get connection state of device
@@ -423,7 +429,7 @@ public final class BluetoothSap implements BluetoothProfile, AutoCloseable {
        } else if (isEnabled() && isValidDevice(device)) {
            try {
                return sBluetoothConnectionCache.query(
                        new Pair<>(service, new Pair<>(mAttributionSource, device)));
                        new Pair<>(service.asBinder(), new Pair<>(mAttributionSource, device)));
            } catch (RuntimeException e) {
                if (!(e.getCause() instanceof TimeoutException)
                        && !(e.getCause() instanceof RemoteException)) {