1 /* 2 * Copyright (C) 2010 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.nfc; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Represents a LLCP packet received in a LLCP Connectionless communication; 24 * @hide 25 */ 26 public class LlcpPacket implements Parcelable { 27 28 private final int mRemoteSap; 29 30 private final byte[] mDataBuffer; 31 32 /** 33 * Creates a LlcpPacket to be sent to a remote Service Access Point number 34 * (SAP) 35 * 36 * @param sap Remote Service Access Point number 37 * @param data Data buffer 38 */ 39 public LlcpPacket(int sap, byte[] data) { 40 mRemoteSap = sap; 41 mDataBuffer = data; 42 } 43 44 /** 45 * Returns the remote Service Access Point number 46 */ 47 public int getRemoteSap() { 48 return mRemoteSap; 49 } 50 51 /** 52 * Returns the data buffer 53 */ 54 public byte[] getDataBuffer() { 55 return mDataBuffer; 56 } 57 58 public int describeContents() { 59 return 0; 60 } 61 62 public void writeToParcel(Parcel dest, int flags) { 63 dest.writeInt(mRemoteSap); 64 dest.writeInt(mDataBuffer.length); 65 dest.writeByteArray(mDataBuffer); 66 } 67 68 public static final Parcelable.Creator<LlcpPacket> CREATOR = new Parcelable.Creator<LlcpPacket>() { 69 public LlcpPacket createFromParcel(Parcel in) { 70 // Remote SAP 71 short sap = (short)in.readInt(); 72 73 // Data Buffer 74 int dataLength = in.readInt(); 75 byte[] data = new byte[dataLength]; 76 in.readByteArray(data); 77 78 return new LlcpPacket(sap, data); 79 } 80 81 public LlcpPacket[] newArray(int size) { 82 return new LlcpPacket[size]; 83 } 84 }; 85 }