OSDN Git Service

Bluetooth: Check descriptors size in BluetoothHidDeviceAppSdpSettings
[android-x86/frameworks-base.git] / core / java / android / bluetooth / BluetoothHidDeviceAppSdpSettings.java
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 import java.util.Random;
24
25 /** @hide */
26 public final class BluetoothHidDeviceAppSdpSettings implements Parcelable {
27
28     private static final int MAX_DESCRIPTOR_SIZE = 2048;
29
30     final public String name;
31     final public String description;
32     final public String provider;
33     final public byte subclass;
34     final public byte[] descriptors;
35
36     public BluetoothHidDeviceAppSdpSettings(String name, String description, String provider,
37             byte subclass, byte[] descriptors) {
38         this.name = name;
39         this.description = description;
40         this.provider = provider;
41         this.subclass = subclass;
42
43         if (descriptors == null || descriptors.length > MAX_DESCRIPTOR_SIZE) {
44             EventLog.writeEvent(0x534e4554, "119819889", -1, "");
45             throw new IllegalArgumentException("descriptors must be not null and shorter than "
46                     + MAX_DESCRIPTOR_SIZE);
47         }
48         this.descriptors = descriptors.clone();
49     }
50
51     @Override
52     public boolean equals(Object o) {
53         if (o instanceof BluetoothHidDeviceAppSdpSettings) {
54             BluetoothHidDeviceAppSdpSettings sdp = (BluetoothHidDeviceAppSdpSettings) o;
55             return false;
56         }
57         return false;
58     }
59
60     @Override
61     public int describeContents() {
62         return 0;
63     }
64
65     public static final Parcelable.Creator<BluetoothHidDeviceAppSdpSettings> CREATOR =
66         new Parcelable.Creator<BluetoothHidDeviceAppSdpSettings>() {
67
68         @Override
69         public BluetoothHidDeviceAppSdpSettings createFromParcel(Parcel in) {
70
71             return new BluetoothHidDeviceAppSdpSettings(in.readString(), in.readString(),
72                     in.readString(), in.readByte(), in.createByteArray());
73         }
74
75         @Override
76         public BluetoothHidDeviceAppSdpSettings[] newArray(int size) {
77             return new BluetoothHidDeviceAppSdpSettings[size];
78         }
79     };
80
81     @Override
82     public void writeToParcel(Parcel out, int flags) {
83         out.writeString(name);
84         out.writeString(description);
85         out.writeString(provider);
86         out.writeByte(subclass);
87         out.writeByteArray(descriptors);
88     }
89 }