Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 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; |
Jakub Pawlowski | 6351921 | 2018-11-29 18:54:21 +0100 | [diff] [blame] | 21 | import android.util.EventLog; |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 22 | |
Hansong Zhang | ceb84db | 2017-11-08 09:57:12 -0800 | [diff] [blame] | 23 | |
Hansong Zhang | fa377b4 | 2017-09-27 14:17:20 -0700 | [diff] [blame] | 24 | /** |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 25 | * Represents the Service Discovery Protocol (SDP) settings for a Bluetooth HID Device application. |
Hansong Zhang | fa377b4 | 2017-09-27 14:17:20 -0700 | [diff] [blame] | 26 | * |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 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. |
Hansong Zhang | fa377b4 | 2017-09-27 14:17:20 -0700 | [diff] [blame] | 29 | * |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 30 | * <p>{@see BluetoothHidDevice} |
Hansong Zhang | fa377b4 | 2017-09-27 14:17:20 -0700 | [diff] [blame] | 31 | */ |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 32 | public final class BluetoothHidDeviceAppSdpSettings implements Parcelable { |
| 33 | |
Jakub Pawlowski | 6351921 | 2018-11-29 18:54:21 +0100 | [diff] [blame] | 34 | private static final int MAX_DESCRIPTOR_SIZE = 2048; |
| 35 | |
Ivan Podogov | 191ce9c | 2018-02-27 17:58:16 +0000 | [diff] [blame] | 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; |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 41 | |
Hansong Zhang | ceb84db | 2017-11-08 09:57:12 -0800 | [diff] [blame] | 42 | /** |
| 43 | * Create a BluetoothHidDeviceAppSdpSettings object for the Bluetooth SDP record. |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 44 | * |
Hansong Zhang | ceb84db | 2017-11-08 09:57:12 -0800 | [diff] [blame] | 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. |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 48 | * @param subclass Subclass of this Bluetooth HID device. See <a |
| 49 | * href="www.usb.org/developers/hidpage/HID1_11.pdf"> |
Hansong Zhang | ceb84db | 2017-11-08 09:57:12 -0800 | [diff] [blame] | 50 | * www.usb.org/developers/hidpage/HID1_11.pdf Section 4.2</a> |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 51 | * @param descriptors Descriptors of this Bluetooth HID device. See <a |
| 52 | * href="www.usb.org/developers/hidpage/HID1_11.pdf"> |
Hansong Zhang | ceb84db | 2017-11-08 09:57:12 -0800 | [diff] [blame] | 53 | * www.usb.org/developers/hidpage/HID1_11.pdf Chapter 6</a> Maximum length is 2048 bytes. |
| 54 | */ |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 55 | public BluetoothHidDeviceAppSdpSettings( |
| 56 | String name, String description, String provider, byte subclass, byte[] descriptors) { |
Ivan Podogov | 191ce9c | 2018-02-27 17:58:16 +0000 | [diff] [blame] | 57 | mName = name; |
| 58 | mDescription = description; |
| 59 | mProvider = provider; |
| 60 | mSubclass = subclass; |
Jakub Pawlowski | 6351921 | 2018-11-29 18:54:21 +0100 | [diff] [blame] | 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 | } |
Ivan Podogov | 191ce9c | 2018-02-27 17:58:16 +0000 | [diff] [blame] | 67 | mDescriptors = descriptors.clone(); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 68 | } |
| 69 | |
Ivan Podogov | 191ce9c | 2018-02-27 17:58:16 +0000 | [diff] [blame] | 70 | 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 Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public int describeContents() { |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | public static final Parcelable.Creator<BluetoothHidDeviceAppSdpSettings> CREATOR = |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 96 | new Parcelable.Creator<BluetoothHidDeviceAppSdpSettings>() { |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 97 | |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 98 | @Override |
| 99 | public BluetoothHidDeviceAppSdpSettings createFromParcel(Parcel in) { |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 100 | |
Hansong Zhang | fa377b4 | 2017-09-27 14:17:20 -0700 | [diff] [blame] | 101 | return new BluetoothHidDeviceAppSdpSettings( |
| 102 | in.readString(), |
| 103 | in.readString(), |
| 104 | in.readString(), |
| 105 | in.readByte(), |
| 106 | in.createByteArray()); |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 107 | } |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 108 | |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 109 | @Override |
| 110 | public BluetoothHidDeviceAppSdpSettings[] newArray(int size) { |
| 111 | return new BluetoothHidDeviceAppSdpSettings[size]; |
| 112 | } |
| 113 | }; |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 114 | |
| 115 | @Override |
| 116 | public void writeToParcel(Parcel out, int flags) { |
Ivan Podogov | 191ce9c | 2018-02-27 17:58:16 +0000 | [diff] [blame] | 117 | out.writeString(mName); |
| 118 | out.writeString(mDescription); |
| 119 | out.writeString(mProvider); |
| 120 | out.writeByte(mSubclass); |
| 121 | out.writeByteArray(mDescriptors); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 122 | } |
| 123 | } |