• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.annotation.NonNull;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import android.util.EventLog;
23 
24 
25 /**
26  * Represents the Service Discovery Protocol (SDP) settings for a Bluetooth HID Device application.
27  *
28  * <p>The BluetoothHidDevice framework adds the SDP record during app registration, so that the
29  * Android device can be discovered as a Bluetooth HID Device.
30  *
31  * <p>{@see BluetoothHidDevice}
32  */
33 public final class BluetoothHidDeviceAppSdpSettings implements Parcelable {
34 
35     private static final int MAX_DESCRIPTOR_SIZE = 2048;
36 
37     private final String mName;
38     private final String mDescription;
39     private final String mProvider;
40     private final byte mSubclass;
41     private final byte[] mDescriptors;
42 
43     /**
44      * Create a BluetoothHidDeviceAppSdpSettings object for the Bluetooth SDP record.
45      *
46      * @param name Name of this Bluetooth HID device. Maximum length is 50 bytes.
47      * @param description Description for this Bluetooth HID device. Maximum length is 50 bytes.
48      * @param provider Provider of this Bluetooth HID device. Maximum length is 50 bytes.
49      * @param subclass Subclass of this Bluetooth HID device. See <a
50      *     href="www.usb.org/developers/hidpage/HID1_11.pdf">
51      *     www.usb.org/developers/hidpage/HID1_11.pdf Section 4.2</a>
52      * @param descriptors Descriptors of this Bluetooth HID device. See <a
53      *     href="www.usb.org/developers/hidpage/HID1_11.pdf">
54      *     www.usb.org/developers/hidpage/HID1_11.pdf Chapter 6</a> Maximum length is 2048 bytes.
55      */
BluetoothHidDeviceAppSdpSettings( String name, String description, String provider, byte subclass, byte[] descriptors)56     public BluetoothHidDeviceAppSdpSettings(
57             String name, String description, String provider, byte subclass, byte[] descriptors) {
58         mName = name;
59         mDescription = description;
60         mProvider = provider;
61         mSubclass = subclass;
62 
63         if (descriptors == null || descriptors.length > MAX_DESCRIPTOR_SIZE) {
64             EventLog.writeEvent(0x534e4554, "119819889", -1, "");
65             throw new IllegalArgumentException("descriptors must be not null and shorter than "
66                     + MAX_DESCRIPTOR_SIZE);
67         }
68         mDescriptors = descriptors.clone();
69     }
70 
getName()71     public String getName() {
72         return mName;
73     }
74 
getDescription()75     public String getDescription() {
76         return mDescription;
77     }
78 
getProvider()79     public String getProvider() {
80         return mProvider;
81     }
82 
getSubclass()83     public byte getSubclass() {
84         return mSubclass;
85     }
86 
getDescriptors()87     public byte[] getDescriptors() {
88         return mDescriptors;
89     }
90 
91     @Override
describeContents()92     public int describeContents() {
93         return 0;
94     }
95 
96     @NonNull
97     public static final Creator<BluetoothHidDeviceAppSdpSettings> CREATOR = new Creator<>() {
98         @Override
99         public BluetoothHidDeviceAppSdpSettings createFromParcel(Parcel in) {
100             return new BluetoothHidDeviceAppSdpSettings(
101                     in.readString(),
102                     in.readString(),
103                     in.readString(),
104                     in.readByte(),
105                     in.createByteArray());
106         }
107 
108         @Override
109         public BluetoothHidDeviceAppSdpSettings[] newArray(int size) {
110             return new BluetoothHidDeviceAppSdpSettings[size];
111         }
112     };
113 
114     @Override
writeToParcel(Parcel out, int flags)115     public void writeToParcel(Parcel out, int flags) {
116         out.writeString(mName);
117         out.writeString(mDescription);
118         out.writeString(mProvider);
119         out.writeByte(mSubclass);
120         out.writeByteArray(mDescriptors);
121     }
122 }
123