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; |
| 21 | |
Hansong Zhang | ceb84db | 2017-11-08 09:57:12 -0800 | [diff] [blame] | 22 | |
Hansong Zhang | fa377b4 | 2017-09-27 14:17:20 -0700 | [diff] [blame] | 23 | /** |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 24 | * 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] | 25 | * |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 26 | * <p>The BluetoothHidDevice framework adds the SDP record during app registration, so that the |
| 27 | * Android device can be discovered as a Bluetooth HID Device. |
Hansong Zhang | fa377b4 | 2017-09-27 14:17:20 -0700 | [diff] [blame] | 28 | * |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 29 | * <p>{@see BluetoothHidDevice} |
Hansong Zhang | fa377b4 | 2017-09-27 14:17:20 -0700 | [diff] [blame] | 30 | */ |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 31 | public final class BluetoothHidDeviceAppSdpSettings implements Parcelable { |
| 32 | |
Ivan Podogov | f2f5dc3 | 2018-02-27 17:58:16 +0000 | [diff] [blame] | 33 | private final String mName; |
| 34 | private final String mDescription; |
| 35 | private final String mProvider; |
| 36 | private final byte mSubclass; |
| 37 | private final byte[] mDescriptors; |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 38 | |
Hansong Zhang | ceb84db | 2017-11-08 09:57:12 -0800 | [diff] [blame] | 39 | /** |
| 40 | * Create a BluetoothHidDeviceAppSdpSettings object for the Bluetooth SDP record. |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 41 | * |
Hansong Zhang | ceb84db | 2017-11-08 09:57:12 -0800 | [diff] [blame] | 42 | * @param name Name of this Bluetooth HID device. Maximum length is 50 bytes. |
| 43 | * @param description Description for this Bluetooth HID device. Maximum length is 50 bytes. |
| 44 | * @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] | 45 | * @param subclass Subclass of this Bluetooth HID device. See <a |
| 46 | * href="www.usb.org/developers/hidpage/HID1_11.pdf"> |
Hansong Zhang | ceb84db | 2017-11-08 09:57:12 -0800 | [diff] [blame] | 47 | * www.usb.org/developers/hidpage/HID1_11.pdf Section 4.2</a> |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 48 | * @param descriptors Descriptors 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 Chapter 6</a> Maximum length is 2048 bytes. |
| 51 | */ |
Hansong Zhang | 53f5412 | 2017-12-04 10:31:30 -0800 | [diff] [blame] | 52 | public BluetoothHidDeviceAppSdpSettings( |
| 53 | String name, String description, String provider, byte subclass, byte[] descriptors) { |
Ivan Podogov | f2f5dc3 | 2018-02-27 17:58:16 +0000 | [diff] [blame] | 54 | mName = name; |
| 55 | mDescription = description; |
| 56 | mProvider = provider; |
| 57 | mSubclass = subclass; |
| 58 | mDescriptors = descriptors.clone(); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 59 | } |
| 60 | |
Ivan Podogov | f2f5dc3 | 2018-02-27 17:58:16 +0000 | [diff] [blame] | 61 | public String getName() { |
| 62 | return mName; |
| 63 | } |
| 64 | |
| 65 | public String getDescription() { |
| 66 | return mDescription; |
| 67 | } |
| 68 | |
| 69 | public String getProvider() { |
| 70 | return mProvider; |
| 71 | } |
| 72 | |
| 73 | public byte getSubclass() { |
| 74 | return mSubclass; |
| 75 | } |
| 76 | |
| 77 | public byte[] getDescriptors() { |
| 78 | return mDescriptors; |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public int describeContents() { |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | public static final Parcelable.Creator<BluetoothHidDeviceAppSdpSettings> CREATOR = |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 87 | new Parcelable.Creator<BluetoothHidDeviceAppSdpSettings>() { |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 88 | |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 89 | @Override |
| 90 | public BluetoothHidDeviceAppSdpSettings createFromParcel(Parcel in) { |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 91 | |
Hansong Zhang | fa377b4 | 2017-09-27 14:17:20 -0700 | [diff] [blame] | 92 | return new BluetoothHidDeviceAppSdpSettings( |
| 93 | in.readString(), |
| 94 | in.readString(), |
| 95 | in.readString(), |
| 96 | in.readByte(), |
| 97 | in.createByteArray()); |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 98 | } |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 99 | |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 100 | @Override |
| 101 | public BluetoothHidDeviceAppSdpSettings[] newArray(int size) { |
| 102 | return new BluetoothHidDeviceAppSdpSettings[size]; |
| 103 | } |
| 104 | }; |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 105 | |
| 106 | @Override |
| 107 | public void writeToParcel(Parcel out, int flags) { |
Ivan Podogov | f2f5dc3 | 2018-02-27 17:58:16 +0000 | [diff] [blame] | 108 | out.writeString(mName); |
| 109 | out.writeString(mDescription); |
| 110 | out.writeString(mProvider); |
| 111 | out.writeByte(mSubclass); |
| 112 | out.writeByteArray(mDescriptors); |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 113 | } |
| 114 | } |