1/* 2* Copyright (C) 2015 Samsung System LSI 3* Licensed under the Apache License, Version 2.0 (the "License"); 4* you may not use this file except in compliance with the License. 5* You may obtain a copy of the License at 6* 7* http://www.apache.org/licenses/LICENSE-2.0 8* 9* Unless required by applicable law or agreed to in writing, software 10* distributed under the License is distributed on an "AS IS" BASIS, 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12* See the License for the specific language governing permissions and 13* limitations under the License. 14*/ 15package android.bluetooth; 16 17import android.os.Parcel; 18import android.os.Parcelable; 19 20import java.util.Arrays; 21 22/** 23 * Data representation of a Object Push Profile Server side SDP record. 24 */ 25 26/** @hide */ 27public class SdpOppOpsRecord implements Parcelable { 28 29 private final String mServiceName; 30 private final int mRfcommChannel; 31 private final int mL2capPsm; 32 private final int mProfileVersion; 33 private final byte[] mFormatsList; 34 35 public SdpOppOpsRecord(String serviceName, int rfcommChannel, 36 int l2capPsm, int version, byte[] formatsList) { 37 super(); 38 mServiceName = serviceName; 39 mRfcommChannel = rfcommChannel; 40 mL2capPsm = l2capPsm; 41 mProfileVersion = version; 42 mFormatsList = formatsList; 43 } 44 45 public String getServiceName() { 46 return mServiceName; 47 } 48 49 public int getRfcommChannel() { 50 return mRfcommChannel; 51 } 52 53 public int getL2capPsm() { 54 return mL2capPsm; 55 } 56 57 public int getProfileVersion() { 58 return mProfileVersion; 59 } 60 61 public byte[] getFormatsList() { 62 return mFormatsList; 63 } 64 65 @Override 66 public int describeContents() { 67 /* No special objects */ 68 return 0; 69 } 70 71 public SdpOppOpsRecord(Parcel in) { 72 mRfcommChannel = in.readInt(); 73 mL2capPsm = in.readInt(); 74 mProfileVersion = in.readInt(); 75 mServiceName = in.readString(); 76 int arrayLength = in.readInt(); 77 if (arrayLength > 0) { 78 byte[] bytes = new byte[arrayLength]; 79 in.readByteArray(bytes); 80 mFormatsList = bytes; 81 } else { 82 mFormatsList = null; 83 } 84 } 85 86 @Override 87 public void writeToParcel(Parcel dest, int flags) { 88 dest.writeInt(mRfcommChannel); 89 dest.writeInt(mL2capPsm); 90 dest.writeInt(mProfileVersion); 91 dest.writeString(mServiceName); 92 if (mFormatsList != null && mFormatsList.length > 0) { 93 dest.writeInt(mFormatsList.length); 94 dest.writeByteArray(mFormatsList); 95 } else { 96 dest.writeInt(0); 97 } 98 } 99 100 @Override 101 public String toString() { 102 StringBuilder sb = new StringBuilder("Bluetooth OPP Server SDP Record:\n"); 103 sb.append(" RFCOMM Chan Number: ").append(mRfcommChannel); 104 sb.append("\n L2CAP PSM: ").append(mL2capPsm); 105 sb.append("\n Profile version: ").append(mProfileVersion); 106 sb.append("\n Service Name: ").append(mServiceName); 107 sb.append("\n Formats List: ").append(Arrays.toString(mFormatsList)); 108 return sb.toString(); 109 } 110 111 public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 112 public SdpOppOpsRecord createFromParcel(Parcel in) { 113 return new SdpOppOpsRecord(in); 114 } 115 116 public SdpOppOpsRecord[] newArray(int size) { 117 return new SdpOppOpsRecord[size]; 118 } 119 }; 120 121} 122