1 /* 2 * Copyright (c) 2014, 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; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Wifi Channel 24 * 25 * @see ScanSettings 26 * 27 * @hide 28 */ 29 public class WifiChannel implements Parcelable { 30 31 private static final int MIN_FREQ_MHZ = 2412; 32 private static final int MAX_FREQ_MHZ = 5825; 33 34 private static final int MIN_CHANNEL_NUM = 1; 35 private static final int MAX_CHANNEL_NUM = 196; 36 37 /** frequency */ 38 public int freqMHz; 39 40 /** channel number */ 41 public int channelNum; 42 43 /** is it a DFS channel? */ 44 public boolean isDFS; 45 46 /** public constructor */ WifiChannel()47 public WifiChannel() { } 48 49 /** check for validity */ isValid()50 public boolean isValid() { 51 if (freqMHz < MIN_FREQ_MHZ || freqMHz > MAX_FREQ_MHZ) return false; 52 if (channelNum < MIN_CHANNEL_NUM || channelNum > MAX_CHANNEL_NUM) return false; 53 return true; 54 } 55 56 /** implement Parcelable interface */ 57 @Override describeContents()58 public int describeContents() { 59 return 0; 60 } 61 62 /** implement Parcelable interface */ 63 @Override writeToParcel(Parcel out, int flags)64 public void writeToParcel(Parcel out, int flags) { 65 out.writeInt(freqMHz); 66 out.writeInt(channelNum); 67 out.writeInt(isDFS ? 1 : 0); 68 } 69 70 /** implement Parcelable interface */ 71 public static final Parcelable.Creator<WifiChannel> CREATOR = 72 new Parcelable.Creator<WifiChannel>() { 73 @Override 74 public WifiChannel createFromParcel(Parcel in) { 75 WifiChannel channel = new WifiChannel(); 76 channel.freqMHz = in.readInt(); 77 channel.channelNum = in.readInt(); 78 channel.isDFS = in.readInt() != 0; 79 return channel; 80 } 81 82 @Override 83 public WifiChannel[] newArray(int size) { 84 return new WifiChannel[size]; 85 } 86 }; 87 } 88