BluetoothGattService.java revision ddf7e4756c31d0ed90802f98abeaa79df6d16b2a
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 android.bluetooth.BluetoothDevice; 199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battaimport java.util.ArrayList; 219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battaimport java.util.List; 229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battaimport java.util.UUID; 239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta/** 25ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Represents a Bluetooth GATT Service 269908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 279908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battapublic class BluetoothGattService { 289908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 299908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Primary service 319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public static final int SERVICE_TYPE_PRIMARY = 0; 339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Secondary service (included by primary services) 369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public static final int SERVICE_TYPE_SECONDARY = 1; 389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * The remote device his service is associated with. 429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * This applies to client applications only. 439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected BluetoothDevice mDevice; 469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * The UUID of this service. 499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected UUID mUuid; 529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Instance ID for this service. 559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected int mInstanceId; 589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Handle counter override (for conformance testing). 619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected int mHandles = 0; 649908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 659908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 669908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Service type (Primary/Secondary). 679908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 689908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 699908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected int mServiceType; 709908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 719908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 729908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * List of characteristics included in this service. 739908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 749908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected List<BluetoothGattCharacteristic> mCharacteristics; 759908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 769908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 779908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * List of included services for this service. 789908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 799908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta protected List<BluetoothGattService> mIncludedServices; 809908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 819908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 829908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Create a new BluetoothGattService. 83ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. 84ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * 85ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param uuid The UUID for this service 86ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param serviceType The type of this service, 87ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * {@link BluetoothGattService#SERVICE_TYPE_PRIMARY} or 88ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * {@link BluetoothGattService#SERVICE_TYPE_SECONDARY} 899908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 90ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie public BluetoothGattService(UUID uuid, int serviceType) { 919908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mDevice = null; 929908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mUuid = uuid; 939908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mInstanceId = 0; 949908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mServiceType = serviceType; 959908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mCharacteristics = new ArrayList<BluetoothGattCharacteristic>(); 969908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mIncludedServices = new ArrayList<BluetoothGattService>(); 979908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 989908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 999908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 1009908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Create a new BluetoothGattService 1019908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 1029908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1039908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /*package*/ BluetoothGattService(BluetoothDevice device, UUID uuid, 1049908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta int instanceId, int serviceType) { 1059908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mDevice = device; 1069908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mUuid = uuid; 1079908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mInstanceId = instanceId; 1089908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mServiceType = serviceType; 1099908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mCharacteristics = new ArrayList<BluetoothGattCharacteristic>(); 1109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mIncludedServices = new ArrayList<BluetoothGattService>(); 1119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 1149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Returns the device associated with this service. 1159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 1169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /*package*/ BluetoothDevice getDevice() { 1189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mDevice; 1199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 122ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Add an included service to this service. 123ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. 124ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * 125ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param service The service to be added 126ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @return true, if the included service was added to the service 127ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie */ 128ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie public boolean addService(BluetoothGattService service) { 129ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie mIncludedServices.add(service); 130ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie return true; 131ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } 132ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie 133ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie /** 1349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Add a characteristic to this service. 135ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission. 136ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * 137ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @param characteristic The characteristics to be added 138ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @return true, if the characteristic was added to the service 1399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 140ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie public boolean addCharacteristic(BluetoothGattCharacteristic characteristic) { 1419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mCharacteristics.add(characteristic); 142ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie characteristic.setService(this); 143ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie return true; 1449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 1479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Get characteristic by UUID and instanceId. 1489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 1499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /*package*/ BluetoothGattCharacteristic getCharacteristic(UUID uuid, int instanceId) { 1519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta for(BluetoothGattCharacteristic characteristic : mCharacteristics) { 1529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta if (uuid.equals(characteristic.getUuid()) && 1539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mInstanceId == instanceId) 1549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return characteristic; 1559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return null; 1579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 160ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Force the instance ID. 161ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * This is needed for conformance testing only. 162ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @hide 163ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie */ 164ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie public void setInstanceId(int instanceId) { 165ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie mInstanceId = instanceId; 166ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } 167ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie 168ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie /** 1699908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Get the handle count override (conformance testing. 1709908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 1719908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1729908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /*package*/ int getHandles() { 1739908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mHandles; 1749908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1759908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1769908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 177ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Force the number of handles to reserve for this service. 178ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * This is needed for conformance testing only. 179ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @hide 180ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie */ 181ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie public void setHandles(int handles) { 182ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie mHandles = handles; 183ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie } 184ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie 185ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie /** 1869908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Add an included service to the internal map. 1879908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @hide 1889908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1899908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /*package*/ void addIncludedService(BluetoothGattService includedService) { 1909908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta mIncludedServices.add(includedService); 1919908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 1929908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 1939908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 1949908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Returns the UUID of this service 1959908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 1969908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @return UUID of this service 1979908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 1989908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public UUID getUuid() { 1999908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mUuid; 2009908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2019908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 2029908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 2039908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Returns the instance ID for this service 2049908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2059908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>If a remote device offers multiple services with the same UUID 2069908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * (ex. multiple battery services for different batteries), the instance 2079908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * ID is used to distuinguish services. 2089908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2099908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @return Instance ID of this service 2109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public int getInstanceId() { 2129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mInstanceId; 2139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 2159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 2169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Get the type of this service (primary/secondary) 2179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public int getType() { 2199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mServiceType; 2209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 2229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 223ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Get the list of included GATT services for this service. 2249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2259908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @return List of included services or empty list if no included services 2269908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * were discovered. 2279908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2289908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public List<BluetoothGattService> getIncludedServices() { 2299908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mIncludedServices; 2309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 2329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 2339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Returns a list of characteristics included in this service. 2349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * @return Characteristics included in this service 2369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public List<BluetoothGattCharacteristic> getCharacteristics() { 2389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return mCharacteristics; 2399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta 2419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta /** 2429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Returns a characteristic with a given UUID out of the list of 2439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * characteristics offered by this service. 2449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>This is a convenience function to allow access to a given characteristic 2469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * without enumerating over the list returned by {@link #getCharacteristics} 2479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * manually. 2489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 2499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * <p>If a remote service offers multiple characteristics with the same 2509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * UUID, the first instance of a characteristic with the given UUID 2519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * is returned. 2529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * 253ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * @return GATT characteristic object or null if no characteristic with the 2549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * given UUID was found. 2559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */ 2569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta public BluetoothGattCharacteristic getCharacteristic(UUID uuid) { 2579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta for(BluetoothGattCharacteristic characteristic : mCharacteristics) { 2589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta if (uuid.equals(characteristic.getUuid())) 2599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return characteristic; 2609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta return null; 2629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta } 2639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta} 264