blob: a485b898c2d4a04b12913f30a2108a0c64cb24ce [file] [log] [blame]
Hemant Guptae88fd4b2014-04-18 11:22:45 +05301/*
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
17package android.bluetooth;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
Hansong Zhangfa377b42017-09-27 14:17:20 -070022/**
Hansong Zhang53f54122017-12-04 10:31:30 -080023 * Represents the Quality of Service (QoS) settings for a Bluetooth HID Device application.
Hansong Zhangfa377b42017-09-27 14:17:20 -070024 *
Hansong Zhang53f54122017-12-04 10:31:30 -080025 * <p>The BluetoothHidDevice framework will update the L2CAP QoS settings for the app during
26 * registration.
Hansong Zhangfa377b42017-09-27 14:17:20 -070027 *
Hansong Zhang53f54122017-12-04 10:31:30 -080028 * <p>{@see BluetoothHidDevice}
Hansong Zhangfa377b42017-09-27 14:17:20 -070029 */
Hemant Guptae88fd4b2014-04-18 11:22:45 +053030public final class BluetoothHidDeviceAppQosSettings implements Parcelable {
31
Ivan Podogovf2f5dc32018-02-27 17:58:16 +000032 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;
Hemant Guptae88fd4b2014-04-18 11:22:45 +053038
Jack He2992cd02017-08-22 21:21:23 -070039 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;
Hemant Guptae88fd4b2014-04-18 11:22:45 +053042
Jack He2992cd02017-08-22 21:21:23 -070043 public static final int MAX = (int) 0xffffffff;
Hemant Guptae88fd4b2014-04-18 11:22:45 +053044
Hansong Zhangceb84db2017-11-08 09:57:12 -080045 /**
Hansong Zhang53f54122017-12-04 10:31:30 -080046 * Create a BluetoothHidDeviceAppQosSettings object for the Bluetooth L2CAP channel. The QoS
Ivan Podogovf2f5dc32018-02-27 17:58:16 +000047 * Settings is optional. Please refer to Bluetooth HID Specfication v1.1.1 Section 5.2 and
48 * Appendix D for parameters.
Hansong Zhang53f54122017-12-04 10:31:30 -080049 *
Ivan Podogovf2f5dc32018-02-27 17:58:16 +000050 * @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
Hansong Zhangceb84db2017-11-08 09:57:12 -080056 */
Ivan Podogovf2f5dc32018-02-27 17:58:16 +000057 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;
Hemant Guptae88fd4b2014-04-18 11:22:45 +053070 }
71
Ivan Podogovf2f5dc32018-02-27 17:58:16 +000072 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;
Hemant Guptae88fd4b2014-04-18 11:22:45 +053094 }
95
96 @Override
97 public int describeContents() {
98 return 0;
99 }
100
101 public static final Parcelable.Creator<BluetoothHidDeviceAppQosSettings> CREATOR =
Jack Hea355e5e2017-08-22 16:06:54 -0700102 new Parcelable.Creator<BluetoothHidDeviceAppQosSettings>() {
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530103
Jack Hea355e5e2017-08-22 16:06:54 -0700104 @Override
105 public BluetoothHidDeviceAppQosSettings createFromParcel(Parcel in) {
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530106
Hansong Zhangfa377b42017-09-27 14:17:20 -0700107 return new BluetoothHidDeviceAppQosSettings(
Jack Hea355e5e2017-08-22 16:06:54 -0700108 in.readInt(),
109 in.readInt(),
Hansong Zhangfa377b42017-09-27 14:17:20 -0700110 in.readInt(),
111 in.readInt(),
112 in.readInt(),
113 in.readInt());
Jack Hea355e5e2017-08-22 16:06:54 -0700114 }
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530115
Jack Hea355e5e2017-08-22 16:06:54 -0700116 @Override
117 public BluetoothHidDeviceAppQosSettings[] newArray(int size) {
118 return new BluetoothHidDeviceAppQosSettings[size];
119 }
120 };
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530121
122 @Override
123 public void writeToParcel(Parcel out, int flags) {
Ivan Podogovf2f5dc32018-02-27 17:58:16 +0000124 out.writeInt(mServiceType);
125 out.writeInt(mTokenRate);
126 out.writeInt(mTokenBucketSize);
127 out.writeInt(mPeakBandwidth);
128 out.writeInt(mLatency);
129 out.writeInt(mDelayVariation);
Hansong Zhangceb84db2017-11-08 09:57:12 -0800130 }
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530131}