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