summaryrefslogtreecommitdiffstats
path: root/wifi/java/android/net/wifi/WifiChannel.java
blob: ba6a64ff86e9396843c2cc9f7a3cf1dbc452e296 (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

package android.net.wifi;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * A class representing one wifi channel or frequency
 * @hide
 */
public class WifiChannel implements Parcelable {
    public int channel;
    public int frequency;
    public boolean ibssAllowed;

    public String toString() {
        StringBuffer sbuf = new StringBuffer();
        sbuf.append(" channel: ").append(channel);
        sbuf.append(" freq: ").append(frequency);
        sbuf.append(" MHz");
        sbuf.append(" IBSS: ").append(ibssAllowed ? "allowed" : "not allowed");
        sbuf.append('\n');
        return sbuf.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof WifiChannel) {
            WifiChannel w = (WifiChannel)o;
            return (this.channel == w.channel &&
                    this.frequency == w.frequency &&
                    this.ibssAllowed == w.ibssAllowed);
        }
        return false;
    }

    /** Implement the Parcelable interface */
    public int describeContents() {
        return 0;
    }

    public WifiChannel() {
        channel = 0;
        frequency = 0;
        ibssAllowed = false;
    }

    public WifiChannel(int ch, int freq, boolean ibss) {
        channel = ch;
        frequency = freq;
        ibssAllowed = ibss;
    }

    /* Copy constructor */
    public WifiChannel(WifiChannel source) {
        if (source != null) {
            channel = source.channel;
            frequency = source.frequency;
            ibssAllowed = source.ibssAllowed;
        }
    }

    /** Implement the Parcelable interface */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(channel);
        dest.writeInt(frequency);
        dest.writeInt(ibssAllowed ? 1 : 0);
    }

    /** Implement the Parcelable interface */
    public static final Creator<WifiChannel> CREATOR =
            new Creator<WifiChannel>() {
                public WifiChannel createFromParcel(Parcel in) {
                    WifiChannel ch = new WifiChannel();
                    ch.channel = in.readInt();
                    ch.frequency = in.readInt();
                    ch.ibssAllowed = (in.readInt() == 1);
                    return ch;
                }

                public WifiChannel[] newArray(int size) {
                    return new WifiChannel[size];
                }
            };
}