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

Commit 8d312a84 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Change how services are passed up to the stack

Right now we pass all services, characteristics and descriptors one by one.
This patch changes that - now we pass whole GATT database at once.

Bug: 27455533
Change-Id: Ie42cd80072538e411904b9c9b011a978f26158b9
parent 93fdc3fa
Loading
Loading
Loading
Loading
+12 −3
Original line number Original line Diff line number Diff line
@@ -6756,9 +6756,10 @@ package android.bluetooth {
    method public void onServicesDiscovered(android.bluetooth.BluetoothGatt, int);
    method public void onServicesDiscovered(android.bluetooth.BluetoothGatt, int);
  }
  }
  public class BluetoothGattCharacteristic {
  public class BluetoothGattCharacteristic implements android.os.Parcelable {
    ctor public BluetoothGattCharacteristic(java.util.UUID, int, int);
    ctor public BluetoothGattCharacteristic(java.util.UUID, int, int);
    method public boolean addDescriptor(android.bluetooth.BluetoothGattDescriptor);
    method public boolean addDescriptor(android.bluetooth.BluetoothGattDescriptor);
    method public int describeContents();
    method public android.bluetooth.BluetoothGattDescriptor getDescriptor(java.util.UUID);
    method public android.bluetooth.BluetoothGattDescriptor getDescriptor(java.util.UUID);
    method public java.util.List<android.bluetooth.BluetoothGattDescriptor> getDescriptors();
    method public java.util.List<android.bluetooth.BluetoothGattDescriptor> getDescriptors();
    method public java.lang.Float getFloatValue(int, int);
    method public java.lang.Float getFloatValue(int, int);
@@ -6776,6 +6777,8 @@ package android.bluetooth {
    method public boolean setValue(int, int, int, int);
    method public boolean setValue(int, int, int, int);
    method public boolean setValue(java.lang.String);
    method public boolean setValue(java.lang.String);
    method public void setWriteType(int);
    method public void setWriteType(int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothGattCharacteristic> CREATOR;
    field public static final int FORMAT_FLOAT = 52; // 0x34
    field public static final int FORMAT_FLOAT = 52; // 0x34
    field public static final int FORMAT_SFLOAT = 50; // 0x32
    field public static final int FORMAT_SFLOAT = 50; // 0x32
    field public static final int FORMAT_SINT16 = 34; // 0x22
    field public static final int FORMAT_SINT16 = 34; // 0x22
@@ -6806,13 +6809,16 @@ package android.bluetooth {
    field protected java.util.List<android.bluetooth.BluetoothGattDescriptor> mDescriptors;
    field protected java.util.List<android.bluetooth.BluetoothGattDescriptor> mDescriptors;
  }
  }
  public class BluetoothGattDescriptor {
  public class BluetoothGattDescriptor implements android.os.Parcelable {
    ctor public BluetoothGattDescriptor(java.util.UUID, int);
    ctor public BluetoothGattDescriptor(java.util.UUID, int);
    method public int describeContents();
    method public android.bluetooth.BluetoothGattCharacteristic getCharacteristic();
    method public android.bluetooth.BluetoothGattCharacteristic getCharacteristic();
    method public int getPermissions();
    method public int getPermissions();
    method public java.util.UUID getUuid();
    method public java.util.UUID getUuid();
    method public byte[] getValue();
    method public byte[] getValue();
    method public boolean setValue(byte[]);
    method public boolean setValue(byte[]);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothGattDescriptor> CREATOR;
    field public static final byte[] DISABLE_NOTIFICATION_VALUE;
    field public static final byte[] DISABLE_NOTIFICATION_VALUE;
    field public static final byte[] ENABLE_INDICATION_VALUE;
    field public static final byte[] ENABLE_INDICATION_VALUE;
    field public static final byte[] ENABLE_NOTIFICATION_VALUE;
    field public static final byte[] ENABLE_NOTIFICATION_VALUE;
@@ -6855,16 +6861,19 @@ package android.bluetooth {
    method public void onServiceAdded(int, android.bluetooth.BluetoothGattService);
    method public void onServiceAdded(int, android.bluetooth.BluetoothGattService);
  }
  }
  public class BluetoothGattService {
  public class BluetoothGattService implements android.os.Parcelable {
    ctor public BluetoothGattService(java.util.UUID, int);
    ctor public BluetoothGattService(java.util.UUID, int);
    method public boolean addCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
    method public boolean addCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
    method public boolean addService(android.bluetooth.BluetoothGattService);
    method public boolean addService(android.bluetooth.BluetoothGattService);
    method public int describeContents();
    method public android.bluetooth.BluetoothGattCharacteristic getCharacteristic(java.util.UUID);
    method public android.bluetooth.BluetoothGattCharacteristic getCharacteristic(java.util.UUID);
    method public java.util.List<android.bluetooth.BluetoothGattCharacteristic> getCharacteristics();
    method public java.util.List<android.bluetooth.BluetoothGattCharacteristic> getCharacteristics();
    method public java.util.List<android.bluetooth.BluetoothGattService> getIncludedServices();
    method public java.util.List<android.bluetooth.BluetoothGattService> getIncludedServices();
    method public int getInstanceId();
    method public int getInstanceId();
    method public int getType();
    method public int getType();
    method public java.util.UUID getUuid();
    method public java.util.UUID getUuid();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothGattService> CREATOR;
    field public static final int SERVICE_TYPE_PRIMARY = 0; // 0x0
    field public static final int SERVICE_TYPE_PRIMARY = 0; // 0x0
    field public static final int SERVICE_TYPE_SECONDARY = 1; // 0x1
    field public static final int SERVICE_TYPE_SECONDARY = 1; // 0x1
    field protected java.util.List<android.bluetooth.BluetoothGattCharacteristic> mCharacteristics;
    field protected java.util.List<android.bluetooth.BluetoothGattCharacteristic> mCharacteristics;
+12 −3
Original line number Original line Diff line number Diff line
@@ -6977,9 +6977,10 @@ package android.bluetooth {
    method public void onServicesDiscovered(android.bluetooth.BluetoothGatt, int);
    method public void onServicesDiscovered(android.bluetooth.BluetoothGatt, int);
  }
  }
  public class BluetoothGattCharacteristic {
  public class BluetoothGattCharacteristic implements android.os.Parcelable {
    ctor public BluetoothGattCharacteristic(java.util.UUID, int, int);
    ctor public BluetoothGattCharacteristic(java.util.UUID, int, int);
    method public boolean addDescriptor(android.bluetooth.BluetoothGattDescriptor);
    method public boolean addDescriptor(android.bluetooth.BluetoothGattDescriptor);
    method public int describeContents();
    method public android.bluetooth.BluetoothGattDescriptor getDescriptor(java.util.UUID);
    method public android.bluetooth.BluetoothGattDescriptor getDescriptor(java.util.UUID);
    method public java.util.List<android.bluetooth.BluetoothGattDescriptor> getDescriptors();
    method public java.util.List<android.bluetooth.BluetoothGattDescriptor> getDescriptors();
    method public java.lang.Float getFloatValue(int, int);
    method public java.lang.Float getFloatValue(int, int);
@@ -6997,6 +6998,8 @@ package android.bluetooth {
    method public boolean setValue(int, int, int, int);
    method public boolean setValue(int, int, int, int);
    method public boolean setValue(java.lang.String);
    method public boolean setValue(java.lang.String);
    method public void setWriteType(int);
    method public void setWriteType(int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothGattCharacteristic> CREATOR;
    field public static final int FORMAT_FLOAT = 52; // 0x34
    field public static final int FORMAT_FLOAT = 52; // 0x34
    field public static final int FORMAT_SFLOAT = 50; // 0x32
    field public static final int FORMAT_SFLOAT = 50; // 0x32
    field public static final int FORMAT_SINT16 = 34; // 0x22
    field public static final int FORMAT_SINT16 = 34; // 0x22
@@ -7027,13 +7030,16 @@ package android.bluetooth {
    field protected java.util.List<android.bluetooth.BluetoothGattDescriptor> mDescriptors;
    field protected java.util.List<android.bluetooth.BluetoothGattDescriptor> mDescriptors;
  }
  }
  public class BluetoothGattDescriptor {
  public class BluetoothGattDescriptor implements android.os.Parcelable {
    ctor public BluetoothGattDescriptor(java.util.UUID, int);
    ctor public BluetoothGattDescriptor(java.util.UUID, int);
    method public int describeContents();
    method public android.bluetooth.BluetoothGattCharacteristic getCharacteristic();
    method public android.bluetooth.BluetoothGattCharacteristic getCharacteristic();
    method public int getPermissions();
    method public int getPermissions();
    method public java.util.UUID getUuid();
    method public java.util.UUID getUuid();
    method public byte[] getValue();
    method public byte[] getValue();
    method public boolean setValue(byte[]);
    method public boolean setValue(byte[]);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothGattDescriptor> CREATOR;
    field public static final byte[] DISABLE_NOTIFICATION_VALUE;
    field public static final byte[] DISABLE_NOTIFICATION_VALUE;
    field public static final byte[] ENABLE_INDICATION_VALUE;
    field public static final byte[] ENABLE_INDICATION_VALUE;
    field public static final byte[] ENABLE_NOTIFICATION_VALUE;
    field public static final byte[] ENABLE_NOTIFICATION_VALUE;
@@ -7076,16 +7082,19 @@ package android.bluetooth {
    method public void onServiceAdded(int, android.bluetooth.BluetoothGattService);
    method public void onServiceAdded(int, android.bluetooth.BluetoothGattService);
  }
  }
  public class BluetoothGattService {
  public class BluetoothGattService implements android.os.Parcelable {
    ctor public BluetoothGattService(java.util.UUID, int);
    ctor public BluetoothGattService(java.util.UUID, int);
    method public boolean addCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
    method public boolean addCharacteristic(android.bluetooth.BluetoothGattCharacteristic);
    method public boolean addService(android.bluetooth.BluetoothGattService);
    method public boolean addService(android.bluetooth.BluetoothGattService);
    method public int describeContents();
    method public android.bluetooth.BluetoothGattCharacteristic getCharacteristic(java.util.UUID);
    method public android.bluetooth.BluetoothGattCharacteristic getCharacteristic(java.util.UUID);
    method public java.util.List<android.bluetooth.BluetoothGattCharacteristic> getCharacteristics();
    method public java.util.List<android.bluetooth.BluetoothGattCharacteristic> getCharacteristics();
    method public java.util.List<android.bluetooth.BluetoothGattService> getIncludedServices();
    method public java.util.List<android.bluetooth.BluetoothGattService> getIncludedServices();
    method public int getInstanceId();
    method public int getInstanceId();
    method public int getType();
    method public int getType();
    method public java.util.UUID getUuid();
    method public java.util.UUID getUuid();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.bluetooth.BluetoothGattService> CREATOR;
    field public static final int SERVICE_TYPE_PRIMARY = 0; // 0x0
    field public static final int SERVICE_TYPE_PRIMARY = 0; // 0x0
    field public static final int SERVICE_TYPE_SECONDARY = 1; // 0x1
    field public static final int SERVICE_TYPE_SECONDARY = 1; // 0x1
    field protected java.util.List<android.bluetooth.BluetoothGattCharacteristic> mCharacteristics;
    field protected java.util.List<android.bluetooth.BluetoothGattCharacteristic> mCharacteristics;
+27 −93
Original line number Original line Diff line number Diff line
@@ -197,109 +197,43 @@ public final class BluetoothGatt implements BluetoothProfile {
            }
            }


            /**
            /**
             * A new GATT service has been discovered.
             * Remote search has been completed.
             * The service is added to the internal list and the search
             * The internal object structure should now reflect the state
             * continues.
             * of the remote device database. Let the application know that
             * we are done at this point.
             * @hide
             * @hide
             */
             */
            public void onGetService(String address, int srvcType,
            public void onSearchComplete(String address, List<BluetoothGattService> services,
                                     int srvcInstId, ParcelUuid srvcUuid) {
                                         int status) {
                if (VDBG) Log.d(TAG, "onGetService() - Device=" + address + " UUID=" + srvcUuid);
                if (DBG) Log.d(TAG, "onSearchComplete() = Device=" + address + " Status=" + status);
                if (!address.equals(mDevice.getAddress())) {
                if (!address.equals(mDevice.getAddress())) {
                    return;
                    return;
                }
                }
                mServices.add(new BluetoothGattService(mDevice, srvcUuid.getUuid(),
                                                       srvcInstId, srvcType));
            }


            /**
                for (BluetoothGattService s : services) {
             * An included service has been found durig GATT discovery.
                    //services we receive don't have device set properly.
             * The included service is added to the respective parent.
                    s.setDevice(mDevice);
             * @hide
             */
            public void onGetIncludedService(String address, int srvcType,
                                             int srvcInstId, ParcelUuid srvcUuid,
                                             int inclSrvcType, int inclSrvcInstId,
                                             ParcelUuid inclSrvcUuid) {
                if (VDBG) Log.d(TAG, "onGetIncludedService() - Device=" + address
                    + " UUID=" + srvcUuid + " Included=" + inclSrvcUuid);

                if (!address.equals(mDevice.getAddress())) {
                    return;
                }
                }
                BluetoothGattService service = getService(mDevice,
                        srvcUuid.getUuid(), srvcInstId, srvcType);
                BluetoothGattService includedService = getService(mDevice,
                        inclSrvcUuid.getUuid(), inclSrvcInstId, inclSrvcType);


                if (service != null && includedService != null) {
                mServices.addAll(services);
                    service.addIncludedService(includedService);
                }
            }


            /**
                // Fix references to included services, as they doesn't point to right objects.
             * A new GATT characteristic has been discovered.
                for (BluetoothGattService fixedService : mServices) {
             * Add the new characteristic to the relevant service and continue
                    ArrayList<BluetoothGattService> includedServices =
             * the remote device inspection.
                        new ArrayList(fixedService.getIncludedServices());
             * @hide
                    fixedService.getIncludedServices().clear();
             */
            public void onGetCharacteristic(String address, int srvcType,
                             int srvcInstId, ParcelUuid srvcUuid,
                             int charInstId, ParcelUuid charUuid,
                             int charProps) {
                if (VDBG) Log.d(TAG, "onGetCharacteristic() - Device=" + address + " UUID=" +
                               charUuid);


                if (!address.equals(mDevice.getAddress())) {
                    for(BluetoothGattService brokenRef : includedServices) {
                    return;
                        BluetoothGattService includedService = getService(mDevice,
                            brokenRef.getUuid(), brokenRef.getInstanceId(), brokenRef.getType());
                        if (includedService != null) {
                            fixedService.addIncludedService(includedService);
                        } else {
                            Log.e(TAG, "Broken GATT database: can't find included service.");
                        }
                        }
                BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
                                                          srvcInstId, srvcType);
                if (service != null) {
                    service.addCharacteristic(new BluetoothGattCharacteristic(
                           service, charUuid.getUuid(), charInstId, charProps, 0));
                    }
                    }
                }
                }


            /**
             * A new GATT descriptor has been discovered.
             * Finally, add the descriptor to the related characteristic.
             * This should conclude the remote device update.
             * @hide
             */
            public void onGetDescriptor(String address, int srvcType,
                             int srvcInstId, ParcelUuid srvcUuid,
                             int charInstId, ParcelUuid charUuid,
                             int descrInstId, ParcelUuid descUuid) {
                if (VDBG) Log.d(TAG, "onGetDescriptor() - Device=" + address + " UUID=" + descUuid);

                if (!address.equals(mDevice.getAddress())) {
                    return;
                }
                BluetoothGattService service = getService(mDevice, srvcUuid.getUuid(),
                                                          srvcInstId, srvcType);
                if (service == null) return;

                BluetoothGattCharacteristic characteristic = service.getCharacteristic(
                    charUuid.getUuid(), charInstId);
                if (characteristic == null) return;

                characteristic.addDescriptor(new BluetoothGattDescriptor(
                    characteristic, descUuid.getUuid(), descrInstId, 0));
            }

            /**
             * Remote search has been completed.
             * The internal object structure should now reflect the state
             * of the remote device database. Let the application know that
             * we are done at this point.
             * @hide
             */
            public void onSearchComplete(String address, int status) {
                if (DBG) Log.d(TAG, "onSearchComplete() = Device=" + address + " Status=" + status);
                if (!address.equals(mDevice.getAddress())) {
                    return;
                }
                try {
                try {
                    mCallback.onServicesDiscovered(BluetoothGatt.this, status);
                    mCallback.onServicesDiscovered(BluetoothGatt.this, status);
                } catch (Exception ex) {
                } catch (Exception ex) {
+3 −24
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package android.bluetooth;


import android.bluetooth.le.AdvertiseSettings;
import android.bluetooth.le.AdvertiseSettings;
import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanResult;
import android.bluetooth.BluetoothGattService;
import android.os.ParcelUuid;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.os.RemoteException;


@@ -48,30 +49,8 @@ public class BluetoothGattCallbackWrapper extends IBluetoothGattCallback.Stub {
    }
    }


    @Override
    @Override
    public void onGetService(String address, int srvcType, int srvcInstId, ParcelUuid srvcUuid)
    public void onSearchComplete(String address, List<BluetoothGattService> services,
            throws RemoteException {
            int status) throws RemoteException {
    }

    @Override
    public void onGetIncludedService(String address, int srvcType, int srvcInstId,
            ParcelUuid srvcUuid, int inclSrvcType, int inclSrvcInstId, ParcelUuid inclSrvcUuid)
            throws RemoteException {
    }

    @Override
    public void onGetCharacteristic(String address, int srvcType, int srvcInstId,
            ParcelUuid srvcUuid, int charInstId, ParcelUuid charUuid, int charProps)
            throws RemoteException {
    }

    @Override
    public void onGetDescriptor(String address, int srvcType, int srvcInstId, ParcelUuid srvcUuid,
            int charInstId, ParcelUuid charUuid, int descrInstId, ParcelUuid descrUuid)
            throws RemoteException {
    }

    @Override
    public void onSearchComplete(String address, int status) throws RemoteException {
    }
    }


    @Override
    @Override
+19 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.bluetooth;

parcelable BluetoothGattCharacteristic;
Loading