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
2633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie *
2733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * <p> Gatt Service contains a collection of {@link BluetoothGattCharacteristic},
2833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * as well as referenced services.
299908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */
309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battapublic class BluetoothGattService {
319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Primary service
349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final int SERVICE_TYPE_PRIMARY = 0;
369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Secondary service (included by primary services)
399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final int SERVICE_TYPE_SECONDARY = 1;
419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * The remote device his service is associated with.
459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * This applies to client applications only.
469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected BluetoothDevice mDevice;
499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * The UUID of this service.
529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected UUID mUuid;
559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Instance ID for this service.
589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected int mInstanceId;
619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Handle counter override (for conformance testing).
649908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
659908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
669908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected int mHandles = 0;
679908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
689908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
699908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Service type (Primary/Secondary).
709908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
719908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
729908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected int mServiceType;
739908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
749908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
759908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * List of characteristics included in this service.
769908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
779908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected List<BluetoothGattCharacteristic> mCharacteristics;
789908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
799908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
809908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * List of included services for this service.
819908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
829908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected List<BluetoothGattService> mIncludedServices;
839908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
849908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
859908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Create a new BluetoothGattService.
86ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
87ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *
88ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param uuid The UUID for this service
89ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param serviceType The type of this service,
90ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *        {@link BluetoothGattService#SERVICE_TYPE_PRIMARY} or
91ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *        {@link BluetoothGattService#SERVICE_TYPE_SECONDARY}
929908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
93ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    public BluetoothGattService(UUID uuid, int serviceType) {
949908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mDevice = null;
959908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mUuid = uuid;
969908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mInstanceId = 0;
979908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mServiceType = serviceType;
989908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mCharacteristics = new ArrayList<BluetoothGattCharacteristic>();
999908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mIncludedServices = new ArrayList<BluetoothGattService>();
1009908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
1019908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1029908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
1039908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Create a new BluetoothGattService
1049908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
1059908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1069908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /*package*/ BluetoothGattService(BluetoothDevice device, UUID uuid,
1079908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta                                     int instanceId, int serviceType) {
1089908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mDevice = device;
1099908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mUuid = uuid;
1109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mInstanceId = instanceId;
1119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mServiceType = serviceType;
1129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mCharacteristics = new ArrayList<BluetoothGattCharacteristic>();
1139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mIncludedServices = new ArrayList<BluetoothGattService>();
1149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
1159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
1179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Returns the device associated with this service.
1189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
1199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /*package*/ BluetoothDevice getDevice() {
1219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mDevice;
1229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
1239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
125ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * Add an included service to this service.
126ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
127ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *
128ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param service The service to be added
129ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @return true, if the included service was added to the service
130ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     */
131ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    public boolean addService(BluetoothGattService service) {
132ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        mIncludedServices.add(service);
133ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        return true;
134ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    }
135ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie
136ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    /**
1379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Add a characteristic to this service.
138ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
139ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *
140ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param characteristic The characteristics to be added
141ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @return true, if the characteristic was added to the service
1429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
143ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    public boolean addCharacteristic(BluetoothGattCharacteristic characteristic) {
1449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mCharacteristics.add(characteristic);
145ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        characteristic.setService(this);
146ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        return true;
1479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
1489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
1509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Get characteristic by UUID and instanceId.
1519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
1529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /*package*/ BluetoothGattCharacteristic getCharacteristic(UUID uuid, int instanceId) {
1549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        for(BluetoothGattCharacteristic characteristic : mCharacteristics) {
15525b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach            if (uuid.equals(characteristic.getUuid())
15625b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach             && characteristic.getInstanceId() == instanceId)
1579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta                return characteristic;
1589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        }
1599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return null;
1609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
1619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
163ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * Force the instance ID.
164ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * This is needed for conformance testing only.
165ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @hide
166ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     */
167ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    public void setInstanceId(int instanceId) {
168ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        mInstanceId = instanceId;
169ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    }
170ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie
171ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    /**
1729908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Get the handle count override (conformance testing.
1739908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
1749908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1759908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /*package*/ int getHandles() {
1769908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mHandles;
1779908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
1789908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1799908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
180ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * Force the number of handles to reserve for this service.
181ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * This is needed for conformance testing only.
182ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @hide
183ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     */
184ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    public void setHandles(int handles) {
185ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        mHandles = handles;
186ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    }
187ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie
188ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    /**
1899908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Add an included service to the internal map.
1909908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
1919908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1929908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /*package*/ void addIncludedService(BluetoothGattService includedService) {
1939908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mIncludedServices.add(includedService);
1949908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
1959908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1969908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
1979908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Returns the UUID of this service
1989908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
1999908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @return UUID of this service
2009908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
2019908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public UUID getUuid() {
2029908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mUuid;
2039908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
2049908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
2059908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
2069908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Returns the instance ID for this service
2079908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2089908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>If a remote device offers multiple services with the same UUID
2099908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * (ex. multiple battery services for different batteries), the instance
2109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * ID is used to distuinguish services.
2119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @return Instance ID of this service
2139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
2149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public int getInstanceId() {
2159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mInstanceId;
2169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
2179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
2189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
2199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Get the type of this service (primary/secondary)
2209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
2219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public int getType() {
2229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mServiceType;
2239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
2249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
2259908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
226ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * Get the list of included GATT services for this service.
2279908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2289908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @return List of included services or empty list if no included services
2299908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *         were discovered.
2309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
2319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public List<BluetoothGattService> getIncludedServices() {
2329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mIncludedServices;
2339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
2349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
2359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
2369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Returns a list of characteristics included in this service.
2379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @return Characteristics included in this service
2399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
2409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public List<BluetoothGattCharacteristic> getCharacteristics() {
2419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mCharacteristics;
2429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
2439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
2449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
2459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Returns a characteristic with a given UUID out of the list of
2469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * characteristics offered by this service.
2479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>This is a convenience function to allow access to a given characteristic
2499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * without enumerating over the list returned by {@link #getCharacteristics}
2509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * manually.
2519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>If a remote service offers multiple characteristics with the same
2539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * UUID, the first instance of a characteristic with the given UUID
2549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * is returned.
2559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
256ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @return GATT characteristic object or null if no characteristic with the
2579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *         given UUID was found.
2589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
2599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public BluetoothGattCharacteristic getCharacteristic(UUID uuid) {
2609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        for(BluetoothGattCharacteristic characteristic : mCharacteristics) {
2619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta            if (uuid.equals(characteristic.getUuid()))
2629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta                return characteristic;
2639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        }
2649908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return null;
2659908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
2669908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta}
267