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

Commit 9a4b756c authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'bt5-cherry-pickerry-3' into oc-dev

* changes:
  Fix NPE when accessing mCallback in BluetoothGatt
  Expose LE advertiser address for easier PTS tests (1/6)
  Read by UUID for PTS tests (1/5)
parents 13d03e50 0e0e7579
Loading
Loading
Loading
Loading
+82 −16
Original line number Diff line number Diff line
@@ -159,9 +159,11 @@ public final class BluetoothGatt implements BluetoothProfile {
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            if (mCallback != null) {
                                mCallback.onConnectionStateChange(BluetoothGatt.this, GATT_FAILURE,
                                                  BluetoothProfile.STATE_DISCONNECTED);
                            }
                        }
                    });

                    synchronized(mStateLock) {
@@ -192,8 +194,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.onPhyUpdate(BluetoothGatt.this, txPhy, rxPhy, status);
                        }
                    }
                });
            }

@@ -212,8 +216,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.onPhyRead(BluetoothGatt.this, txPhy, rxPhy, status);
                        }
                    }
                });
            }

@@ -235,7 +241,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mCallback.onConnectionStateChange(BluetoothGatt.this, status, profileState);
                        if (mCallback != null) {
                            mCallback.onConnectionStateChange(BluetoothGatt.this, status,
                                                              profileState);
                        }
                    }
                });

@@ -294,8 +303,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.onServicesDiscovered(BluetoothGatt.this, status);
                        }
                    }
                });
            }

@@ -344,7 +355,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mCallback.onCharacteristicRead(BluetoothGatt.this, characteristic, status);
                        if (mCallback != null) {
                            mCallback.onCharacteristicRead(BluetoothGatt.this, characteristic,
                                                           status);
                        }
                    }
                });
            }
@@ -390,7 +404,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mCallback.onCharacteristicWrite(BluetoothGatt.this, characteristic, status);
                        if (mCallback != null) {
                            mCallback.onCharacteristicWrite(BluetoothGatt.this, characteristic,
                                                            status);
                        }
                    }
                });
            }
@@ -416,8 +433,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.onCharacteristicChanged(BluetoothGatt.this, characteristic);
                        }
                    }
                });
            }

@@ -461,8 +480,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.onDescriptorRead(BluetoothGatt.this, descriptor, status);
                        }
                    }
                });
            }

@@ -505,8 +526,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.onDescriptorWrite(BluetoothGatt.this, descriptor, status);
                        }
                    }
                });
            }

@@ -529,8 +552,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                           mCallback.onReliableWriteCompleted(BluetoothGatt.this, status);
                        }
                    }
                });
            }

@@ -548,8 +573,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.onReadRemoteRssi(BluetoothGatt.this, rssi, status);
                        }
                    }
                });
            }

@@ -568,8 +595,10 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.onMtuChanged(BluetoothGatt.this, mtu, status);
                        }
                    }
                });
            }

@@ -590,9 +619,11 @@ public final class BluetoothGatt implements BluetoothProfile {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.onConnectionUpdated(BluetoothGatt.this, interval, latency,
                                                          timeout, status);
                        }
                    }
                });
            }
        };
@@ -972,6 +1003,41 @@ public final class BluetoothGatt implements BluetoothProfile {
        return true;
    }

    /**
     * Reads the characteristic using its UUID from the associated remote device.
     *
     * <p>This is an asynchronous operation. The result of the read operation
     * is reported by the {@link BluetoothGattCallback#onCharacteristicRead}
     * callback.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param uuid UUID of characteristic to read from the remote device
     * @return true, if the read operation was initiated successfully
     * @hide
     */
    public boolean readUsingCharacteristicUuid(UUID uuid, int startHandle, int endHandle) {
        if (VDBG) Log.d(TAG, "readUsingCharacteristicUuid() - uuid: " + uuid);
        if (mService == null || mClientIf == 0) return false;

        synchronized(mDeviceBusy) {
            if (mDeviceBusy) return false;
            mDeviceBusy = true;
        }

        try {
            mService.readUsingCharacteristicUuid(mClientIf, mDevice.getAddress(),
                new ParcelUuid(uuid), startHandle, endHandle, AUTHENTICATION_NONE);
        } catch (RemoteException e) {
            Log.e(TAG,"",e);
            mDeviceBusy = false;
            return false;
        }

        return true;
    }


    /**
     * Writes a given characteristic and its values to the associated remote device.
     *
+3 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ interface IBluetoothGatt {
                                in IAdvertisingSetCallback callback);
    void stopAdvertisingSet(in IAdvertisingSetCallback callback);

    void getOwnAddress(in int advertiserId);
    void enableAdvertisingSet(in int advertiserId, in boolean enable, in int duration, in int maxExtAdvEvents);
    void setAdvertisingData(in int advertiserId, in AdvertiseData data);
    void setScanResponseData(in int advertiserId, in AdvertiseData data);
@@ -80,6 +81,8 @@ interface IBluetoothGatt {
    void refreshDevice(in int clientIf, in String address);
    void discoverServices(in int clientIf, in String address);
    void readCharacteristic(in int clientIf, in String address, in int handle, in int authReq);
    void readUsingCharacteristicUuid(in int clientIf, in String address, in ParcelUuid uuid,
                           in int startHandle, in int endHandle, in int authReq);
    void writeCharacteristic(in int clientIf, in String address, in int handle,
                            in int writeType, in int authReq, in byte[] value);
    void readDescriptor(in int clientIf, in String address, in int handle, in int authReq);
+17 −1
Original line number Diff line number Diff line
@@ -181,7 +181,23 @@ public final class AdvertisingSet {
    }

    /**
     * Returns advertiserId associated with thsi advertising set.
     * Returns address associated with this advertising set.
     * This method is exposed only for Bluetooth PTS tests, no app or system service
     * should ever use it.
     *
     * This method requires {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED} permission.
     * @hide
     */
    public void getOwnAddress(){
        try {
            gatt.getOwnAddress(this.advertiserId);
        } catch (RemoteException e) {
            Log.e(TAG, "remote exception - ", e);
        }
    }

    /**
     * Returns advertiserId associated with this advertising set.
     *
     * @hide
     */
+11 −0
Original line number Diff line number Diff line
@@ -143,4 +143,15 @@ public abstract class AdvertisingSetCallback {
     */
    public void onPeriodicAdvertisingEnabled(AdvertisingSet advertisingSet, boolean enable,
                                            int status) {}

    /**
     * Callback triggered in response to {@link AdvertisingSet#getOwnAddress()}
     * indicating result of the operation.
     *
     * @param advertisingSet The advertising set.
     * @param addressType type of address.
     * @param address advertising set bluetooth address.
     * @hide
     */
    public void onOwnAddressRead(AdvertisingSet advertisingSet, int addressType, String address) {}
}
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
@@ -543,6 +543,17 @@ public final class BluetoothLeAdvertiser {
                });
            }

            @Override
            public void onOwnAddressRead(int advertiserId, int addressType, String address) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        AdvertisingSet advertisingSet = mAdvertisingSets.get(advertiserId);
                        callback.onOwnAddressRead(advertisingSet, addressType, address);
                    }
                });
            }

            @Override
            public void onAdvertisingSetStopped(int advertiserId) {
                handler.post(new Runnable() {
Loading