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 
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  */
29 public final class BluetoothHealthAppConfiguration implements Parcelable {
30     private final String mName;
31     private final int mDataType;
32     private final int mRole;
33     private final int mChannelType;
34 
35     /**
36      * Constructor to register the SINK role
37      *
38      * @param name Friendly name associated with the application configuration
39      * @param dataType Data Type of the remote Bluetooth Health device
40      * @hide
41      */
BluetoothHealthAppConfiguration(String name, int dataType)42     BluetoothHealthAppConfiguration(String name, int dataType) {
43         mName = name;
44         mDataType = dataType;
45         mRole = BluetoothHealth.SINK_ROLE;
46         mChannelType = BluetoothHealth.CHANNEL_TYPE_ANY;
47     }
48 
49     /**
50      * Constructor to register the application configuration.
51      *
52      * @param name Friendly name associated with the application configuration
53      * @param dataType Data Type of the remote Bluetooth Health device
54      * @param role {@link BluetoothHealth#SOURCE_ROLE} or {@link BluetoothHealth#SINK_ROLE}
55      * @hide
56      */
BluetoothHealthAppConfiguration(String name, int dataType, int role, int channelType)57     BluetoothHealthAppConfiguration(String name, int dataType, int role, int
58             channelType) {
59         mName = name;
60         mDataType = dataType;
61         mRole = role;
62         mChannelType = channelType;
63     }
64 
65     @Override
equals(Object o)66     public boolean equals(Object o) {
67         if (o instanceof BluetoothHealthAppConfiguration) {
68             BluetoothHealthAppConfiguration config = (BluetoothHealthAppConfiguration) o;
69 
70             if (mName == null) return false;
71 
72             return mName.equals(config.getName()) && mDataType == config.getDataType()
73                     && mRole == config.getRole() && mChannelType == config.getChannelType();
74         }
75         return false;
76     }
77 
78     @Override
hashCode()79     public int hashCode() {
80         int result = 17;
81         result = 31 * result + (mName != null ? mName.hashCode() : 0);
82         result = 31 * result + mDataType;
83         result = 31 * result + mRole;
84         result = 31 * result + mChannelType;
85         return result;
86     }
87 
88     @Override
toString()89     public String toString() {
90         return "BluetoothHealthAppConfiguration [mName = " + mName + ",mDataType = " + mDataType
91                 + ", mRole = " + mRole + ",mChannelType = " + mChannelType + "]";
92     }
93 
94     @Override
describeContents()95     public int describeContents() {
96         return 0;
97     }
98 
99     /**
100      * Return the data type associated with this application configuration.
101      *
102      * @return dataType
103      */
getDataType()104     public int getDataType() {
105         return mDataType;
106     }
107 
108     /**
109      * Return the name of the application configuration.
110      *
111      * @return String name
112      */
getName()113     public String getName() {
114         return mName;
115     }
116 
117     /**
118      * Return the role associated with this application configuration.
119      *
120      * @return One of {@link BluetoothHealth#SOURCE_ROLE} or {@link BluetoothHealth#SINK_ROLE}
121      */
getRole()122     public int getRole() {
123         return mRole;
124     }
125 
126     /**
127      * Return the channel type associated with this application configuration.
128      *
129      * @return One of {@link BluetoothHealth#CHANNEL_TYPE_RELIABLE} or {@link
130      * BluetoothHealth#CHANNEL_TYPE_STREAMING} or {@link BluetoothHealth#CHANNEL_TYPE_ANY}.
131      * @hide
132      */
getChannelType()133     public int getChannelType() {
134         return mChannelType;
135     }
136 
137     public static final Parcelable.Creator<BluetoothHealthAppConfiguration> CREATOR =
138             new Parcelable.Creator<BluetoothHealthAppConfiguration>() {
139                 @Override
140                 public BluetoothHealthAppConfiguration createFromParcel(Parcel in) {
141                     String name = in.readString();
142                     int type = in.readInt();
143                     int role = in.readInt();
144                     int channelType = in.readInt();
145                     return new BluetoothHealthAppConfiguration(name, type, role,
146                             channelType);
147                 }
148 
149                 @Override
150                 public BluetoothHealthAppConfiguration[] newArray(int size) {
151                     return new BluetoothHealthAppConfiguration[size];
152                 }
153             };
154 
155     @Override
writeToParcel(Parcel out, int flags)156     public void writeToParcel(Parcel out, int flags) {
157         out.writeString(mName);
158         out.writeInt(mDataType);
159         out.writeInt(mRole);
160         out.writeInt(mChannelType);
161     }
162 }
163