• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 HIMSA II K/S - www.himsa.com.
3  * Represented by EHIMA - www.ehima.com
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package android.bluetooth;
19 
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.text.TextUtils;
25 
26 /**
27  * Represents the Hearing Access Profile preset.
28  * @hide
29  */
30 @SystemApi
31 public final class BluetoothHapPresetInfo implements Parcelable {
32     private int mPresetIndex;
33     private String mPresetName = "";
34     private boolean mIsWritable;
35     private boolean mIsAvailable;
36 
37     /**
38      * HapPresetInfo constructor
39      *
40      * @param presetIndex Preset index
41      * @param presetName Preset Name
42      * @param isWritable Is writable flag
43      * @param isAvailable Is available flag
44      */
BluetoothHapPresetInfo(int presetIndex, @NonNull String presetName, boolean isWritable, boolean isAvailable)45     /*package*/ BluetoothHapPresetInfo(int presetIndex, @NonNull String presetName,
46             boolean isWritable, boolean isAvailable) {
47         this.mPresetIndex = presetIndex;
48         this.mPresetName = presetName;
49         this.mIsWritable = isWritable;
50         this.mIsAvailable = isAvailable;
51     }
52 
53     /**
54      * HapPresetInfo constructor
55      *
56      * @param in HapPresetInfo parcel
57      */
BluetoothHapPresetInfo(@onNull Parcel in)58     private BluetoothHapPresetInfo(@NonNull Parcel in) {
59         mPresetIndex = in.readInt();
60         mPresetName = in.readString();
61         mIsWritable = in.readBoolean();
62         mIsAvailable = in.readBoolean();
63     }
64 
65     /**
66      * HapPresetInfo preset index
67      *
68      * @return Preset index
69      */
getIndex()70     public int getIndex() {
71         return mPresetIndex;
72     }
73 
74     /**
75      * HapPresetInfo preset name
76      *
77      * @return Preset name
78      */
getName()79     public @NonNull String getName() {
80         return mPresetName;
81     }
82 
83     /**
84      * HapPresetInfo preset writability
85      *
86      * @return If preset is writable
87      */
isWritable()88     public boolean isWritable() {
89         return mIsWritable;
90     }
91 
92     /**
93      * HapPresetInfo availability
94      *
95      * @return If preset is available
96      */
isAvailable()97     public boolean isAvailable() {
98         return mIsAvailable;
99     }
100 
101     /**
102      * HapPresetInfo array creator
103      */
104     public static final @NonNull Creator<BluetoothHapPresetInfo> CREATOR =
105             new Creator<BluetoothHapPresetInfo>() {
106                 public BluetoothHapPresetInfo createFromParcel(@NonNull Parcel in) {
107                     return new BluetoothHapPresetInfo(in);
108                 }
109 
110                 public BluetoothHapPresetInfo[] newArray(int size) {
111                     return new BluetoothHapPresetInfo[size];
112                 }
113             };
114 
115     /** @hide */
116     @Override
describeContents()117     public int describeContents() {
118         return 0;
119     }
120 
121     @Override
writeToParcel(@onNull Parcel dest, int flags)122     public void writeToParcel(@NonNull Parcel dest, int flags) {
123         dest.writeInt(mPresetIndex);
124         dest.writeString(mPresetName);
125         dest.writeBoolean(mIsWritable);
126         dest.writeBoolean(mIsAvailable);
127     }
128 
129     /**
130      * Builder for {@link BluetoothHapPresetInfo}.
131      * <p> By default, the preset index will be set to
132      * {@link BluetoothHapClient#PRESET_INDEX_UNAVAILABLE}, the name to an empty string,
133      * writability and availability both to false.
134      * @hide
135      */
136     public static final class Builder {
137         private int mPresetIndex = BluetoothHapClient.PRESET_INDEX_UNAVAILABLE;
138         private String mPresetName = "";
139         private boolean mIsWritable = false;
140         private boolean mIsAvailable = false;
141 
142         /**
143          * Creates a new builder.
144          *
145          * @param index The preset index for HAP preset info
146          * @param name The preset name for HAP preset info
147          */
Builder(int index, @NonNull String name)148         public Builder(int index, @NonNull String name) {
149             if (TextUtils.isEmpty(name)) {
150                 throw new IllegalArgumentException("The size of the preset name for HAP shall be at"
151                         + " least one character long.");
152             }
153             if (index < 0) {
154                 throw new IllegalArgumentException(
155                         "Preset index for HAP shall be a non-negative value.");
156             }
157 
158             mPresetIndex = index;
159             mPresetName = name;
160         }
161 
162         /**
163          * Set preset writability for HAP preset info.
164          *
165          * @param isWritable whether preset is writable
166          * @return the same Builder instance
167          */
setWritable(boolean isWritable)168         public @NonNull Builder setWritable(boolean isWritable) {
169             mIsWritable = isWritable;
170             return this;
171         }
172 
173         /**
174          * Set preset availability for HAP preset info.
175          *
176          * @param isAvailable whether preset is currently available to select
177          * @return the same Builder instance
178          */
setAvailable(boolean isAvailable)179         public @NonNull Builder setAvailable(boolean isAvailable) {
180             mIsAvailable = isAvailable;
181             return this;
182         }
183 
184         /**
185          * Build {@link BluetoothHapPresetInfo}.
186          * @return new BluetoothHapPresetInfo built
187          */
build()188         public @NonNull BluetoothHapPresetInfo build() {
189             return new BluetoothHapPresetInfo(mPresetIndex, mPresetName, mIsWritable, mIsAvailable);
190         }
191     }
192 }
193