19908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta/* 29908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Copyright (C) 2013 The Android Open Source Project 39908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 49908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Licensed under the Apache License, Version 2.0 (the "License"); 59908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * you may not use this file except in compliance with the License. 69908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * You may obtain a copy of the License at 79908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 89908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * http://www.apache.org/licenses/LICENSE-2.0 99908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Unless required by applicable law or agreed to in writing, software 119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * distributed under the License is distributed on an "AS IS" BASIS, 129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * See the License for the specific language governing permissions and 149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * limitations under the License. 159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battapackage android.bluetooth; 179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battaimport java.util.ArrayList; 199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battaimport java.util.List; 209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battaimport java.util.UUID; 219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta/** 23ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Represents a Bluetooth GATT Service 2433ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * 2533ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * <p> Gatt Service contains a collection of {@link BluetoothGattCharacteristic}, 2633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * as well as referenced services. 279908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 289908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battapublic class BluetoothGattService { 299908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Primary service 329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public static final int SERVICE_TYPE_PRIMARY = 0; 349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Secondary service (included by primary services) 379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public static final int SERVICE_TYPE_SECONDARY = 1; 399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * The remote device his service is associated with. 439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * This applies to client applications only. 449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected BluetoothDevice mDevice; 479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * The UUID of this service. 509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected UUID mUuid; 539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Instance ID for this service. 569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected int mInstanceId; 599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Handle counter override (for conformance testing). 629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 649908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected int mHandles = 0; 659908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 669908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 679908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Service type (Primary/Secondary). 689908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 699908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 709908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected int mServiceType; 719908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 729908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 739908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * List of characteristics included in this service. 749908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 759908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected List<BluetoothGattCharacteristic> mCharacteristics; 769908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 779908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 789908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * List of included services for this service. 799908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 809908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected List<BluetoothGattService> mIncludedServices; 819908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 829908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 8318c76934f62410d1499e2eb63635b5dd8da5013aWei Wang * Whether the service uuid should be advertised. 8418c76934f62410d1499e2eb63635b5dd8da5013aWei Wang */ 8518c76934f62410d1499e2eb63635b5dd8da5013aWei Wang private boolean mAdvertisePreferred; 8618c76934f62410d1499e2eb63635b5dd8da5013aWei Wang 8718c76934f62410d1499e2eb63635b5dd8da5013aWei Wang /** 889908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Create a new BluetoothGattService. 89ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. 90ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * 91ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param uuid The UUID for this service 92ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param serviceType The type of this service, 93ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * {@link BluetoothGattService#SERVICE_TYPE_PRIMARY} or 94ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * {@link BluetoothGattService#SERVICE_TYPE_SECONDARY} 959908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 96ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie public BluetoothGattService(UUID uuid, int serviceType) { 979908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mDevice = null; 989908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mUuid = uuid; 999908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mInstanceId = 0; 1009908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mServiceType = serviceType; 1019908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mCharacteristics = new ArrayList<BluetoothGattCharacteristic>(); 1029908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mIncludedServices = new ArrayList<BluetoothGattService>(); 1039908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1049908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1059908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 1069908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Create a new BluetoothGattService 1079908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 1089908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1099908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /*package*/ BluetoothGattService(BluetoothDevice device, UUID uuid, 1109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta int instanceId, int serviceType) { 1119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mDevice = device; 1129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mUuid = uuid; 1139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mInstanceId = instanceId; 1149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mServiceType = serviceType; 1159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mCharacteristics = new ArrayList<BluetoothGattCharacteristic>(); 1169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mIncludedServices = new ArrayList<BluetoothGattService>(); 1179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 1209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Returns the device associated with this service. 1219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 1229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /*package*/ BluetoothDevice getDevice() { 1249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mDevice; 1259908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1269908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1279908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 128ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Add an included service to this service. 129ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. 130ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * 131ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param service The service to be added 132ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @return true, if the included service was added to the service 133ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie */ 134ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie public boolean addService(BluetoothGattService service) { 135ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie mIncludedServices.add(service); 136ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie return true; 137ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } 138ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie 139ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie /** 1409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Add a characteristic to this service. 141ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. 142ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * 143ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param characteristic The characteristics to be added 144ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @return true, if the characteristic was added to the service 1459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 146ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie public boolean addCharacteristic(BluetoothGattCharacteristic characteristic) { 1479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mCharacteristics.add(characteristic); 148ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie characteristic.setService(this); 149ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie return true; 1509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 1539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Get characteristic by UUID and instanceId. 1549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 1559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /*package*/ BluetoothGattCharacteristic getCharacteristic(UUID uuid, int instanceId) { 1579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta for(BluetoothGattCharacteristic characteristic : mCharacteristics) { 15825b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach if (uuid.equals(characteristic.getUuid()) 15925b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach && characteristic.getInstanceId() == instanceId) 1609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return characteristic; 1619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return null; 1639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1649908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1659908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 166ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Force the instance ID. 167ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * This is needed for conformance testing only. 168ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @hide 169ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie */ 170ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie public void setInstanceId(int instanceId) { 171ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie mInstanceId = instanceId; 172ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } 173ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie 174ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie /** 1759908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Get the handle count override (conformance testing. 1769908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 1779908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1789908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /*package*/ int getHandles() { 1799908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mHandles; 1809908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1819908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1829908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 183ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Force the number of handles to reserve for this service. 184ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * This is needed for conformance testing only. 185ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @hide 186ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie */ 187ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie public void setHandles(int handles) { 188ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie mHandles = handles; 189ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } 190ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie 191ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie /** 1929908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Add an included service to the internal map. 1939908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 1949908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1959908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /*package*/ void addIncludedService(BluetoothGattService includedService) { 1969908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mIncludedServices.add(includedService); 1979908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1989908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1999908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 2009908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Returns the UUID of this service 2019908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2029908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @return UUID of this service 2039908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2049908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public UUID getUuid() { 2059908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mUuid; 2069908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2079908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 2089908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 2099908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Returns the instance ID for this service 2109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>If a remote device offers multiple services with the same UUID 2129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * (ex. multiple battery services for different batteries), the instance 2139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * ID is used to distuinguish services. 2149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @return Instance ID of this service 2169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public int getInstanceId() { 2189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mInstanceId; 2199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 2219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 2229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Get the type of this service (primary/secondary) 2239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public int getType() { 2259908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mServiceType; 2269908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2279908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 2289908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 229ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Get the list of included GATT services for this service. 2309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @return List of included services or empty list if no included services 2329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * were discovered. 2339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public List<BluetoothGattService> getIncludedServices() { 2359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mIncludedServices; 2369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 2389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 2399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Returns a list of characteristics included in this service. 2409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @return Characteristics included in this service 2429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public List<BluetoothGattCharacteristic> getCharacteristics() { 2449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mCharacteristics; 2459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 2479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 2489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Returns a characteristic with a given UUID out of the list of 2499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * characteristics offered by this service. 2509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>This is a convenience function to allow access to a given characteristic 2529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * without enumerating over the list returned by {@link #getCharacteristics} 2539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * manually. 2549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>If a remote service offers multiple characteristics with the same 2569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * UUID, the first instance of a characteristic with the given UUID 2579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * is returned. 2589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 259ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @return GATT characteristic object or null if no characteristic with the 2609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * given UUID was found. 2619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public BluetoothGattCharacteristic getCharacteristic(UUID uuid) { 2639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta for(BluetoothGattCharacteristic characteristic : mCharacteristics) { 2649908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta if (uuid.equals(characteristic.getUuid())) 2659908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return characteristic; 2669908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2679908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return null; 2689908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 26918c76934f62410d1499e2eb63635b5dd8da5013aWei Wang 27018c76934f62410d1499e2eb63635b5dd8da5013aWei Wang /** 27118c76934f62410d1499e2eb63635b5dd8da5013aWei Wang * Returns whether the uuid of the service should be advertised. 27218c76934f62410d1499e2eb63635b5dd8da5013aWei Wang * @hide 27318c76934f62410d1499e2eb63635b5dd8da5013aWei Wang */ 27418c76934f62410d1499e2eb63635b5dd8da5013aWei Wang public boolean isAdvertisePreferred() { 27518c76934f62410d1499e2eb63635b5dd8da5013aWei Wang return mAdvertisePreferred; 27618c76934f62410d1499e2eb63635b5dd8da5013aWei Wang } 27718c76934f62410d1499e2eb63635b5dd8da5013aWei Wang 27818c76934f62410d1499e2eb63635b5dd8da5013aWei Wang /** 27918c76934f62410d1499e2eb63635b5dd8da5013aWei Wang * Set whether the service uuid should be advertised. 28018c76934f62410d1499e2eb63635b5dd8da5013aWei Wang * @hide 28118c76934f62410d1499e2eb63635b5dd8da5013aWei Wang */ 28218c76934f62410d1499e2eb63635b5dd8da5013aWei Wang public void setAdvertisePreferred(boolean advertisePreferred) { 28318c76934f62410d1499e2eb63635b5dd8da5013aWei Wang this.mAdvertisePreferred = advertisePreferred; 28418c76934f62410d1499e2eb63635b5dd8da5013aWei Wang } 2859908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta} 286