summaryrefslogtreecommitdiffstats
path: root/service/java/com/android/server/wifi/hotspot2/anqp/IconInfo.java
blob: c89c4429c3c9b154f682564ea0c803cfcd3354a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.android.server.wifi.hotspot2.anqp;

import java.net.ProtocolException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Locale;

import static com.android.server.wifi.hotspot2.anqp.Constants.SHORT_MASK;

/**
 * The Icons available OSU Providers sub field, as specified in
 * Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00,
 * section 4.8.1.4
 */
public class IconInfo {
    private final int mWidth;
    private final int mHeight;
    private final String mLanguage;
    private final String mIconType;
    private final String mFileName;

    public IconInfo(ByteBuffer payload) throws ProtocolException {
        if (payload.remaining() < 9) {
            throw new ProtocolException("Truncated icon meta data");
        }

        mWidth = payload.getShort() & SHORT_MASK;
        mHeight = payload.getShort() & SHORT_MASK;
        mLanguage = Constants.getTrimmedString(payload,
                Constants.LANG_CODE_LENGTH, StandardCharsets.US_ASCII);
        mIconType = Constants.getPrefixedString(payload, 1, StandardCharsets.US_ASCII);
        mFileName = Constants.getPrefixedString(payload, 1, StandardCharsets.UTF_8);
    }

    public int getWidth() {
        return mWidth;
    }

    public int getHeight() {
        return mHeight;
    }

    public String getLanguage() {
        return mLanguage;
    }

    public String getIconType() {
        return mIconType;
    }

    public String getFileName() {
        return mFileName;
    }

    @Override
    public boolean equals(Object thatObject) {
        if (this == thatObject) {
            return true;
        }
        if (thatObject == null || getClass() != thatObject.getClass()) {
            return false;
        }

        IconInfo that = (IconInfo) thatObject;
        return mHeight == that.mHeight &&
                mWidth == that.mWidth &&
                mFileName.equals(that.mFileName) &&
                mIconType.equals(that.mIconType) &&
                mLanguage.equals(that.mLanguage);
    }

    @Override
    public int hashCode() {
        int result = mWidth;
        result = 31 * result + mHeight;
        result = 31 * result + mLanguage.hashCode();
        result = 31 * result + mIconType.hashCode();
        result = 31 * result + mFileName.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "IconInfo{" +
                "Width=" + mWidth +
                ", Height=" + mHeight +
                ", Language=" + mLanguage +
                ", IconType='" + mIconType + '\'' +
                ", FileName='" + mFileName + '\'' +
                '}';
    }
}