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 package android.bluetooth;
17 
18 import android.annotation.NonNull;
19 import android.os.Parcel;
20 import android.os.ParcelUuid;
21 import android.os.Parcelable;
22 
23 import java.util.UUID;
24 
25 /**
26  * Represents a Bluetooth GATT Included Service
27  *
28  * @hide
29  */
30 public class BluetoothGattIncludedService implements Parcelable {
31 
32     /** The UUID of this service. */
33     protected UUID mUuid;
34 
35     /** Instance ID for this service. */
36     protected int mInstanceId;
37 
38     /** Service type (Primary/Secondary). */
39     protected int mServiceType;
40 
41     /** Create a new BluetoothGattIncludedService */
BluetoothGattIncludedService(UUID uuid, int instanceId, int serviceType)42     public BluetoothGattIncludedService(UUID uuid, int instanceId, int serviceType) {
43         mUuid = uuid;
44         mInstanceId = instanceId;
45         mServiceType = serviceType;
46     }
47 
48     @Override
describeContents()49     public int describeContents() {
50         return 0;
51     }
52 
53     @Override
writeToParcel(Parcel out, int flags)54     public void writeToParcel(Parcel out, int flags) {
55         out.writeParcelable(new ParcelUuid(mUuid), 0);
56         out.writeInt(mInstanceId);
57         out.writeInt(mServiceType);
58     }
59 
60     public static final @NonNull Creator<BluetoothGattIncludedService> CREATOR =
61             new Creator<>() {
62                 public BluetoothGattIncludedService createFromParcel(Parcel in) {
63                     return new BluetoothGattIncludedService(in);
64                 }
65 
66                 public BluetoothGattIncludedService[] newArray(int size) {
67                     return new BluetoothGattIncludedService[size];
68                 }
69             };
70 
BluetoothGattIncludedService(Parcel in)71     private BluetoothGattIncludedService(Parcel in) {
72         mUuid = ((ParcelUuid) in.readParcelable(null)).getUuid();
73         mInstanceId = in.readInt();
74         mServiceType = in.readInt();
75     }
76 
77     /**
78      * Returns the UUID of this service
79      *
80      * @return UUID of this service
81      */
getUuid()82     public UUID getUuid() {
83         return mUuid;
84     }
85 
86     /**
87      * Returns the instance ID for this service
88      *
89      * <p>If a remote device offers multiple services with the same UUID (ex. multiple battery
90      * services for different batteries), the instance ID is used to distuinguish services.
91      *
92      * @return Instance ID of this service
93      */
getInstanceId()94     public int getInstanceId() {
95         return mInstanceId;
96     }
97 
98     /** Get the type of this service (primary/secondary) */
getType()99     public int getType() {
100         return mServiceType;
101     }
102 }
103