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