• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package android.net.wifi.nl80211;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.util.Log;
22 
23 import java.util.ArrayList;
24 import java.util.Objects;
25 
26 /**
27  * SingleScanSettings for wificond
28  *
29  * @hide
30  */
31 public class SingleScanSettings implements Parcelable {
32     private static final String TAG = "SingleScanSettings";
33 
34     public int scanType;
35     public boolean enable6GhzRnr;
36     public ArrayList<ChannelSettings> channelSettings;
37     public ArrayList<HiddenNetwork> hiddenNetworks;
38 
39     /** public constructor */
SingleScanSettings()40     public SingleScanSettings() { }
41 
42     /** override comparator */
43     @Override
equals(Object rhs)44     public boolean equals(Object rhs) {
45         if (this == rhs) return true;
46         if (!(rhs instanceof SingleScanSettings)) {
47             return false;
48         }
49         SingleScanSettings settings = (SingleScanSettings) rhs;
50         if (settings == null) {
51             return false;
52         }
53         return scanType == settings.scanType
54                 && enable6GhzRnr == settings.enable6GhzRnr
55                 && channelSettings.equals(settings.channelSettings)
56                 && hiddenNetworks.equals(settings.hiddenNetworks);
57     }
58 
59     /** override hash code */
60     @Override
hashCode()61     public int hashCode() {
62         return Objects.hash(scanType, channelSettings, hiddenNetworks, enable6GhzRnr);
63     }
64 
65 
66     /** implement Parcelable interface */
67     @Override
describeContents()68     public int describeContents() {
69         return 0;
70     }
71 
isValidScanType(int scanType)72     private static boolean isValidScanType(int scanType) {
73         return scanType == IWifiScannerImpl.SCAN_TYPE_LOW_SPAN
74                 || scanType == IWifiScannerImpl.SCAN_TYPE_LOW_POWER
75                 || scanType == IWifiScannerImpl.SCAN_TYPE_HIGH_ACCURACY;
76     }
77 
78     /**
79      * implement Parcelable interface
80      * |flags| is ignored.
81      */
82     @Override
writeToParcel(Parcel out, int flags)83     public void writeToParcel(Parcel out, int flags) {
84         if (!isValidScanType(scanType)) {
85             Log.wtf(TAG, "Invalid scan type " + scanType);
86         }
87         out.writeInt(scanType);
88         out.writeBoolean(enable6GhzRnr);
89         out.writeTypedList(channelSettings);
90         out.writeTypedList(hiddenNetworks);
91     }
92 
93     /** implement Parcelable interface */
94     public static final Parcelable.Creator<SingleScanSettings> CREATOR =
95             new Parcelable.Creator<SingleScanSettings>() {
96         /**
97          * Caller is responsible for providing a valid parcel.
98          */
99         @Override
100         public SingleScanSettings createFromParcel(Parcel in) {
101             SingleScanSettings result = new SingleScanSettings();
102             result.scanType = in.readInt();
103             if (!isValidScanType(result.scanType)) {
104                 Log.wtf(TAG, "Invalid scan type " + result.scanType);
105             }
106             result.enable6GhzRnr = in.readBoolean();
107             result.channelSettings = new ArrayList<ChannelSettings>();
108             in.readTypedList(result.channelSettings, ChannelSettings.CREATOR);
109             result.hiddenNetworks = new ArrayList<HiddenNetwork>();
110             in.readTypedList(result.hiddenNetworks, HiddenNetwork.CREATOR);
111             if (in.dataAvail() != 0) {
112                 Log.e(TAG, "Found trailing data after parcel parsing.");
113             }
114             return result;
115         }
116 
117         @Override
118         public SingleScanSettings[] newArray(int size) {
119             return new SingleScanSettings[size];
120         }
121     };
122 }
123