diff options
author | Jakub Pawlowski <jpawlowski@google.com> | 2016-03-01 18:50:27 -0800 |
---|---|---|
committer | Jakub Pawlowski <jpawlowski@google.com> | 2016-03-18 12:57:33 -0700 |
commit | c9ba8c7ed1ab4271ef4cd84cac0032d13eb46513 (patch) | |
tree | 6a31a941bf6b55a2bdb8a245eabba532b4c5a0e2 /framework/java/android/bluetooth/BluetoothGattService.java | |
parent | f3793ce8b299495b3124c3854a7490fbf9d5cc96 (diff) |
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
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothGattService.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothGattService.java | 90 |
1 files changed, 88 insertions, 2 deletions
diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index 52bc0f796c..a4e1dc01d0 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -15,6 +15,9 @@ */ package android.bluetooth; +import android.os.Parcel; +import android.os.Parcelable; +import android.os.ParcelUuid; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -25,7 +28,7 @@ import java.util.UUID; * <p> Gatt Service contains a collection of {@link BluetoothGattCharacteristic}, * as well as referenced services. */ -public class BluetoothGattService { +public class BluetoothGattService implements Parcelable { /** * Primary service @@ -117,6 +120,81 @@ public class BluetoothGattService { } /** + * Create a new BluetoothGattService + * @hide + */ + public BluetoothGattService(UUID uuid, int instanceId, int serviceType) { + mDevice = null; + mUuid = uuid; + mInstanceId = instanceId; + mServiceType = serviceType; + mCharacteristics = new ArrayList<BluetoothGattCharacteristic>(); + mIncludedServices = new ArrayList<BluetoothGattService>(); + } + + /** + * @hide + */ + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(new ParcelUuid(mUuid), 0); + out.writeInt(mInstanceId); + out.writeInt(mServiceType); + out.writeTypedList(mCharacteristics); + + ArrayList<BluetoothGattIncludedService> includedServices = + new ArrayList<BluetoothGattIncludedService>(mIncludedServices.size()); + for(BluetoothGattService s : mIncludedServices) { + includedServices.add(new BluetoothGattIncludedService(s.getUuid(), + s.getInstanceId(), s.getType())); + } + out.writeTypedList(includedServices); + } + + public static final Parcelable.Creator<BluetoothGattService> CREATOR + = new Parcelable.Creator<BluetoothGattService>() { + public BluetoothGattService createFromParcel(Parcel in) { + return new BluetoothGattService(in); + } + + public BluetoothGattService[] newArray(int size) { + return new BluetoothGattService[size]; + } + }; + + private BluetoothGattService(Parcel in) { + mUuid = ((ParcelUuid)in.readParcelable(null)).getUuid(); + mInstanceId = in.readInt(); + mServiceType = in.readInt(); + + mCharacteristics = new ArrayList<BluetoothGattCharacteristic>(); + + ArrayList<BluetoothGattCharacteristic> chrcs = + in.createTypedArrayList(BluetoothGattCharacteristic.CREATOR); + if (chrcs != null) { + for (BluetoothGattCharacteristic chrc : chrcs) { + chrc.setService(this); + mCharacteristics.add(chrc); + } + } + + mIncludedServices = new ArrayList<BluetoothGattService>(); + + ArrayList<BluetoothGattIncludedService> inclSvcs = + in.createTypedArrayList(BluetoothGattIncludedService.CREATOR); + if (chrcs != null) { + for (BluetoothGattIncludedService isvc : inclSvcs) { + mIncludedServices.add(new BluetoothGattService(null, isvc.getUuid(), + isvc.getInstanceId(), isvc.getType())); + } + } + } + + /** * Returns the device associated with this service. * @hide */ @@ -125,6 +203,14 @@ public class BluetoothGattService { } /** + * Returns the device associated with this service. + * @hide + */ + /*package*/ void setDevice(BluetoothDevice device) { + this.mDevice = device; + } + + /** * Add an included service to this service. * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. * @@ -192,7 +278,7 @@ public class BluetoothGattService { * Add an included service to the internal map. * @hide */ - /*package*/ void addIncludedService(BluetoothGattService includedService) { + public void addIncludedService(BluetoothGattService includedService) { mIncludedServices.add(includedService); } |