Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | package android.bluetooth; |
| 19 | |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import 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 Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 29 | */ |
| 30 | public 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 Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 35 | |
| 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 Ganesh | eb9d346 | 2011-08-31 15:36:05 -0700 | [diff] [blame] | 41 | * @hide |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 42 | */ |
Jaikumar Ganesh | fb658c7 | 2011-07-06 17:37:02 -0700 | [diff] [blame] | 43 | BluetoothHealthAppConfiguration(String name, int dataType) { |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 44 | mName = name; |
| 45 | mDataType = dataType; |
| 46 | mRole = BluetoothHealth.SINK_ROLE; |
| 47 | mChannelType = BluetoothHealth.CHANNEL_TYPE_ANY; |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 48 | } |
| 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 Ganesh | fb658c7 | 2011-07-06 17:37:02 -0700 | [diff] [blame] | 55 | * @param role {@link BluetoothHealth#SOURCE_ROLE} or |
| 56 | * {@link BluetoothHealth#SINK_ROLE} |
Jaikumar Ganesh | eb9d346 | 2011-08-31 15:36:05 -0700 | [diff] [blame] | 57 | * @hide |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 58 | */ |
Jaikumar Ganesh | fb658c7 | 2011-07-06 17:37:02 -0700 | [diff] [blame] | 59 | BluetoothHealthAppConfiguration(String name, int dataType, int role, int |
| 60 | channelType) { |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 61 | mName = name; |
| 62 | mDataType = dataType; |
| 63 | mRole = role; |
| 64 | mChannelType = channelType; |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 65 | } |
| 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 Ganesh | fb658c7 | 2011-07-06 17:37:02 -0700 | [diff] [blame] | 75 | mChannelType == config.getChannelType(); |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 76 | } |
| 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 Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 87 | return result; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public String toString() { |
| 92 | return "BluetoothHealthAppConfiguration [mName = " + mName + |
| 93 | ",mDataType = " + mDataType + ", mRole = " + mRole + ",mChannelType = " + |
Jaikumar Ganesh | fb658c7 | 2011-07-06 17:37:02 -0700 | [diff] [blame] | 94 | mChannelType + "]"; |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 95 | } |
| 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 Ganesh | eb9d346 | 2011-08-31 15:36:05 -0700 | [diff] [blame] | 135 | * @hide |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 136 | */ |
| 137 | public int getChannelType() { |
| 138 | return mChannelType; |
| 139 | } |
| 140 | |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 141 | public static final Parcelable.Creator<BluetoothHealthAppConfiguration> CREATOR = |
| 142 | new Parcelable.Creator<BluetoothHealthAppConfiguration>() { |
Jaikumar Ganesh | fb658c7 | 2011-07-06 17:37:02 -0700 | [diff] [blame] | 143 | @Override |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 144 | 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 Ganesh | fb658c7 | 2011-07-06 17:37:02 -0700 | [diff] [blame] | 149 | return new BluetoothHealthAppConfiguration(name, type, role, |
| 150 | channelType); |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 151 | } |
Jaikumar Ganesh | fb658c7 | 2011-07-06 17:37:02 -0700 | [diff] [blame] | 152 | |
| 153 | @Override |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 154 | 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 Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 164 | } |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 165 | } |