blob: 4e1a2aaedcf0b7f46aa867cd1ddc7679994b84ea [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;
Jakub Pawlowski63519212018-11-29 18:54:21 +010021import android.util.EventLog;
Hemant Guptae88fd4b2014-04-18 11:22:45 +053022
Hansong Zhangceb84db2017-11-08 09:57:12 -080023
Hansong Zhangfa377b42017-09-27 14:17:20 -070024/**
Hansong Zhang53f54122017-12-04 10:31:30 -080025 * Represents the Service Discovery Protocol (SDP) settings for a Bluetooth HID Device application.
Hansong Zhangfa377b42017-09-27 14:17:20 -070026 *
Hansong Zhang53f54122017-12-04 10:31:30 -080027 * <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.
Hansong Zhangfa377b42017-09-27 14:17:20 -070029 *
Hansong Zhang53f54122017-12-04 10:31:30 -080030 * <p>{@see BluetoothHidDevice}
Hansong Zhangfa377b42017-09-27 14:17:20 -070031 */
Hemant Guptae88fd4b2014-04-18 11:22:45 +053032public final class BluetoothHidDeviceAppSdpSettings implements Parcelable {
33
Jakub Pawlowski63519212018-11-29 18:54:21 +010034 private static final int MAX_DESCRIPTOR_SIZE = 2048;
35
Ivan Podogov191ce9c2018-02-27 17:58:16 +000036 private final String mName;
37 private final String mDescription;
38 private final String mProvider;
39 private final byte mSubclass;
40 private final byte[] mDescriptors;
Hemant Guptae88fd4b2014-04-18 11:22:45 +053041
Hansong Zhangceb84db2017-11-08 09:57:12 -080042 /**
43 * Create a BluetoothHidDeviceAppSdpSettings object for the Bluetooth SDP record.
Hansong Zhang53f54122017-12-04 10:31:30 -080044 *
Hansong Zhangceb84db2017-11-08 09:57:12 -080045 * @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.
Hansong Zhang53f54122017-12-04 10:31:30 -080048 * @param subclass Subclass of this Bluetooth HID device. See <a
49 * href="www.usb.org/developers/hidpage/HID1_11.pdf">
Hansong Zhangceb84db2017-11-08 09:57:12 -080050 * www.usb.org/developers/hidpage/HID1_11.pdf Section 4.2</a>
Hansong Zhang53f54122017-12-04 10:31:30 -080051 * @param descriptors Descriptors of this Bluetooth HID device. See <a
52 * href="www.usb.org/developers/hidpage/HID1_11.pdf">
Hansong Zhangceb84db2017-11-08 09:57:12 -080053 * www.usb.org/developers/hidpage/HID1_11.pdf Chapter 6</a> Maximum length is 2048 bytes.
54 */
Hansong Zhang53f54122017-12-04 10:31:30 -080055 public BluetoothHidDeviceAppSdpSettings(
56 String name, String description, String provider, byte subclass, byte[] descriptors) {
Ivan Podogov191ce9c2018-02-27 17:58:16 +000057 mName = name;
58 mDescription = description;
59 mProvider = provider;
60 mSubclass = subclass;
Jakub Pawlowski63519212018-11-29 18:54:21 +010061
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 }
Ivan Podogov191ce9c2018-02-27 17:58:16 +000067 mDescriptors = descriptors.clone();
Hemant Guptae88fd4b2014-04-18 11:22:45 +053068 }
69
Ivan Podogov191ce9c2018-02-27 17:58:16 +000070 public String getName() {
71 return mName;
72 }
73
74 public String getDescription() {
75 return mDescription;
76 }
77
78 public String getProvider() {
79 return mProvider;
80 }
81
82 public byte getSubclass() {
83 return mSubclass;
84 }
85
86 public byte[] getDescriptors() {
87 return mDescriptors;
Hemant Guptae88fd4b2014-04-18 11:22:45 +053088 }
89
90 @Override
91 public int describeContents() {
92 return 0;
93 }
94
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070095 public static final @android.annotation.NonNull Parcelable.Creator<BluetoothHidDeviceAppSdpSettings> CREATOR =
Jack Hea355e5e2017-08-22 16:06:54 -070096 new Parcelable.Creator<BluetoothHidDeviceAppSdpSettings>() {
Hemant Guptae88fd4b2014-04-18 11:22:45 +053097
Jack Hea355e5e2017-08-22 16:06:54 -070098 @Override
99 public BluetoothHidDeviceAppSdpSettings createFromParcel(Parcel in) {
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530100
Hansong Zhangfa377b42017-09-27 14:17:20 -0700101 return new BluetoothHidDeviceAppSdpSettings(
102 in.readString(),
103 in.readString(),
104 in.readString(),
105 in.readByte(),
106 in.createByteArray());
Jack Hea355e5e2017-08-22 16:06:54 -0700107 }
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530108
Jack Hea355e5e2017-08-22 16:06:54 -0700109 @Override
110 public BluetoothHidDeviceAppSdpSettings[] newArray(int size) {
111 return new BluetoothHidDeviceAppSdpSettings[size];
112 }
113 };
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530114
115 @Override
116 public void writeToParcel(Parcel out, int flags) {
Ivan Podogov191ce9c2018-02-27 17:58:16 +0000117 out.writeString(mName);
118 out.writeString(mDescription);
119 out.writeString(mProvider);
120 out.writeByte(mSubclass);
121 out.writeByteArray(mDescriptors);
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530122 }
123}