From 40b98951361157933c2084e855f7cffef0ca7fb7 Mon Sep 17 00:00:00 2001 From: Ganesh Ganapathi Batta Date: Tue, 5 Feb 2013 15:28:33 -0800 Subject: Initial version of BLE support for Bluedroid The API classes are hidden for now. Will unhide after API console approval. Change-Id: I8283dd562fd6189fdd15c866ef2efb8bbdbc4109 --- .../android/bluetooth/BluetoothGattService.java | 232 +++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 framework/java/android/bluetooth/BluetoothGattService.java (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java new file mode 100644 index 0000000000..6a3ce66e8f --- /dev/null +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2013 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.bluetooth.BluetoothDevice; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * Represents a Bluetooth Gatt Service + * @hide + */ +public class BluetoothGattService { + + /** + * Primary service + */ + public static final int SERVICE_TYPE_PRIMARY = 0; + + /** + * Secondary service (included by primary services) + */ + public static final int SERVICE_TYPE_SECONDARY = 1; + + + /** + * The remote device his service is associated with. + * This applies to client applications only. + * @hide + */ + protected BluetoothDevice mDevice; + + /** + * The UUID of this service. + * @hide + */ + protected UUID mUuid; + + /** + * Instance ID for this service. + * @hide + */ + protected int mInstanceId; + + /** + * Handle counter override (for conformance testing). + * @hide + */ + protected int mHandles = 0; + + /** + * Service type (Primary/Secondary). + * @hide + */ + protected int mServiceType; + + /** + * List of characteristics included in this service. + */ + protected List mCharacteristics; + + /** + * List of included services for this service. + */ + protected List mIncludedServices; + + /** + * Create a new BluetoothGattService. + * @hide + */ + /*package*/ BluetoothGattService(UUID uuid, int serviceType) { + mDevice = null; + mUuid = uuid; + mInstanceId = 0; + mServiceType = serviceType; + mCharacteristics = new ArrayList(); + mIncludedServices = new ArrayList(); + } + + /** + * Create a new BluetoothGattService + * @hide + */ + /*package*/ BluetoothGattService(BluetoothDevice device, UUID uuid, + int instanceId, int serviceType) { + mDevice = device; + mUuid = uuid; + mInstanceId = instanceId; + mServiceType = serviceType; + mCharacteristics = new ArrayList(); + mIncludedServices = new ArrayList(); + } + + /** + * Returns the device associated with this service. + * @hide + */ + /*package*/ BluetoothDevice getDevice() { + return mDevice; + } + + /** + * Add a characteristic to this service. + * @hide + */ + /*package*/ void addCharacteristic(BluetoothGattCharacteristic characteristic) { + mCharacteristics.add(characteristic); + } + + /** + * Get characteristic by UUID and instanceId. + * @hide + */ + /*package*/ BluetoothGattCharacteristic getCharacteristic(UUID uuid, int instanceId) { + for(BluetoothGattCharacteristic characteristic : mCharacteristics) { + if (uuid.equals(characteristic.getUuid()) && + mInstanceId == instanceId) + return characteristic; + } + return null; + } + + /** + * Get the handle count override (conformance testing. + * @hide + */ + /*package*/ int getHandles() { + return mHandles; + } + + /** + * Add an included service to the internal map. + * @hide + */ + /*package*/ void addIncludedService(BluetoothGattService includedService) { + mIncludedServices.add(includedService); + } + + /** + * Returns the UUID of this service + *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. + * + * @return UUID of this service + */ + public UUID getUuid() { + return mUuid; + } + + /** + * Returns the instance ID for this service + * + *

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. + * + *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. + * + * @return Instance ID of this service + */ + public int getInstanceId() { + return mInstanceId; + } + + /** + * Get the type of this service (primary/secondary) + * @hide + */ + public int getType() { + return mServiceType; + } + + /** + * Get the list of included Gatt services for this service. + *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. + * + * @return List of included services or empty list if no included services + * were discovered. + */ + public List getIncludedServices() { + return mIncludedServices; + } + + /** + * Returns a list of characteristics included in this service. + *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. + * + * @return Characteristics included in this service + */ + public List getCharacteristics() { + return mCharacteristics; + } + + /** + * Returns a characteristic with a given UUID out of the list of + * characteristics offered by this service. + * + *

This is a convenience function to allow access to a given characteristic + * without enumerating over the list returned by {@link #getCharacteristics} + * manually. + * + *

If a remote service offers multiple characteristics with the same + * UUID, the first instance of a characteristic with the given UUID + * is returned. + * + *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. + * + * @return Gatt characteristic object or null if no characteristic with the + * given UUID was found. + */ + public BluetoothGattCharacteristic getCharacteristic(UUID uuid) { + for(BluetoothGattCharacteristic characteristic : mCharacteristics) { + if (uuid.equals(characteristic.getUuid())) + return characteristic; + } + return null; + } +} -- cgit v1.2.3 From 9afa274491ca272dc30f6f6211ef2719b7a2226e Mon Sep 17 00:00:00 2001 From: Matthew Xie Date: Fri, 1 Mar 2013 18:41:02 -0800 Subject: Unhide Bluetooth Low Energy public APIs Updated API headers. Add BluetoothManager to be retrieved by context.getSystemService(Context.BLUETOOTH_SERVICE). LE scan functions are placed in BluetoothAdapter The GATT API are device driven instead of a profile-driver. bug 8450158 Change-Id: I424a4cedaac3ef8120a05996500008dd210d2553 --- .../android/bluetooth/BluetoothGattService.java | 63 ++++++++++++++++------ 1 file changed, 47 insertions(+), 16 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index 6a3ce66e8f..c3b3cfe239 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -22,8 +22,7 @@ import java.util.List; import java.util.UUID; /** - * Represents a Bluetooth Gatt Service - * @hide + * Represents a Bluetooth GATT Service */ public class BluetoothGattService { @@ -81,9 +80,14 @@ public class BluetoothGattService { /** * Create a new BluetoothGattService. - * @hide + *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. + * + * @param uuid The UUID for this service + * @param serviceType The type of this service, + * {@link BluetoothGattService#SERVICE_TYPE_PRIMARY} or + * {@link BluetoothGattService#SERVICE_TYPE_SECONDARY} */ - /*package*/ BluetoothGattService(UUID uuid, int serviceType) { + public BluetoothGattService(UUID uuid, int serviceType) { mDevice = null; mUuid = uuid; mInstanceId = 0; @@ -114,12 +118,29 @@ public class BluetoothGattService { return mDevice; } + /** + * Add an included service to this service. + *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. + * + * @param service The service to be added + * @return true, if the included service was added to the service + */ + public boolean addService(BluetoothGattService service) { + mIncludedServices.add(service); + return true; + } + /** * Add a characteristic to this service. - * @hide + *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. + * + * @param characteristic The characteristics to be added + * @return true, if the characteristic was added to the service */ - /*package*/ void addCharacteristic(BluetoothGattCharacteristic characteristic) { + public boolean addCharacteristic(BluetoothGattCharacteristic characteristic) { mCharacteristics.add(characteristic); + characteristic.setService(this); + return true; } /** @@ -135,6 +156,15 @@ public class BluetoothGattService { return null; } + /** + * Force the instance ID. + * This is needed for conformance testing only. + * @hide + */ + public void setInstanceId(int instanceId) { + mInstanceId = instanceId; + } + /** * Get the handle count override (conformance testing. * @hide @@ -143,6 +173,15 @@ public class BluetoothGattService { return mHandles; } + /** + * Force the number of handles to reserve for this service. + * This is needed for conformance testing only. + * @hide + */ + public void setHandles(int handles) { + mHandles = handles; + } + /** * Add an included service to the internal map. * @hide @@ -153,7 +192,6 @@ public class BluetoothGattService { /** * Returns the UUID of this service - *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. * * @return UUID of this service */ @@ -168,8 +206,6 @@ public class BluetoothGattService { * (ex. multiple battery services for different batteries), the instance * ID is used to distuinguish services. * - *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. - * * @return Instance ID of this service */ public int getInstanceId() { @@ -178,15 +214,13 @@ public class BluetoothGattService { /** * Get the type of this service (primary/secondary) - * @hide */ public int getType() { return mServiceType; } /** - * Get the list of included Gatt services for this service. - *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. + * Get the list of included GATT services for this service. * * @return List of included services or empty list if no included services * were discovered. @@ -197,7 +231,6 @@ public class BluetoothGattService { /** * Returns a list of characteristics included in this service. - *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. * * @return Characteristics included in this service */ @@ -217,9 +250,7 @@ public class BluetoothGattService { * UUID, the first instance of a characteristic with the given UUID * is returned. * - *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. - * - * @return Gatt characteristic object or null if no characteristic with the + * @return GATT characteristic object or null if no characteristic with the * given UUID was found. */ public BluetoothGattCharacteristic getCharacteristic(UUID uuid) { -- cgit v1.2.3 From 18b2c9aa6d972220ebd0669280377b4e97ff3459 Mon Sep 17 00:00:00 2001 From: Matthew Xie Date: Wed, 3 Apr 2013 00:29:27 -0700 Subject: Change BluetoothGattCallback methods argument from BluetoothDevice to BluetoothGatt Change name of BluetoothDevice#connectGattServer to BluetoothDevice#connectGatt Add BluetoothGatt#getDevice to retrieve device from BluetoothGatt Add BluetoothGatt#connect() to reconnect back to the server. Make BluetoothGatt#close() public to clean up/unregister callback Add BluetoothDevice.getType() to return int of bug 8529188 Change-Id: Iebd9ac68cc7a64c43972e617dd3068f66c8ea0b2 --- framework/java/android/bluetooth/BluetoothGattService.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index c3b3cfe239..39a435becb 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -23,6 +23,9 @@ import java.util.UUID; /** * Represents a Bluetooth GATT Service + * + *

Gatt Service contains a collection of {@link BluetoothGattCharacteristic}, + * as well as referenced services. */ public class BluetoothGattService { -- cgit v1.2.3 From 93aa2e43a01a8d908ad34c4de6bfcd037e4fbfee Mon Sep 17 00:00:00 2001 From: Andre Eisenbach Date: Mon, 8 Jul 2013 23:58:16 -0700 Subject: LE: Add instance ID to descriptors (1/4) If a remote devices offers multiple descriptors with the same UUID, the instance ID is used to differentiate between them. Change-Id: I0c36494c980c86abd23f9647196af8d59ef663e9 --- framework/java/android/bluetooth/BluetoothGattService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index 39a435becb..1e66369601 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -152,8 +152,8 @@ public class BluetoothGattService { */ /*package*/ BluetoothGattCharacteristic getCharacteristic(UUID uuid, int instanceId) { for(BluetoothGattCharacteristic characteristic : mCharacteristics) { - if (uuid.equals(characteristic.getUuid()) && - mInstanceId == instanceId) + if (uuid.equals(characteristic.getUuid()) + && characteristic.getInstanceId() == instanceId) return characteristic; } return null; -- cgit v1.2.3 From 2f7544ce3f0c2e0697318e9961c4ced457b71d5f Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Tue, 29 Oct 2013 21:05:37 -0700 Subject: BLE peripheral mode (3/4): Add peripheral mode API. Change-Id: Id9d2f566b6d9ed0fffe73b67efad2e3d045360b4 Conflicts: core/java/android/bluetooth/BluetoothAdapter.java core/java/android/bluetooth/BluetoothGatt.java --- .../android/bluetooth/BluetoothGattService.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index 1e66369601..52bc0f796c 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -15,8 +15,6 @@ */ package android.bluetooth; -import android.bluetooth.BluetoothDevice; - import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -81,6 +79,11 @@ public class BluetoothGattService { */ protected List mIncludedServices; + /** + * Whether the service uuid should be advertised. + */ + private boolean mAdvertisePreferred; + /** * Create a new BluetoothGattService. *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. @@ -263,4 +266,20 @@ public class BluetoothGattService { } return null; } + + /** + * Returns whether the uuid of the service should be advertised. + * @hide + */ + public boolean isAdvertisePreferred() { + return mAdvertisePreferred; + } + + /** + * Set whether the service uuid should be advertised. + * @hide + */ + public void setAdvertisePreferred(boolean advertisePreferred) { + this.mAdvertisePreferred = advertisePreferred; + } } -- cgit v1.2.3 From c9ba8c7ed1ab4271ef4cd84cac0032d13eb46513 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Tue, 1 Mar 2016 18:50:27 -0800 Subject: 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 --- .../android/bluetooth/BluetoothGattService.java | 90 +++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') 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; *

Gatt Service contains a collection of {@link BluetoothGattCharacteristic}, * as well as referenced services. */ -public class BluetoothGattService { +public class BluetoothGattService implements Parcelable { /** * Primary service @@ -116,6 +119,81 @@ public class BluetoothGattService { mIncludedServices = new ArrayList(); } + /** + * Create a new BluetoothGattService + * @hide + */ + public BluetoothGattService(UUID uuid, int instanceId, int serviceType) { + mDevice = null; + mUuid = uuid; + mInstanceId = instanceId; + mServiceType = serviceType; + mCharacteristics = new ArrayList(); + mIncludedServices = new ArrayList(); + } + + /** + * @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 includedServices = + new ArrayList(mIncludedServices.size()); + for(BluetoothGattService s : mIncludedServices) { + includedServices.add(new BluetoothGattIncludedService(s.getUuid(), + s.getInstanceId(), s.getType())); + } + out.writeTypedList(includedServices); + } + + public static final Parcelable.Creator CREATOR + = new Parcelable.Creator() { + 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(); + + ArrayList chrcs = + in.createTypedArrayList(BluetoothGattCharacteristic.CREATOR); + if (chrcs != null) { + for (BluetoothGattCharacteristic chrc : chrcs) { + chrc.setService(this); + mCharacteristics.add(chrc); + } + } + + mIncludedServices = new ArrayList(); + + ArrayList 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 @@ -124,6 +202,14 @@ public class BluetoothGattService { 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. *

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); } -- cgit v1.2.3 From 8d7adf284bab6292ef6f54435a726bf7293e2998 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Fri, 1 Apr 2016 07:51:45 -0700 Subject: GATT Server refactoring (2/4) Bug: 27999121 Change-Id: Ia5f91298a4b01b62adebc8adc30f27f757259588 --- framework/java/android/bluetooth/BluetoothGattService.java | 1 - 1 file changed, 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index a4e1dc01d0..c888a451e9 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -250,7 +250,6 @@ public class BluetoothGattService implements Parcelable { /** * Force the instance ID. - * This is needed for conformance testing only. * @hide */ public void setInstanceId(int instanceId) { -- cgit v1.2.3 From 910201beb0bde1dcf6b33e4ec5d1eb60042419d8 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 22 Aug 2017 16:06:54 -0700 Subject: Fix checkstyle errors (1/2) * Automatic style corrections through IDE Bug: 63596319 Test: make checkbuild, no manual changes, no functional changes Change-Id: I2397d55abc34c9b7a9b748bec6137778df3421a7 --- .../android/bluetooth/BluetoothGattService.java | 56 ++++++++++++++-------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index c888a451e9..db820d874a 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -16,8 +16,9 @@ package android.bluetooth; import android.os.Parcel; -import android.os.Parcelable; import android.os.ParcelUuid; +import android.os.Parcelable; + import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -44,30 +45,35 @@ public class BluetoothGattService implements Parcelable { /** * The remote device his service is associated with. * This applies to client applications only. + * * @hide */ protected BluetoothDevice mDevice; /** * The UUID of this service. + * * @hide */ protected UUID mUuid; /** * Instance ID for this service. + * * @hide */ protected int mInstanceId; /** * Handle counter override (for conformance testing). + * * @hide */ protected int mHandles = 0; /** * Service type (Primary/Secondary). + * * @hide */ protected int mServiceType; @@ -93,8 +99,8 @@ public class BluetoothGattService implements Parcelable { * * @param uuid The UUID for this service * @param serviceType The type of this service, - * {@link BluetoothGattService#SERVICE_TYPE_PRIMARY} or - * {@link BluetoothGattService#SERVICE_TYPE_SECONDARY} + * {@link BluetoothGattService#SERVICE_TYPE_PRIMARY} + * or {@link BluetoothGattService#SERVICE_TYPE_SECONDARY} */ public BluetoothGattService(UUID uuid, int serviceType) { mDevice = null; @@ -107,10 +113,11 @@ public class BluetoothGattService implements Parcelable { /** * Create a new BluetoothGattService + * * @hide */ /*package*/ BluetoothGattService(BluetoothDevice device, UUID uuid, - int instanceId, int serviceType) { + int instanceId, int serviceType) { mDevice = device; mUuid = uuid; mInstanceId = instanceId; @@ -121,6 +128,7 @@ public class BluetoothGattService implements Parcelable { /** * Create a new BluetoothGattService + * * @hide */ public BluetoothGattService(UUID uuid, int instanceId, int serviceType) { @@ -148,12 +156,12 @@ public class BluetoothGattService implements Parcelable { ArrayList includedServices = new ArrayList(mIncludedServices.size()); - for(BluetoothGattService s : mIncludedServices) { + for (BluetoothGattService s : mIncludedServices) { includedServices.add(new BluetoothGattIncludedService(s.getUuid(), - s.getInstanceId(), s.getType())); + s.getInstanceId(), s.getType())); } out.writeTypedList(includedServices); - } + } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @@ -167,7 +175,7 @@ public class BluetoothGattService implements Parcelable { }; private BluetoothGattService(Parcel in) { - mUuid = ((ParcelUuid)in.readParcelable(null)).getUuid(); + mUuid = ((ParcelUuid) in.readParcelable(null)).getUuid(); mInstanceId = in.readInt(); mServiceType = in.readInt(); @@ -189,13 +197,14 @@ public class BluetoothGattService implements Parcelable { if (chrcs != null) { for (BluetoothGattIncludedService isvc : inclSvcs) { mIncludedServices.add(new BluetoothGattService(null, isvc.getUuid(), - isvc.getInstanceId(), isvc.getType())); + isvc.getInstanceId(), isvc.getType())); } } } /** * Returns the device associated with this service. + * * @hide */ /*package*/ BluetoothDevice getDevice() { @@ -204,6 +213,7 @@ public class BluetoothGattService implements Parcelable { /** * Returns the device associated with this service. + * * @hide */ /*package*/ void setDevice(BluetoothDevice device) { @@ -237,19 +247,22 @@ public class BluetoothGattService implements Parcelable { /** * Get characteristic by UUID and instanceId. + * * @hide */ /*package*/ BluetoothGattCharacteristic getCharacteristic(UUID uuid, int instanceId) { - for(BluetoothGattCharacteristic characteristic : mCharacteristics) { + for (BluetoothGattCharacteristic characteristic : mCharacteristics) { if (uuid.equals(characteristic.getUuid()) - && characteristic.getInstanceId() == instanceId) + && characteristic.getInstanceId() == instanceId) { return characteristic; + } } return null; } /** * Force the instance ID. + * * @hide */ public void setInstanceId(int instanceId) { @@ -258,6 +271,7 @@ public class BluetoothGattService implements Parcelable { /** * Get the handle count override (conformance testing. + * * @hide */ /*package*/ int getHandles() { @@ -267,6 +281,7 @@ public class BluetoothGattService implements Parcelable { /** * Force the number of handles to reserve for this service. * This is needed for conformance testing only. + * * @hide */ public void setHandles(int handles) { @@ -275,6 +290,7 @@ public class BluetoothGattService implements Parcelable { /** * Add an included service to the internal map. + * * @hide */ public void addIncludedService(BluetoothGattService includedService) { @@ -313,8 +329,7 @@ public class BluetoothGattService implements Parcelable { /** * Get the list of included GATT services for this service. * - * @return List of included services or empty list if no included services - * were discovered. + * @return List of included services or empty list if no included services were discovered. */ public List getIncludedServices() { return mIncludedServices; @@ -341,30 +356,33 @@ public class BluetoothGattService implements Parcelable { * UUID, the first instance of a characteristic with the given UUID * is returned. * - * @return GATT characteristic object or null if no characteristic with the - * given UUID was found. + * @return GATT characteristic object or null if no characteristic with the given UUID was + * found. */ public BluetoothGattCharacteristic getCharacteristic(UUID uuid) { - for(BluetoothGattCharacteristic characteristic : mCharacteristics) { - if (uuid.equals(characteristic.getUuid())) + for (BluetoothGattCharacteristic characteristic : mCharacteristics) { + if (uuid.equals(characteristic.getUuid())) { return characteristic; + } } return null; } /** * Returns whether the uuid of the service should be advertised. + * * @hide */ public boolean isAdvertisePreferred() { - return mAdvertisePreferred; + return mAdvertisePreferred; } /** * Set whether the service uuid should be advertised. + * * @hide */ public void setAdvertisePreferred(boolean advertisePreferred) { - this.mAdvertisePreferred = advertisePreferred; + this.mAdvertisePreferred = advertisePreferred; } } -- cgit v1.2.3 From 9e045d26d0128826b40520f523307d8d16473779 Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 22 Aug 2017 21:21:23 -0700 Subject: Fix checkstyle errors (2/2) * Manual style corrections with IDE assistance * Variable name refactors are done through IDE * Corrected general style errors such as: - "final private var" -> "private final var" - "&&", "+", "||" should not be at the end of line - Non-static private variable should be like "mVar" - Private static variable should be like "sVar" - Code file should always end with newline - Inherited methods should be annotated with @Override and no @hide tags - Public methods should always have a JavaDoc entry - "int[] array" is preferred over "int array[]" - private methods should be accessed without "this." when there is no name collisions. - "boolean ? true : false" -> boolean - "boolean ? false : true" -> !boolean - "boolean == true" OR "boolean != false" -> boolean - "boolean != true" OR "boolean == false" -> !boolean Bug: 63596319 Test: make checkbuild, no functional changes Change-Id: Iabdc2be912a32dd63a53213d175cf1bfef268ccd --- framework/java/android/bluetooth/BluetoothGattService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index db820d874a..ce1dc1ce63 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -163,8 +163,8 @@ public class BluetoothGattService implements Parcelable { out.writeTypedList(includedServices); } - public static final Parcelable.Creator CREATOR - = new Parcelable.Creator() { + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { public BluetoothGattService createFromParcel(Parcel in) { return new BluetoothGattService(in); } @@ -217,7 +217,7 @@ public class BluetoothGattService implements Parcelable { * @hide */ /*package*/ void setDevice(BluetoothDevice device) { - this.mDevice = device; + mDevice = device; } /** @@ -383,6 +383,6 @@ public class BluetoothGattService implements Parcelable { * @hide */ public void setAdvertisePreferred(boolean advertisePreferred) { - this.mAdvertisePreferred = advertisePreferred; + mAdvertisePreferred = advertisePreferred; } } -- cgit v1.2.3 From de2b201ddbf64e0a14475155ce5635d829ea5692 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Wed, 1 Aug 2018 15:00:35 +0100 Subject: Add @UnsupportedAppUsage annotations For packages: android.bluetooth.le android.bluetooth This is an automatically generated CL. See go/UnsupportedAppUsage for more details. Exempted-From-Owner-Approval: Mechanical changes to the codebase which have been approved by Android API council and announced on android-eng@ Bug: 110868826 Test: m Change-Id: I88a1311e27c5f9a5f9d1035db76034f86f650efc --- framework/java/android/bluetooth/BluetoothGattService.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index ce1dc1ce63..8e740ee387 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -15,6 +15,7 @@ */ package android.bluetooth; +import android.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.ParcelUuid; import android.os.Parcelable; @@ -48,6 +49,7 @@ public class BluetoothGattService implements Parcelable { * * @hide */ + @UnsupportedAppUsage protected BluetoothDevice mDevice; /** @@ -265,6 +267,7 @@ public class BluetoothGattService implements Parcelable { * * @hide */ + @UnsupportedAppUsage public void setInstanceId(int instanceId) { mInstanceId = instanceId; } @@ -382,6 +385,7 @@ public class BluetoothGattService implements Parcelable { * * @hide */ + @UnsupportedAppUsage public void setAdvertisePreferred(boolean advertisePreferred) { mAdvertisePreferred = advertisePreferred; } -- cgit v1.2.3 From 13613a3f176ab3e10367685367443dddeee77db5 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 28 Feb 2019 12:06:45 -0700 Subject: All Parcelable CREATOR fields are @NonNull. If they were null, then the Parcelable would fail to work. Bug: 126726802 Test: manual Change-Id: I7929ffa2f20e5de1c8e68e8263cca99496e9d014 Exempt-From-Owner-Approval: Trivial API annotations --- framework/java/android/bluetooth/BluetoothGattService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index 8e740ee387..c20faf9db6 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -165,7 +165,7 @@ public class BluetoothGattService implements Parcelable { out.writeTypedList(includedServices); } - public static final Parcelable.Creator CREATOR = + public static final @android.annotation.NonNull Parcelable.Creator CREATOR = new Parcelable.Creator() { public BluetoothGattService createFromParcel(Parcel in) { return new BluetoothGattService(in); -- cgit v1.2.3 From d8fe38cc98bb4f49cd0c4ab9d7855f98ee1209f3 Mon Sep 17 00:00:00 2001 From: Artur Satayev Date: Tue, 10 Dec 2019 17:47:52 +0000 Subject: Use new UnsupportedAppUsage annotation. Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library. Bug: 145132366 Test: m && diff unsupportedappusage_index.csv Change-Id: I6ab53570aca580fbee1fcc927871caa09780f58f Merged-In: I6ab53570aca580fbee1fcc927871caa09780f58f --- framework/java/android/bluetooth/BluetoothGattService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index c20faf9db6..13d6d7021e 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -15,7 +15,7 @@ */ package android.bluetooth; -import android.annotation.UnsupportedAppUsage; +import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.ParcelUuid; import android.os.Parcelable; -- cgit v1.2.3 From c5386afbc18b5164c381b1d8e099327953205436 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 11 Sep 2020 14:57:21 -0600 Subject: Update language to comply with Android's inclusive language guidance See https://source.android.com/setup/contribute/respectful-code for reference Test: none Bug: 168334533 Exempt-From-Owner-Approval: docs updates Change-Id: I245b8d9cac722da76ea67983738a3cbb9deb68df --- framework/java/android/bluetooth/BluetoothGattService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index 13d6d7021e..e7809aeb1b 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -44,7 +44,7 @@ public class BluetoothGattService implements Parcelable { /** - * The remote device his service is associated with. + * The remote device this service is associated with. * This applies to client applications only. * * @hide -- cgit v1.2.3 From bc9a809f18a3b0ec23cbc39802fb4928c2074ea3 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Tue, 27 Oct 2020 11:47:29 +0000 Subject: Add maxTargetSdk restriction to unused APIs. These are APIs that have @UnsupportedAppUsage but for which we don't have any evidence of them currently being used, so should be safe to remove from the unsupported list. Bug: 170729553 Test: Treehugger Change-Id: I4c8fd0006f950de9955242e93968fb0996ceb372 --- framework/java/android/bluetooth/BluetoothGattService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index e7809aeb1b..23dc7c8308 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -16,6 +16,7 @@ package android.bluetooth; import android.compat.annotation.UnsupportedAppUsage; +import android.os.Build; import android.os.Parcel; import android.os.ParcelUuid; import android.os.Parcelable; @@ -385,7 +386,7 @@ public class BluetoothGattService implements Parcelable { * * @hide */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public void setAdvertisePreferred(boolean advertisePreferred) { mAdvertisePreferred = advertisePreferred; } -- cgit v1.2.3 From bddbb77484a3694357df750c5e7df9527f409c8a Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Wed, 28 Oct 2020 19:38:11 +0000 Subject: Revert "Add maxTargetSdk restriction to unused APIs." This reverts commit bc9a809f18a3b0ec23cbc39802fb4928c2074ea3. Reason for revert: Droidcop-triggered revert due to breakage https://android-build.googleplex.com/builds/quarterdeck?testMethod=testAppZygotePreload&testClass=android.app.cts.ServiceTest&atpConfigName=suite%2Ftest-mapping-presubmit-retry_cloud-tf&testModule=CtsAppTestCases&fkbb=6936597&lkbb=6936969&lkgb=6936551&testResults=true&branch=git_master&target=cf_x86_phone-userdebug>, bug b/171886397 Bug: 171886397 Change-Id: Ibe0f0430a3451477c1ee8ef56a596e91ea1e7672 --- framework/java/android/bluetooth/BluetoothGattService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index 23dc7c8308..e7809aeb1b 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -16,7 +16,6 @@ package android.bluetooth; import android.compat.annotation.UnsupportedAppUsage; -import android.os.Build; import android.os.Parcel; import android.os.ParcelUuid; import android.os.Parcelable; @@ -386,7 +385,7 @@ public class BluetoothGattService implements Parcelable { * * @hide */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @UnsupportedAppUsage public void setAdvertisePreferred(boolean advertisePreferred) { mAdvertisePreferred = advertisePreferred; } -- cgit v1.2.3 From cba870b777fc6d2a03a27758cf1db1c38556efe8 Mon Sep 17 00:00:00 2001 From: Mathew Inwood Date: Tue, 27 Oct 2020 11:47:29 +0000 Subject: Add maxTargetSdk restriction to unused APIs. These are APIs that have @UnsupportedAppUsage but for which we don't have any evidence of them currently being used, so should be safe to remove from the unsupported list. This is a resubmit of ag/12929664 with some APIs excluded that caused test failures; see bugs 171886397, 171888296, 171864568. APIs excluded: Landroid/bluetooth/le/ScanRecord;->parseFromBytes([B)Landroid/bluetooth/le/ScanRecord; Landroid/os/Process;->myPpid()I Landroid/os/SharedMemory;->getFd()I Landroid/hardware/input/InputManager;->INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH:I Bug: 170729553 Test: Treehugger Change-Id: I8285daa8530260251ecad6f3f38f98e263629ca7 --- framework/java/android/bluetooth/BluetoothGattService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index e7809aeb1b..23dc7c8308 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -16,6 +16,7 @@ package android.bluetooth; import android.compat.annotation.UnsupportedAppUsage; +import android.os.Build; import android.os.Parcel; import android.os.ParcelUuid; import android.os.Parcelable; @@ -385,7 +386,7 @@ public class BluetoothGattService implements Parcelable { * * @hide */ - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public void setAdvertisePreferred(boolean advertisePreferred) { mAdvertisePreferred = advertisePreferred; } -- cgit v1.2.3 From 8f80e4a05b3f1b227f40de5ec0e9a6297154ffc0 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 2 Apr 2021 08:06:09 -0600 Subject: Update Bluetooth API annotations. Recent work has introduced a new "Nearby devices" runtime permission which protects all existing Bluetooth APIs; we've done this by defining a to convert the old BLUETOOTH and BLUETOOTH_ADMIN permissions into one of three new permissions: * BLUETOOTH_ADVERTISE: Required to be able to advertise to nearby Bluetooth devices. * BLUETOOTH_CONNECT: Allows applications to connect to paired bluetooth devices. * BLUETOOTH_SCAN: Required to be able to discover and pair nearby Bluetooth devices. At its core, this change begins updating the Bluetooth APIs to have correct @RequiresPermission indicating which permission is actually enforced internally. To ensure alignment across Binder, the newly added "RequiresPermissionChecker" Error Prone checker was used to discover any inconsistencies, ensuring correctness from server-side enforcement up through to the public APIs. In addition, since developers will continue building apps for both modern and legacy platforms, this change introduces new auto-doc annotations which will emit helpful consistent documentation describing the behavior of older devices that are still using the old permission model. Bug: 183626724 Test: ./build/soong/soong_ui.bash --make-mode Bluetooth RUN_ERROR_PRONE=true Change-Id: I02aa127e8e07f239561f4f2a3bbdfc6fccb82f7f --- framework/java/android/bluetooth/BluetoothGattService.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothGattService.java') diff --git a/framework/java/android/bluetooth/BluetoothGattService.java b/framework/java/android/bluetooth/BluetoothGattService.java index 23dc7c8308..f64d09fc30 100644 --- a/framework/java/android/bluetooth/BluetoothGattService.java +++ b/framework/java/android/bluetooth/BluetoothGattService.java @@ -15,6 +15,9 @@ */ package android.bluetooth; +import android.annotation.RequiresPermission; +import android.bluetooth.annotations.RequiresBluetoothConnectPermission; +import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; import android.os.Parcel; @@ -98,7 +101,6 @@ public class BluetoothGattService implements Parcelable { /** * Create a new BluetoothGattService. - *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. * * @param uuid The UUID for this service * @param serviceType The type of this service, @@ -225,11 +227,11 @@ public class BluetoothGattService implements Parcelable { /** * Add an included service to this service. - *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. * * @param service The service to be added * @return true, if the included service was added to the service */ + @RequiresLegacyBluetoothPermission public boolean addService(BluetoothGattService service) { mIncludedServices.add(service); return true; @@ -237,11 +239,11 @@ public class BluetoothGattService implements Parcelable { /** * Add a characteristic to this service. - *

Requires {@link android.Manifest.permission#BLUETOOTH} permission. * * @param characteristic The characteristics to be added * @return true, if the characteristic was added to the service */ + @RequiresLegacyBluetoothPermission public boolean addCharacteristic(BluetoothGattCharacteristic characteristic) { mCharacteristics.add(characteristic); characteristic.setService(this); -- cgit v1.2.3