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