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.BufferUnderflowException; 22 import java.nio.ByteBuffer; 23 import java.util.ArrayList; 24 import java.util.Collections; 25 import java.util.List; 26 27 /** 28 * The Connection Capability vendor specific ANQP Element, 29 * Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00, 30 * section 4.5 31 * 32 * Format: 33 * | ProtoPort Tuple #1 (optiional) | .... 34 * 4 35 */ 36 public class HSConnectionCapabilityElement extends ANQPElement { 37 private final List<ProtocolPortTuple> mStatusList; 38 39 @VisibleForTesting HSConnectionCapabilityElement(List<ProtocolPortTuple> statusList)40 public HSConnectionCapabilityElement(List<ProtocolPortTuple> statusList) { 41 super(Constants.ANQPElementType.HSConnCapability); 42 mStatusList = statusList; 43 } 44 45 /** 46 * Parse a HSConnectionCapabilityElement from the given buffer. 47 * 48 * @param payload The byte buffer to read from 49 * @return {@link HSConnectionCapabilityElement} 50 * @throws BufferUnderflowException 51 */ parse(ByteBuffer payload)52 public static HSConnectionCapabilityElement parse(ByteBuffer payload) { 53 List<ProtocolPortTuple> statusList = new ArrayList<>(); 54 while (payload.hasRemaining()) { 55 statusList.add(ProtocolPortTuple.parse(payload)); 56 } 57 return new HSConnectionCapabilityElement(statusList); 58 } 59 getStatusList()60 public List<ProtocolPortTuple> getStatusList() { 61 return Collections.unmodifiableList(mStatusList); 62 } 63 64 @Override equals(Object thatObject)65 public boolean equals(Object thatObject) { 66 if (this == thatObject) { 67 return true; 68 } 69 if (!(thatObject instanceof HSConnectionCapabilityElement)) { 70 return false; 71 } 72 HSConnectionCapabilityElement that = (HSConnectionCapabilityElement) thatObject; 73 return mStatusList.equals(that.mStatusList); 74 } 75 76 @Override hashCode()77 public int hashCode() { 78 return mStatusList.hashCode(); 79 } 80 81 @Override toString()82 public String toString() { 83 return "HSConnectionCapability{" + 84 "mStatusList=" + mStatusList + 85 '}'; 86 } 87 } 88