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