Merge "Change how services are passed up to the stack"

This commit is contained in:
Andre Eisenbach
2016-03-18 22:11:51 +00:00
committed by Gerrit Code Review
13 changed files with 428 additions and 141 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -196,98 +196,6 @@ public final class BluetoothGatt implements BluetoothProfile {
} }
} }
/**
* A new GATT service has been discovered.
* The service is added to the internal list and the search
* continues.
* @hide
*/
public void onGetService(String address, int srvcType,
int srvcInstId, ParcelUuid srvcUuid) {
if (VDBG) Log.d(TAG, "onGetService() - Device=" + address + " UUID=" + srvcUuid);
if (!address.equals(mDevice.getAddress())) {
return;
}
mServices.add(new BluetoothGattService(mDevice, srvcUuid.getUuid(),
srvcInstId, srvcType));
}
/**
* An included service has been found durig GATT discovery.
* The included service is added to the respective parent.
* @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) {
service.addIncludedService(includedService);
}
}
/**
* A new GATT characteristic has been discovered.
* Add the new characteristic to the relevant service and continue
* the remote device inspection.
* @hide
*/
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())) {
return;
}
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. * Remote search has been completed.
* The internal object structure should now reflect the state * The internal object structure should now reflect the state
@@ -295,11 +203,37 @@ public final class BluetoothGatt implements BluetoothProfile {
* we are done at this point. * we are done at this point.
* @hide * @hide
*/ */
public void onSearchComplete(String address, int status) { public void onSearchComplete(String address, List<BluetoothGattService> services,
int status) {
if (DBG) Log.d(TAG, "onSearchComplete() = Device=" + address + " Status=" + status); if (DBG) Log.d(TAG, "onSearchComplete() = Device=" + address + " Status=" + status);
if (!address.equals(mDevice.getAddress())) { if (!address.equals(mDevice.getAddress())) {
return; return;
} }
for (BluetoothGattService s : services) {
//services we receive don't have device set properly.
s.setDevice(mDevice);
}
mServices.addAll(services);
// Fix references to included services, as they doesn't point to right objects.
for (BluetoothGattService fixedService : mServices) {
ArrayList<BluetoothGattService> includedServices =
new ArrayList(fixedService.getIncludedServices());
fixedService.getIncludedServices().clear();
for(BluetoothGattService brokenRef : includedServices) {
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.");
}
}
}
try { try {
mCallback.onServicesDiscovered(BluetoothGatt.this, status); mCallback.onServicesDiscovered(BluetoothGatt.this, status);
} catch (Exception ex) { } catch (Exception ex) {

View File

@@ -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

View File

@@ -0,0 +1,19 @@
/*
* 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;

View File

@@ -15,6 +15,9 @@
*/ */
package android.bluetooth; package android.bluetooth;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ParcelUuid;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@@ -26,7 +29,7 @@ import java.util.UUID;
* {@link BluetoothGattService}. The characteristic contains a value as well as * {@link BluetoothGattService}. The characteristic contains a value as well as
* additional information and optional GATT descriptors, {@link BluetoothGattDescriptor}. * additional information and optional GATT descriptors, {@link BluetoothGattDescriptor}.
*/ */
public class BluetoothGattCharacteristic { public class BluetoothGattCharacteristic implements Parcelable {
/** /**
* Characteristic proprty: Characteristic is broadcastable. * Characteristic proprty: Characteristic is broadcastable.
@@ -242,6 +245,15 @@ public class BluetoothGattCharacteristic {
initCharacteristic(service, uuid, instanceId, properties, permissions); initCharacteristic(service, uuid, instanceId, properties, permissions);
} }
/**
* Create a new BluetoothGattCharacteristic
* @hide
*/
public BluetoothGattCharacteristic(UUID uuid, int instanceId,
int properties, int permissions) {
initCharacteristic(null, uuid, instanceId, properties, permissions);
}
private void initCharacteristic(BluetoothGattService service, private void initCharacteristic(BluetoothGattService service,
UUID uuid, int instanceId, UUID uuid, int instanceId,
int properties, int permissions) { int properties, int permissions) {
@@ -260,6 +272,50 @@ public class BluetoothGattCharacteristic {
} }
} }
/**
* @hide
*/
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(new ParcelUuid(mUuid), 0);
out.writeInt(mInstance);
out.writeInt(mProperties);
out.writeInt(mPermissions);
out.writeTypedList(mDescriptors);
}
public static final Parcelable.Creator<BluetoothGattCharacteristic> CREATOR
= new Parcelable.Creator<BluetoothGattCharacteristic>() {
public BluetoothGattCharacteristic createFromParcel(Parcel in) {
return new BluetoothGattCharacteristic(in);
}
public BluetoothGattCharacteristic[] newArray(int size) {
return new BluetoothGattCharacteristic[size];
}
};
private BluetoothGattCharacteristic(Parcel in) {
mUuid = ((ParcelUuid)in.readParcelable(null)).getUuid();
mInstance = in.readInt();
mProperties = in.readInt();
mPermissions = in.readInt();
mDescriptors = new ArrayList<BluetoothGattDescriptor>();
ArrayList<BluetoothGattDescriptor> descs =
in.createTypedArrayList(BluetoothGattDescriptor.CREATOR);
if (descs != null) {
for (BluetoothGattDescriptor desc: descs) {
desc.setCharacteristic(this);
mDescriptors.add(desc);
}
}
}
/** /**
* Returns the deisred key size. * Returns the deisred key size.
* @hide * @hide

View File

@@ -0,0 +1,19 @@
/*
* 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 BluetoothGattDescriptor;

View File

@@ -16,6 +16,9 @@
package android.bluetooth; package android.bluetooth;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ParcelUuid;
import java.util.UUID; import java.util.UUID;
/** /**
@@ -25,7 +28,7 @@ import java.util.UUID;
* characteristic, {@link BluetoothGattCharacteristic}. They can be used to describe * characteristic, {@link BluetoothGattCharacteristic}. They can be used to describe
* the characteristic's features or to control certain behaviours of the characteristic. * the characteristic's features or to control certain behaviours of the characteristic.
*/ */
public class BluetoothGattDescriptor { public class BluetoothGattDescriptor implements Parcelable {
/** /**
* Value used to enable notification for a client configuration descriptor * Value used to enable notification for a client configuration descriptor
@@ -138,6 +141,13 @@ public class BluetoothGattDescriptor {
initDescriptor(characteristic, uuid, instance, permissions); initDescriptor(characteristic, uuid, instance, permissions);
} }
/**
* @hide
*/
public BluetoothGattDescriptor(UUID uuid, int instance, int permissions) {
initDescriptor(null, uuid, instance, permissions);
}
private void initDescriptor(BluetoothGattCharacteristic characteristic, UUID uuid, private void initDescriptor(BluetoothGattCharacteristic characteristic, UUID uuid,
int instance, int permissions) { int instance, int permissions) {
mCharacteristic = characteristic; mCharacteristic = characteristic;
@@ -146,6 +156,36 @@ public class BluetoothGattDescriptor {
mPermissions = permissions; mPermissions = permissions;
} }
/**
* @hide
*/
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(new ParcelUuid(mUuid), 0);
out.writeInt(mInstance);
out.writeInt(mPermissions);
}
public static final Parcelable.Creator<BluetoothGattDescriptor> CREATOR
= new Parcelable.Creator<BluetoothGattDescriptor>() {
public BluetoothGattDescriptor createFromParcel(Parcel in) {
return new BluetoothGattDescriptor(in);
}
public BluetoothGattDescriptor[] newArray(int size) {
return new BluetoothGattDescriptor[size];
}
};
private BluetoothGattDescriptor(Parcel in) {
mUuid = ((ParcelUuid)in.readParcelable(null)).getUuid();
mInstance = in.readInt();
mPermissions = in.readInt();
}
/** /**
* Returns the characteristic this descriptor belongs to. * Returns the characteristic this descriptor belongs to.
* @return The characteristic. * @return The characteristic.

View File

@@ -0,0 +1,19 @@
/*
* 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 BluetoothGattIncludedService;

View File

@@ -0,0 +1,110 @@
/*
* 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;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ParcelUuid;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Represents a Bluetooth GATT Included Service
* @hide
*/
public class BluetoothGattIncludedService implements Parcelable {
/**
* The UUID of this service.
*/
protected UUID mUuid;
/**
* Instance ID for this service.
*/
protected int mInstanceId;
/**
* Service type (Primary/Secondary).
*/
protected int mServiceType;
/**
* Create a new BluetoothGattIncludedService
*/
public BluetoothGattIncludedService(UUID uuid, int instanceId, int serviceType) {
mUuid = uuid;
mInstanceId = instanceId;
mServiceType = serviceType;
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(new ParcelUuid(mUuid), 0);
out.writeInt(mInstanceId);
out.writeInt(mServiceType);
}
public static final Parcelable.Creator<BluetoothGattIncludedService> CREATOR
= new Parcelable.Creator<BluetoothGattIncludedService>() {
public BluetoothGattIncludedService createFromParcel(Parcel in) {
return new BluetoothGattIncludedService(in);
}
public BluetoothGattIncludedService[] newArray(int size) {
return new BluetoothGattIncludedService[size];
}
};
private BluetoothGattIncludedService(Parcel in) {
mUuid = ((ParcelUuid)in.readParcelable(null)).getUuid();
mInstanceId = in.readInt();
mServiceType = in.readInt();
}
/**
* Returns the UUID of this service
*
* @return UUID of this service
*/
public UUID getUuid() {
return mUuid;
}
/**
* Returns the instance ID for this service
*
* <p>If a remote device offers multiple services with the same UUID
* (ex. multiple battery services for different batteries), the instance
* ID is used to distuinguish services.
*
* @return Instance ID of this service
*/
public int getInstanceId() {
return mInstanceId;
}
/**
* Get the type of this service (primary/secondary)
*/
public int getType() {
return mServiceType;
}
}

View File

@@ -0,0 +1,19 @@
/*
* 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 BluetoothGattService;

View File

@@ -15,6 +15,9 @@
*/ */
package android.bluetooth; package android.bluetooth;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ParcelUuid;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@@ -25,7 +28,7 @@ import java.util.UUID;
* <p> Gatt Service contains a collection of {@link BluetoothGattCharacteristic}, * <p> Gatt Service contains a collection of {@link BluetoothGattCharacteristic},
* as well as referenced services. * as well as referenced services.
*/ */
public class BluetoothGattService { public class BluetoothGattService implements Parcelable {
/** /**
* Primary service * Primary service
@@ -116,6 +119,81 @@ public class BluetoothGattService {
mIncludedServices = new ArrayList<BluetoothGattService>(); mIncludedServices = new ArrayList<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. * Returns the device associated with this service.
* @hide * @hide
@@ -124,6 +202,14 @@ public class BluetoothGattService {
return mDevice; return mDevice;
} }
/**
* Returns the device associated with this service.
* @hide
*/
/*package*/ void setDevice(BluetoothDevice device) {
this.mDevice = device;
}
/** /**
* Add an included service to this service. * Add an included service to this service.
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
@@ -192,7 +278,7 @@ public class BluetoothGattService {
* Add an included service to the internal map. * Add an included service to the internal map.
* @hide * @hide
*/ */
/*package*/ void addIncludedService(BluetoothGattService includedService) { public void addIncludedService(BluetoothGattService includedService) {
mIncludedServices.add(includedService); mIncludedServices.add(includedService);
} }

View File

@@ -16,6 +16,7 @@
package android.bluetooth; package android.bluetooth;
import android.os.ParcelUuid; import android.os.ParcelUuid;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.le.AdvertiseSettings; import android.bluetooth.le.AdvertiseSettings;
import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanResult;
@@ -29,20 +30,7 @@ oneway interface IBluetoothGattCallback {
in boolean connected, in String address); in boolean connected, in String address);
void onScanResult(in ScanResult scanResult); void onScanResult(in ScanResult scanResult);
void onBatchScanResults(in List<ScanResult> batchResults); void onBatchScanResults(in List<ScanResult> batchResults);
void onGetService(in String address, in int srvcType, in int srvcInstId, void onSearchComplete(in String address, in List<BluetoothGattService> services, in int status);
in ParcelUuid srvcUuid);
void onGetIncludedService(in String address, in int srvcType, in int srvcInstId,
in ParcelUuid srvcUuid, in int inclSrvcType,
in int inclSrvcInstId, in ParcelUuid inclSrvcUuid);
void onGetCharacteristic(in String address, in int srvcType,
in int srvcInstId, in ParcelUuid srvcUuid,
in int charInstId, in ParcelUuid charUuid,
in int charProps);
void onGetDescriptor(in String address, in int srvcType,
in int srvcInstId, in ParcelUuid srvcUuid,
in int charInstId, in ParcelUuid charUuid,
in int descrInstId, in ParcelUuid descrUuid);
void onSearchComplete(in String address, in int status);
void onCharacteristicRead(in String address, in int status, in int srvcType, void onCharacteristicRead(in String address, in int status, in int srvcType,
in int srvcInstId, in ParcelUuid srvcUuid, in int srvcInstId, in ParcelUuid srvcUuid,
in int charInstId, in ParcelUuid charUuid, in int charInstId, in ParcelUuid charUuid,