Home | History | Annotate | Download | only in anqp
      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 com.android.server.wifi.hotspot2.anqp;
     18 
     19 import com.android.internal.annotations.VisibleForTesting;
     20 
     21 import java.nio.ByteBuffer;
     22 import java.util.Arrays;
     23 
     24 /**
     25  * An object holding the raw octets of an ANQP element as provided by the wpa_supplicant.
     26  */
     27 public class RawByteElement extends ANQPElement {
     28     private final byte[] mPayload;
     29 
     30     @VisibleForTesting
     31     public RawByteElement(Constants.ANQPElementType infoID, byte[] payload) {
     32         super(infoID);
     33         mPayload = payload;
     34     }
     35 
     36     /**
     37      * Parse a RawByteElement from the given buffer.
     38      *
     39      * @param payload The byte buffer to read from
     40      * @return {@link HSConnectionCapabilityElement}
     41      */
     42     public static RawByteElement parse(Constants.ANQPElementType infoID, ByteBuffer payload) {
     43         byte[] rawBytes = new byte[payload.remaining()];
     44         if (payload.hasRemaining()) {
     45             payload.get(rawBytes);
     46         }
     47         return new RawByteElement(infoID, rawBytes);
     48     }
     49 
     50     public byte[] getPayload() {
     51         return mPayload;
     52     }
     53 
     54     @Override
     55     public boolean equals(Object thatObject) {
     56         if (this == thatObject) {
     57             return true;
     58         }
     59         if (!(thatObject instanceof RawByteElement)) {
     60             return false;
     61         }
     62         RawByteElement that = (RawByteElement) thatObject;
     63         return getID() == that.getID() && Arrays.equals(mPayload, that.mPayload);
     64     }
     65 
     66     @Override
     67     public int hashCode() {
     68         return Arrays.hashCode(mPayload);
     69     }
     70 }
     71