blob: 15a9101452edd7bfc9f818b416a9552927da6573 [file] [log] [blame]
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -07001/*
2 * Copyright (C) 2011 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
18package android.bluetooth;
19
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070020import android.os.Parcel;
21import android.os.Parcelable;
22
23/**
24 * The Bluetooth Health Application Configuration that is used in conjunction with
25 * the {@link BluetoothHealth} class. This class represents an application configuration
26 * that the Bluetooth Health third party application will register to communicate with the
27 * remote Bluetooth health device.
28 *
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070029 */
30public final class BluetoothHealthAppConfiguration implements Parcelable {
31 private final String mName;
32 private final int mDataType;
33 private final int mRole;
34 private final int mChannelType;
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070035
36 /**
37 * Constructor to register the SINK role
38 *
39 * @param name Friendly name associated with the application configuration
40 * @param dataType Data Type of the remote Bluetooth Health device
Jaikumar Ganesheb9d3462011-08-31 15:36:05 -070041 * @hide
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070042 */
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -070043 BluetoothHealthAppConfiguration(String name, int dataType) {
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070044 mName = name;
45 mDataType = dataType;
46 mRole = BluetoothHealth.SINK_ROLE;
47 mChannelType = BluetoothHealth.CHANNEL_TYPE_ANY;
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070048 }
49
50 /**
51 * Constructor to register the application configuration.
52 *
53 * @param name Friendly name associated with the application configuration
54 * @param dataType Data Type of the remote Bluetooth Health device
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -070055 * @param role {@link BluetoothHealth#SOURCE_ROLE} or
56 * {@link BluetoothHealth#SINK_ROLE}
Jaikumar Ganesheb9d3462011-08-31 15:36:05 -070057 * @hide
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070058 */
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -070059 BluetoothHealthAppConfiguration(String name, int dataType, int role, int
60 channelType) {
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070061 mName = name;
62 mDataType = dataType;
63 mRole = role;
64 mChannelType = channelType;
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070065 }
66
67 @Override
68 public boolean equals(Object o) {
69 if (o instanceof BluetoothHealthAppConfiguration) {
70 BluetoothHealthAppConfiguration config = (BluetoothHealthAppConfiguration) o;
71 // config.getName() can never be NULL
72 return mName.equals(config.getName()) &&
73 mDataType == config.getDataType() &&
74 mRole == config.getRole() &&
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -070075 mChannelType == config.getChannelType();
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070076 }
77 return false;
78 }
79
80 @Override
81 public int hashCode() {
82 int result = 17;
83 result = 31 * result + (mName != null ? mName.hashCode() : 0);
84 result = 31 * result + mDataType;
85 result = 31 * result + mRole;
86 result = 31 * result + mChannelType;
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070087 return result;
88 }
89
90 @Override
91 public String toString() {
92 return "BluetoothHealthAppConfiguration [mName = " + mName +
93 ",mDataType = " + mDataType + ", mRole = " + mRole + ",mChannelType = " +
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -070094 mChannelType + "]";
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070095 }
96
97 public int describeContents() {
98 return 0;
99 }
100
101 /**
102 * Return the data type associated with this application configuration.
103 *
104 * @return dataType
105 */
106 public int getDataType() {
107 return mDataType;
108 }
109
110 /**
111 * Return the name of the application configuration.
112 *
113 * @return String name
114 */
115 public String getName() {
116 return mName;
117 }
118
119 /**
120 * Return the role associated with this application configuration.
121 *
122 * @return One of {@link BluetoothHealth#SOURCE_ROLE} or
123 * {@link BluetoothHealth#SINK_ROLE}
124 */
125 public int getRole() {
126 return mRole;
127 }
128
129 /**
130 * Return the channel type associated with this application configuration.
131 *
132 * @return One of {@link BluetoothHealth#CHANNEL_TYPE_RELIABLE} or
133 * {@link BluetoothHealth#CHANNEL_TYPE_STREAMING} or
134 * {@link BluetoothHealth#CHANNEL_TYPE_ANY}.
Jaikumar Ganesheb9d3462011-08-31 15:36:05 -0700135 * @hide
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700136 */
137 public int getChannelType() {
138 return mChannelType;
139 }
140
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700141 public static final Parcelable.Creator<BluetoothHealthAppConfiguration> CREATOR =
142 new Parcelable.Creator<BluetoothHealthAppConfiguration>() {
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -0700143 @Override
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700144 public BluetoothHealthAppConfiguration createFromParcel(Parcel in) {
145 String name = in.readString();
146 int type = in.readInt();
147 int role = in.readInt();
148 int channelType = in.readInt();
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -0700149 return new BluetoothHealthAppConfiguration(name, type, role,
150 channelType);
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700151 }
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -0700152
153 @Override
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700154 public BluetoothHealthAppConfiguration[] newArray(int size) {
155 return new BluetoothHealthAppConfiguration[size];
156 }
157 };
158
159 public void writeToParcel(Parcel out, int flags) {
160 out.writeString(mName);
161 out.writeInt(mDataType);
162 out.writeInt(mRole);
163 out.writeInt(mChannelType);
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700164 }
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700165}