1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.bluetooth.gatt; 18 19 import java.util.UUID; 20 21 /** 22 * Helper class for passing gatt db elements between java and JNI, equal to 23 * native btgatt_db_element_t. 24 * @hide 25 */ 26 public class GattDbElement { 27 28 public static final int TYPE_PRIMARY_SERVICE = 0; 29 public static final int TYPE_SECONDARY_SERVICE = 1; 30 public static final int TYPE_INCLUDED_SERVICE = 2; 31 public static final int TYPE_CHARACTERISTIC = 3; 32 public static final int TYPE_DESCRIPTOR = 4; 33 34 public GattDbElement() {} 35 36 public int id; 37 public UUID uuid; 38 public int type; 39 public int attributeHandle; 40 41 /* 42 * If type is TYPE_PRIMARY_SERVICE, or TYPE_SECONDARY_SERVICE, 43 * this contains the start and end attribute handles. 44 */ 45 public int startHandle; 46 public int endHandle; 47 48 /* 49 * If type is TYPE_CHARACTERISTIC, this contains the properties of 50 * the characteristic. 51 */ 52 public int properties; 53 public int permissions; 54 55 public static GattDbElement createPrimaryService(UUID uuid) { 56 GattDbElement el = new GattDbElement(); 57 el.type = TYPE_PRIMARY_SERVICE; 58 el.uuid = uuid; 59 return el; 60 } 61 62 public static GattDbElement createSecondaryService(UUID uuid) { 63 GattDbElement el = new GattDbElement(); 64 el.type = TYPE_SECONDARY_SERVICE; 65 el.uuid = uuid; 66 return el; 67 } 68 69 public static GattDbElement createCharacteristic(UUID uuid, int properties, int permissions) { 70 GattDbElement el = new GattDbElement(); 71 el.type = TYPE_CHARACTERISTIC; 72 el.uuid = uuid; 73 el.properties = properties; 74 el.permissions = permissions; 75 return el; 76 } 77 78 public static GattDbElement createDescriptor(UUID uuid, int permissions) { 79 GattDbElement el = new GattDbElement(); 80 el.type = TYPE_DESCRIPTOR; 81 el.uuid = uuid; 82 el.permissions = permissions; 83 return el; 84 } 85 86 public static GattDbElement createIncludedService(int attributeHandle) { 87 GattDbElement el = new GattDbElement(); 88 el.type = TYPE_INCLUDED_SERVICE; 89 el.attributeHandle = attributeHandle; 90 return el; 91 } 92 } 93