1 package com.android.anqp; 2 3 import java.net.ProtocolException; 4 import java.nio.ByteBuffer; 5 import java.nio.charset.StandardCharsets; 6 7 import static com.android.anqp.Constants.SHORT_MASK; 8 9 /** 10 * The Icons available OSU Providers sub field, as specified in 11 * Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00, 12 * section 4.8.1.4 13 */ 14 public class IconInfo { 15 private final int mWidth; 16 private final int mHeight; 17 private final String mLanguage; 18 private final String mIconType; 19 private final String mFileName; 20 IconInfo(ByteBuffer payload)21 public IconInfo(ByteBuffer payload) throws ProtocolException { 22 if (payload.remaining() < 9) { 23 throw new ProtocolException("Truncated icon meta data"); 24 } 25 26 mWidth = payload.getShort() & SHORT_MASK; 27 mHeight = payload.getShort() & SHORT_MASK; 28 mLanguage = Constants.getTrimmedString(payload, 29 Constants.LANG_CODE_LENGTH, StandardCharsets.US_ASCII); 30 mIconType = Constants.getPrefixedString(payload, 1, StandardCharsets.US_ASCII); 31 mFileName = Constants.getPrefixedString(payload, 1, StandardCharsets.UTF_8); 32 } 33 getWidth()34 public int getWidth() { 35 return mWidth; 36 } 37 getHeight()38 public int getHeight() { 39 return mHeight; 40 } 41 getLanguage()42 public String getLanguage() { 43 return mLanguage; 44 } 45 getIconType()46 public String getIconType() { 47 return mIconType; 48 } 49 getFileName()50 public String getFileName() { 51 return mFileName; 52 } 53 54 @Override equals(Object thatObject)55 public boolean equals(Object thatObject) { 56 if (this == thatObject) { 57 return true; 58 } 59 if (thatObject == null || getClass() != thatObject.getClass()) { 60 return false; 61 } 62 63 IconInfo that = (IconInfo) thatObject; 64 return mHeight == that.mHeight && 65 mWidth == that.mWidth && 66 mFileName.equals(that.mFileName) && 67 mIconType.equals(that.mIconType) && 68 mLanguage.equals(that.mLanguage); 69 } 70 71 @Override hashCode()72 public int hashCode() { 73 int result = mWidth; 74 result = 31 * result + mHeight; 75 result = 31 * result + mLanguage.hashCode(); 76 result = 31 * result + mIconType.hashCode(); 77 result = 31 * result + mFileName.hashCode(); 78 return result; 79 } 80 81 @Override toString()82 public String toString() { 83 return "IconInfo{" + 84 "Width=" + mWidth + 85 ", Height=" + mHeight + 86 ", Language=" + mLanguage + 87 ", IconType='" + mIconType + '\'' + 88 ", FileName='" + mFileName + '\'' + 89 '}'; 90 } 91 } 92