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

Commit 4d6863f3 authored by Rongxuan Liu's avatar Rongxuan Liu
Browse files

Add support to connect LE Gatt with address type (1/2)

Bug: 266449499
Tag: #feature
Test: atest BluetoothInstrumentationTests; atest GattServiceTest
Change-Id: I6d86151bd631a854a33b9787e46da8268dcd4538
parent 28f34c79
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -1471,8 +1471,9 @@ static void gattClientScanNative(JNIEnv* env, jobject object, jboolean start) {
}

static void gattClientConnectNative(JNIEnv* env, jobject object, jint clientif,
                                    jstring address, jboolean isDirect,
                                    jint transport, jboolean opportunistic,
                                    jstring address, jint addressType,
                                    jboolean isDirect, jint transport,
                                    jboolean opportunistic,
                                    jint initiating_phys) {
  if (!sGattIf) return;

@@ -2758,7 +2759,7 @@ static JNINativeMethod sMethods[] = {
     (void*)gattClientRegisterAppNative},
    {"gattClientUnregisterAppNative", "(I)V",
     (void*)gattClientUnregisterAppNative},
    {"gattClientConnectNative", "(ILjava/lang/String;ZIZI)V",
    {"gattClientConnectNative", "(ILjava/lang/String;IZIZI)V",
     (void*)gattClientConnectNative},
    {"gattClientDisconnectNative", "(ILjava/lang/String;I)V",
     (void*)gattClientDisconnectNative},
+6 −6
Original line number Diff line number Diff line
@@ -312,8 +312,8 @@ public class GattNativeInterface {
    private native void gattClientRegisterAppNative(long appUuidLsb, long appUuidMsb,
            boolean eattSupport);
    private native void gattClientUnregisterAppNative(int clientIf);
    private native void gattClientConnectNative(int clientIf, String address, boolean isDirect,
            int transport, boolean opportunistic, int initiatingPhys);
    private native void gattClientConnectNative(int clientIf, String address, int addressType,
            boolean isDirect, int transport, boolean opportunistic, int initiatingPhys);
    private native void gattClientDisconnectNative(int clientIf, String address, int connId);
    private native void gattClientSetPreferredPhyNative(int clientIf, String address, int txPhy,
            int rxPhy, int phyOptions);
@@ -408,10 +408,10 @@ public class GattNativeInterface {
     * Connect to the remote Gatt server
     * @see {@link BluetoothDevice#connectGatt} for parameters.
     */
    public void gattClientConnect(int clientIf, String address, boolean isDirect, int transport,
            boolean opportunistic, int initiatingPhys) {
        gattClientConnectNative(clientIf, address, isDirect, transport, opportunistic,
                initiatingPhys);
    public void gattClientConnect(int clientIf, String address, int addressType,
            boolean isDirect, int transport, boolean opportunistic, int initiatingPhys) {
        gattClientConnectNative(clientIf, address, addressType, isDirect, transport,
                opportunistic, initiatingPhys);
    }

    /**
+16 −14
Original line number Diff line number Diff line
@@ -800,25 +800,26 @@ public class GattService extends ProfileService {
        }

        @Override
        public void clientConnect(int clientIf, String address, boolean isDirect, int transport,
                boolean opportunistic, int phy, AttributionSource attributionSource,
        public void clientConnect(int clientIf, String address, int addressType, boolean isDirect,
                int transport, boolean opportunistic, int phy, AttributionSource attributionSource,
                SynchronousResultReceiver receiver) {
            try {
                clientConnect(clientIf, address, isDirect, transport, opportunistic, phy,
                        attributionSource);
                clientConnect(clientIf, address, addressType, isDirect, transport, opportunistic,
                        phy, attributionSource);
                receiver.send(null);
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }
        private void clientConnect(int clientIf, String address, boolean isDirect, int transport,
                boolean opportunistic, int phy, AttributionSource attributionSource) {
        private void clientConnect(int clientIf, String address, int addressType, boolean isDirect,
                int transport, boolean opportunistic, int phy,
                AttributionSource attributionSource) {
            GattService service = getService();
            if (service == null) {
                return;
            }
            service.clientConnect(clientIf, address, isDirect, transport, opportunistic, phy,
                    attributionSource);
            service.clientConnect(clientIf, address, addressType, isDirect, transport,
                    opportunistic, phy, attributionSource);
        }

        @Override
@@ -3627,23 +3628,24 @@ public class GattService extends ProfileService {
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    void clientConnect(int clientIf, String address, boolean isDirect, int transport,
            boolean opportunistic, int phy, AttributionSource attributionSource) {
    void clientConnect(int clientIf, String address, int addressType, boolean isDirect,
            int transport, boolean opportunistic, int phy, AttributionSource attributionSource) {
        if (!Utils.checkConnectPermissionForDataDelivery(
                this, attributionSource, "GattService clientConnect")) {
            return;
        }

        if (DBG) {
            Log.d(TAG, "clientConnect() - address=" + address + ", isDirect=" + isDirect
                    + ", opportunistic=" + opportunistic + ", phy=" + phy);
            Log.d(TAG, "clientConnect() - address=" + address + ", addressType="
                    + addressType + ", isDirect=" + isDirect + ", opportunistic="
                    + opportunistic + ", phy=" + phy);
        }
        statsLogAppPackage(address, attributionSource.getUid(), clientIf);
        statsLogGattConnectionStateChange(
                BluetoothProfile.GATT, address, clientIf,
                BluetoothProtoEnums.CONNECTION_STATE_CONNECTING, -1);
        mNativeInterface.gattClientConnect(clientIf, address, isDirect, transport, opportunistic,
                phy);
        mNativeInterface.gattClientConnect(clientIf, address, addressType, isDirect, transport,
                opportunistic, phy);
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
+5 −4
Original line number Diff line number Diff line
@@ -193,16 +193,17 @@ public class GattServiceBinderTest {
    public void clientConnect() throws Exception {
        int clientIf = 1;
        String address = REMOTE_DEVICE_ADDRESS;
        int addressType = BluetoothDevice.ADDRESS_TYPE_RANDOM;
        boolean isDirect = true;
        int transport = 2;
        boolean opportunistic = true;
        int phy = 3;

        mBinder.clientConnect(clientIf, address, isDirect, transport, opportunistic, phy,
                mAttributionSource, SynchronousResultReceiver.get());
        mBinder.clientConnect(clientIf, address, addressType, isDirect, transport, opportunistic,
                phy, mAttributionSource, SynchronousResultReceiver.get());

        verify(mService).clientConnect(clientIf, address, isDirect, transport, opportunistic, phy,
                mAttributionSource);
        verify(mService).clientConnect(clientIf, address, addressType, isDirect, transport,
                opportunistic, phy, mAttributionSource);
    }

    @Test
+17 −0
Original line number Diff line number Diff line
@@ -308,6 +308,23 @@ public class GattServiceTest {
        verify(callback).onBatchScanResults(any());
    }

    @Test
    public void clientConnect() throws Exception {
        int clientIf = 1;
        String address = REMOTE_DEVICE_ADDRESS;
        int addressType = BluetoothDevice.ADDRESS_TYPE_RANDOM;
        boolean isDirect = false;
        int transport = 2;
        boolean opportunistic = true;
        int phy = 3;

        mService.clientConnect(clientIf, address, addressType, isDirect, transport,
                opportunistic, phy, mAttributionSource);

        verify(mNativeInterface).gattClientConnect(clientIf, address, addressType,
                isDirect, transport, opportunistic, phy);
    }

    @Test
    public void disconnectAll() {
        Map<Integer, String> connMap = new HashMap<>();
Loading