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.annotation.DurationMillisLong; 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 import java.util.Objects; 28 29 /** 30 * Configuration for a PNO (preferred network offload). A mechanism by which scans are offloaded 31 * from the host device to the Wi-Fi chip. 32 * 33 * @hide 34 */ 35 @SystemApi 36 public final class PnoSettings implements Parcelable { 37 private long mIntervalMs; 38 private int mMin2gRssi; 39 private int mMin5gRssi; 40 private int mMin6gRssi; 41 private List<PnoNetwork> mPnoNetworks; 42 43 /** Construct an uninitialized PnoSettings object */ PnoSettings()44 public PnoSettings() { } 45 46 /** 47 * Get the requested PNO scan interval in milliseconds. 48 * 49 * @return An interval in milliseconds. 50 */ getIntervalMillis()51 public @DurationMillisLong long getIntervalMillis() { 52 return mIntervalMs; 53 } 54 55 /** 56 * Set the requested PNO scan interval in milliseconds. 57 * 58 * @param intervalMillis An interval in milliseconds. 59 */ setIntervalMillis(@urationMillisLong long intervalMillis)60 public void setIntervalMillis(@DurationMillisLong long intervalMillis) { 61 this.mIntervalMs = intervalMillis; 62 } 63 64 /** 65 * Get the requested minimum RSSI threshold (in dBm) for APs to report in scan results in the 66 * 2.4GHz band. 67 * 68 * @return An RSSI value in dBm. 69 */ getMin2gRssiDbm()70 public int getMin2gRssiDbm() { 71 return mMin2gRssi; 72 } 73 74 /** 75 * Set the requested minimum RSSI threshold (in dBm) for APs to report in scan scan results in 76 * the 2.4GHz band. 77 * 78 * @param min2gRssiDbm An RSSI value in dBm. 79 */ setMin2gRssiDbm(int min2gRssiDbm)80 public void setMin2gRssiDbm(int min2gRssiDbm) { 81 this.mMin2gRssi = min2gRssiDbm; 82 } 83 84 /** 85 * Get the requested minimum RSSI threshold (in dBm) for APs to report in scan results in the 86 * 5GHz band. 87 * 88 * @return An RSSI value in dBm. 89 */ getMin5gRssiDbm()90 public int getMin5gRssiDbm() { 91 return mMin5gRssi; 92 } 93 94 /** 95 * Set the requested minimum RSSI threshold (in dBm) for APs to report in scan scan results in 96 * the 5GHz band. 97 * 98 * @param min5gRssiDbm An RSSI value in dBm. 99 */ setMin5gRssiDbm(int min5gRssiDbm)100 public void setMin5gRssiDbm(int min5gRssiDbm) { 101 this.mMin5gRssi = min5gRssiDbm; 102 } 103 104 /** 105 * Get the requested minimum RSSI threshold (in dBm) for APs to report in scan results in the 106 * 6GHz band. 107 * 108 * @return An RSSI value in dBm. 109 */ getMin6gRssiDbm()110 public int getMin6gRssiDbm() { 111 return mMin6gRssi; 112 } 113 114 /** 115 * Set the requested minimum RSSI threshold (in dBm) for APs to report in scan scan results in 116 * the 6GHz band. 117 * 118 * @param min6gRssiDbm An RSSI value in dBm. 119 */ setMin6gRssiDbm(int min6gRssiDbm)120 public void setMin6gRssiDbm(int min6gRssiDbm) { 121 this.mMin6gRssi = min6gRssiDbm; 122 } 123 124 /** 125 * Return the configured list of specific networks to search for in a PNO scan. 126 * 127 * @return A list of {@link PnoNetwork} objects, possibly empty if non configured. 128 */ getPnoNetworks()129 @NonNull public List<PnoNetwork> getPnoNetworks() { 130 return mPnoNetworks; 131 } 132 133 /** 134 * Set the list of specified networks to scan for in a PNO scan. The networks (APs) are 135 * specified using {@link PnoNetwork}s. An empty list indicates that all networks are scanned 136 * for. 137 * 138 * @param pnoNetworks A (possibly empty) list of {@link PnoNetwork} objects. 139 */ setPnoNetworks(@onNull List<PnoNetwork> pnoNetworks)140 public void setPnoNetworks(@NonNull List<PnoNetwork> pnoNetworks) { 141 this.mPnoNetworks = pnoNetworks; 142 } 143 144 /** override comparator */ 145 @Override equals(Object rhs)146 public boolean equals(Object rhs) { 147 if (this == rhs) return true; 148 if (!(rhs instanceof PnoSettings)) { 149 return false; 150 } 151 PnoSettings settings = (PnoSettings) rhs; 152 if (settings == null) { 153 return false; 154 } 155 return mIntervalMs == settings.mIntervalMs 156 && mMin2gRssi == settings.mMin2gRssi 157 && mMin5gRssi == settings.mMin5gRssi 158 && mMin6gRssi == settings.mMin6gRssi 159 && mPnoNetworks.equals(settings.mPnoNetworks); 160 } 161 162 /** override hash code */ 163 @Override hashCode()164 public int hashCode() { 165 return Objects.hash(mIntervalMs, mMin2gRssi, mMin5gRssi, mMin6gRssi, mPnoNetworks); 166 } 167 168 /** implement Parcelable interface */ 169 @Override describeContents()170 public int describeContents() { 171 return 0; 172 } 173 174 /** 175 * implement Parcelable interface 176 * |flag| is ignored. 177 **/ 178 @Override writeToParcel(@onNull Parcel out, int flags)179 public void writeToParcel(@NonNull Parcel out, int flags) { 180 out.writeLong(mIntervalMs); 181 out.writeInt(mMin2gRssi); 182 out.writeInt(mMin5gRssi); 183 out.writeInt(mMin6gRssi); 184 out.writeTypedList(mPnoNetworks); 185 } 186 187 /** implement Parcelable interface */ 188 @NonNull public static final Parcelable.Creator<PnoSettings> CREATOR = 189 new Parcelable.Creator<PnoSettings>() { 190 @Override 191 public PnoSettings createFromParcel(Parcel in) { 192 PnoSettings result = new PnoSettings(); 193 result.mIntervalMs = in.readLong(); 194 result.mMin2gRssi = in.readInt(); 195 result.mMin5gRssi = in.readInt(); 196 result.mMin6gRssi = in.readInt(); 197 198 result.mPnoNetworks = new ArrayList<>(); 199 in.readTypedList(result.mPnoNetworks, PnoNetwork.CREATOR); 200 201 return result; 202 } 203 204 @Override 205 public PnoSettings[] newArray(int size) { 206 return new PnoSettings[size]; 207 } 208 }; 209 } 210