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