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             // config.getName() can never be NULL
     72             return mName.equals(config.getName()) &&
     73                     mDataType == config.getDataType() &&
     74                     mRole == config.getRole() &&
     75                     mChannelType == config.getChannelType();
     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;
     87         return result;
     88     }
     89 
     90     @Override
     91     public String toString() {
     92         return "BluetoothHealthAppConfiguration [mName = " + mName +
     93             ",mDataType = " + mDataType + ", mRole = " + mRole + ",mChannelType = " +
     94             mChannelType + "]";
     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}.
    135      * @hide
    136      */
    137     public int getChannelType() {
    138         return mChannelType;
    139     }
    140 
    141     public static final Parcelable.Creator<BluetoothHealthAppConfiguration> CREATOR =
    142         new Parcelable.Creator<BluetoothHealthAppConfiguration>() {
    143         @Override
    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();
    149             return new BluetoothHealthAppConfiguration(name, type, role,
    150                 channelType);
    151         }
    152 
    153         @Override
    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);
    164     }
    165 }
    166