ChannelSettings.java revision cc0a86f647320808c5d88da6e9d45c6de10b65b0
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
17package com.android.server.wifi.wificond;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.util.Log;
22
23import java.util.Objects;
24
25/**
26 * ChannelSettings for wificond
27 *
28 * @hide
29 */
30public class ChannelSettings implements Parcelable {
31    private static final String TAG = "ChannelSettings";
32
33    public int frequency;
34
35    /** public constructor */
36    public ChannelSettings() { }
37
38    /** override comparator */
39    @Override
40    public boolean equals(Object rhs) {
41        if (this == rhs) return true;
42        if (!(rhs instanceof ChannelSettings)) {
43            return false;
44        }
45        ChannelSettings channel = (ChannelSettings) rhs;
46        if (channel == null) {
47            return false;
48        }
49        return frequency == channel.frequency;
50    }
51
52    /** override hash code */
53    @Override
54    public int hashCode() {
55        return Objects.hash(frequency);
56    }
57
58    /** implement Parcelable interface */
59    @Override
60    public int describeContents() {
61        return 0;
62    }
63
64    /**
65     * implement Parcelable interface
66     * |flags| is ignored.
67     * */
68    @Override
69    public void writeToParcel(Parcel out, int flags) {
70        out.writeInt(frequency);
71    }
72
73    /** implement Parcelable interface */
74    public static final Parcelable.Creator<ChannelSettings> CREATOR =
75            new Parcelable.Creator<ChannelSettings>() {
76        /**
77         * Caller is responsible for providing a valid parcel.
78         */
79        @Override
80        public ChannelSettings createFromParcel(Parcel in) {
81            ChannelSettings result = new ChannelSettings();
82            result.frequency = in.readInt();
83            if (in.dataAvail() != 0) {
84                Log.e(TAG, "Found trailing data after parcel parsing.");
85            }
86
87            return result;
88        }
89
90        @Override
91        public ChannelSettings[] newArray(int size) {
92            return new ChannelSettings[size];
93        }
94    };
95}
96