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