Home | History | Annotate | Download | only in bluetooth
      1 /*
      2  * Copyright (C) 2016 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 package android.bluetooth;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 
     22 /**
     23  * Represents the Quality of Service (QoS) settings for a Bluetooth HID Device application.
     24  *
     25  * <p>The BluetoothHidDevice framework will update the L2CAP QoS settings for the app during
     26  * registration.
     27  *
     28  * <p>{@see BluetoothHidDevice}
     29  */
     30 public final class BluetoothHidDeviceAppQosSettings implements Parcelable {
     31 
     32     private final int mServiceType;
     33     private final int mTokenRate;
     34     private final int mTokenBucketSize;
     35     private final int mPeakBandwidth;
     36     private final int mLatency;
     37     private final int mDelayVariation;
     38 
     39     public static final int SERVICE_NO_TRAFFIC = 0x00;
     40     public static final int SERVICE_BEST_EFFORT = 0x01;
     41     public static final int SERVICE_GUARANTEED = 0x02;
     42 
     43     public static final int MAX = (int) 0xffffffff;
     44 
     45     /**
     46      * Create a BluetoothHidDeviceAppQosSettings object for the Bluetooth L2CAP channel. The QoS
     47      * Settings is optional. Please refer to Bluetooth HID Specfication v1.1.1 Section 5.2 and
     48      * Appendix D for parameters.
     49      *
     50      * @param serviceType L2CAP service type, default = SERVICE_BEST_EFFORT
     51      * @param tokenRate L2CAP token rate, default = 0
     52      * @param tokenBucketSize L2CAP token bucket size, default = 0
     53      * @param peakBandwidth L2CAP peak bandwidth, default = 0
     54      * @param latency L2CAP latency, default = MAX
     55      * @param delayVariation L2CAP delay variation, default = MAX
     56      */
     57     public BluetoothHidDeviceAppQosSettings(
     58             int serviceType,
     59             int tokenRate,
     60             int tokenBucketSize,
     61             int peakBandwidth,
     62             int latency,
     63             int delayVariation) {
     64         mServiceType = serviceType;
     65         mTokenRate = tokenRate;
     66         mTokenBucketSize = tokenBucketSize;
     67         mPeakBandwidth = peakBandwidth;
     68         mLatency = latency;
     69         mDelayVariation = delayVariation;
     70     }
     71 
     72     public int getServiceType() {
     73         return mServiceType;
     74     }
     75 
     76     public int getTokenRate() {
     77         return mTokenRate;
     78     }
     79 
     80     public int getTokenBucketSize() {
     81         return mTokenBucketSize;
     82     }
     83 
     84     public int getPeakBandwidth() {
     85         return mPeakBandwidth;
     86     }
     87 
     88     public int getLatency() {
     89         return mLatency;
     90     }
     91 
     92     public int getDelayVariation() {
     93         return mDelayVariation;
     94     }
     95 
     96     @Override
     97     public int describeContents() {
     98         return 0;
     99     }
    100 
    101     public static final Parcelable.Creator<BluetoothHidDeviceAppQosSettings> CREATOR =
    102             new Parcelable.Creator<BluetoothHidDeviceAppQosSettings>() {
    103 
    104                 @Override
    105                 public BluetoothHidDeviceAppQosSettings createFromParcel(Parcel in) {
    106 
    107                     return new BluetoothHidDeviceAppQosSettings(
    108                             in.readInt(),
    109                             in.readInt(),
    110                             in.readInt(),
    111                             in.readInt(),
    112                             in.readInt(),
    113                             in.readInt());
    114                 }
    115 
    116                 @Override
    117                 public BluetoothHidDeviceAppQosSettings[] newArray(int size) {
    118                     return new BluetoothHidDeviceAppQosSettings[size];
    119                 }
    120             };
    121 
    122     @Override
    123     public void writeToParcel(Parcel out, int flags) {
    124         out.writeInt(mServiceType);
    125         out.writeInt(mTokenRate);
    126         out.writeInt(mTokenBucketSize);
    127         out.writeInt(mPeakBandwidth);
    128         out.writeInt(mLatency);
    129         out.writeInt(mDelayVariation);
    130     }
    131 }
    132