yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.telephony; |
| 18 | |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 19 | import android.annotation.IntDef; |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 23 | import java.lang.annotation.Retention; |
| 24 | import java.lang.annotation.RetentionPolicy; |
Sooraj Sasindran | bdca31b | 2019-12-10 19:29:01 -0800 | [diff] [blame] | 25 | import java.util.ArrayList; |
| 26 | import java.util.Arrays; |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Defines a request to peform a network scan. |
| 30 | * |
| 31 | * This class defines whether the network scan will be performed only once or periodically until |
| 32 | * cancelled, when the scan is performed periodically, the time interval is not controlled by the |
| 33 | * user but defined by the modem vendor. |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 34 | */ |
| 35 | public final class NetworkScanRequest implements Parcelable { |
| 36 | |
yinxu | a88d199 | 2017-05-30 18:04:19 -0700 | [diff] [blame] | 37 | // Below size limits for RAN/Band/Channel are for pre-treble modems and will be removed later. |
| 38 | /** @hide */ |
| 39 | public static final int MAX_RADIO_ACCESS_NETWORKS = 8; |
| 40 | /** @hide */ |
| 41 | public static final int MAX_BANDS = 8; |
| 42 | /** @hide */ |
| 43 | public static final int MAX_CHANNELS = 32; |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 44 | /** @hide */ |
| 45 | public static final int MAX_MCC_MNC_LIST_SIZE = 20; |
| 46 | /** @hide */ |
| 47 | public static final int MIN_SEARCH_PERIODICITY_SEC = 5; |
| 48 | /** @hide */ |
| 49 | public static final int MAX_SEARCH_PERIODICITY_SEC = 300; |
| 50 | /** @hide */ |
| 51 | public static final int MIN_SEARCH_MAX_SEC = 60; |
| 52 | /** @hide */ |
| 53 | public static final int MAX_SEARCH_MAX_SEC = 3600; |
| 54 | /** @hide */ |
| 55 | public static final int MIN_INCREMENTAL_PERIODICITY_SEC = 1; |
| 56 | /** @hide */ |
| 57 | public static final int MAX_INCREMENTAL_PERIODICITY_SEC = 10; |
yinxu | a88d199 | 2017-05-30 18:04:19 -0700 | [diff] [blame] | 58 | |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 59 | /** @hide */ |
| 60 | @Retention(RetentionPolicy.SOURCE) |
| 61 | @IntDef({ |
| 62 | SCAN_TYPE_ONE_SHOT, |
| 63 | SCAN_TYPE_PERIODIC, |
| 64 | }) |
| 65 | public @interface ScanType {} |
| 66 | |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 67 | /** Performs the scan only once */ |
| 68 | public static final int SCAN_TYPE_ONE_SHOT = 0; |
| 69 | /** |
| 70 | * Performs the scan periodically until cancelled |
| 71 | * |
| 72 | * The modem will start new scans periodically, and the interval between two scans is usually |
| 73 | * multiple minutes. |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 74 | */ |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 75 | public static final int SCAN_TYPE_PERIODIC = 1; |
| 76 | |
| 77 | /** Defines the type of the scan. */ |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 78 | private int mScanType; |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 79 | |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 80 | /** |
| 81 | * Search periodicity (in seconds). |
| 82 | * Expected range for the input is [5s - 300s] |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 83 | * This value must be less than or equal to mMaxSearchTime |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 84 | */ |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 85 | private int mSearchPeriodicity; |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * Maximum duration of the periodic search (in seconds). |
| 89 | * Expected range for the input is [60s - 3600s] |
| 90 | * If the search lasts this long, it will be terminated. |
| 91 | */ |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 92 | private int mMaxSearchTime; |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Indicates whether the modem should report incremental |
| 96 | * results of the network scan to the client. |
| 97 | * FALSE – Incremental results are not reported. |
| 98 | * TRUE (default) – Incremental results are reported |
| 99 | */ |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 100 | private boolean mIncrementalResults; |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Indicates the periodicity with which the modem should |
| 104 | * report incremental results to the client (in seconds). |
| 105 | * Expected range for the input is [1s - 10s] |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 106 | * This value must be less than or equal to mMaxSearchTime |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 107 | */ |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 108 | private int mIncrementalResultsPeriodicity; |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 109 | |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 110 | /** Describes the radio access technologies with bands or channels that need to be scanned. */ |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 111 | private RadioAccessSpecifier[] mSpecifiers; |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 114 | * Describes the List of PLMN ids (MCC-MNC) |
| 115 | * If any PLMN of this list is found, search should end at that point and |
| 116 | * results with all PLMN found till that point should be sent as response. |
| 117 | * If list not sent, search to be completed till end and all PLMNs found to be reported. |
| 118 | * Max size of array is MAX_MCC_MNC_LIST_SIZE |
| 119 | */ |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 120 | private ArrayList<String> mMccMncs; |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 123 | * Creates a new NetworkScanRequest with mScanType and network mSpecifiers |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 124 | * |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 125 | * @param scanType The type of the scan, can be either one shot or periodic |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 126 | * @param specifiers the radio network with bands / channels to be scanned |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 127 | * @param searchPeriodicity The modem will restart the scan every searchPeriodicity seconds if |
| 128 | * no network has been found, until it reaches the maxSearchTime. Only |
| 129 | * valid when scan type is periodic scan. |
| 130 | * @param maxSearchTime Maximum duration of the search (in seconds) |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 131 | * @param incrementalResults Indicates whether the modem should report incremental |
| 132 | * results of the network scan to the client |
| 133 | * @param incrementalResultsPeriodicity Indicates the periodicity with which the modem should |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 134 | * report incremental results to the client (in seconds), |
| 135 | * only valid when incrementalResults is true |
| 136 | * @param mccMncs Describes the list of PLMN ids (MCC-MNC), once any network in the list has |
| 137 | * been found, the scan will be terminated by the modem. |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 138 | */ |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 139 | public NetworkScanRequest(int scanType, RadioAccessSpecifier[] specifiers, |
| 140 | int searchPeriodicity, |
| 141 | int maxSearchTime, |
| 142 | boolean incrementalResults, |
| 143 | int incrementalResultsPeriodicity, |
| 144 | ArrayList<String> mccMncs) { |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 145 | this.mScanType = scanType; |
yinxu | f45c946 | 2018-01-09 16:27:10 -0800 | [diff] [blame] | 146 | if (specifiers != null) { |
| 147 | this.mSpecifiers = specifiers.clone(); |
| 148 | } else { |
| 149 | this.mSpecifiers = null; |
| 150 | } |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 151 | this.mSearchPeriodicity = searchPeriodicity; |
| 152 | this.mMaxSearchTime = maxSearchTime; |
| 153 | this.mIncrementalResults = incrementalResults; |
| 154 | this.mIncrementalResultsPeriodicity = incrementalResultsPeriodicity; |
Cassie | 5f460b6 | 2018-04-17 09:20:08 -0700 | [diff] [blame] | 155 | if (mccMncs != null) { |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 156 | this.mMccMncs = (ArrayList<String>) mccMncs.clone(); |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 157 | } else { |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 158 | this.mMccMncs = new ArrayList<>(); |
Sooraj Sasindran | 6e2226d | 2017-07-20 02:43:58 -0700 | [diff] [blame] | 159 | } |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 160 | } |
| 161 | |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 162 | /** Returns the type of the scan. */ |
| 163 | @ScanType |
| 164 | public int getScanType() { |
| 165 | return mScanType; |
| 166 | } |
| 167 | |
| 168 | /** Returns the search periodicity in seconds. */ |
| 169 | public int getSearchPeriodicity() { |
| 170 | return mSearchPeriodicity; |
| 171 | } |
| 172 | |
| 173 | /** Returns maximum duration of the periodic search in seconds. */ |
| 174 | public int getMaxSearchTime() { |
| 175 | return mMaxSearchTime; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Returns whether incremental result is enabled. |
| 180 | * FALSE – Incremental results is not enabled. |
| 181 | * TRUE – Incremental results is reported. |
| 182 | */ |
| 183 | public boolean getIncrementalResults() { |
| 184 | return mIncrementalResults; |
| 185 | } |
| 186 | |
| 187 | /** Returns the periodicity in seconds of incremental results. */ |
| 188 | public int getIncrementalResultsPeriodicity() { |
| 189 | return mIncrementalResultsPeriodicity; |
| 190 | } |
| 191 | |
| 192 | /** Returns the radio access technologies with bands or channels that need to be scanned. */ |
| 193 | public RadioAccessSpecifier[] getSpecifiers() { |
yinxu | f45c946 | 2018-01-09 16:27:10 -0800 | [diff] [blame] | 194 | return mSpecifiers == null ? null : mSpecifiers.clone(); |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Returns the List of PLMN ids (MCC-MNC) for early termination of scan. |
| 199 | * If any PLMN of this list is found, search should end at that point and |
| 200 | * results with all PLMN found till that point should be sent as response. |
| 201 | */ |
| 202 | public ArrayList<String> getPlmns() { |
| 203 | return (ArrayList<String>) mMccMncs.clone(); |
| 204 | } |
| 205 | |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 206 | @Override |
| 207 | public int describeContents() { |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | @Override |
| 212 | public void writeToParcel(Parcel dest, int flags) { |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 213 | dest.writeInt(mScanType); |
| 214 | dest.writeParcelableArray(mSpecifiers, flags); |
| 215 | dest.writeInt(mSearchPeriodicity); |
| 216 | dest.writeInt(mMaxSearchTime); |
| 217 | dest.writeBoolean(mIncrementalResults); |
| 218 | dest.writeInt(mIncrementalResultsPeriodicity); |
| 219 | dest.writeStringList(mMccMncs); |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | private NetworkScanRequest(Parcel in) { |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 223 | mScanType = in.readInt(); |
Sooraj Sasindran | bdca31b | 2019-12-10 19:29:01 -0800 | [diff] [blame] | 224 | Parcelable[] tempSpecifiers = in.readParcelableArray(Object.class.getClassLoader()); |
Sooraj Sasindran | 8dcbd64 | 2019-12-16 16:46:55 -0800 | [diff] [blame] | 225 | if (tempSpecifiers != null) { |
| 226 | mSpecifiers = new RadioAccessSpecifier[tempSpecifiers.length]; |
| 227 | for (int i = 0; i < tempSpecifiers.length; i++) { |
| 228 | mSpecifiers[i] = (RadioAccessSpecifier) tempSpecifiers[i]; |
| 229 | } |
| 230 | } else { |
| 231 | mSpecifiers = null; |
Sooraj Sasindran | bdca31b | 2019-12-10 19:29:01 -0800 | [diff] [blame] | 232 | } |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 233 | mSearchPeriodicity = in.readInt(); |
| 234 | mMaxSearchTime = in.readInt(); |
| 235 | mIncrementalResults = in.readBoolean(); |
| 236 | mIncrementalResultsPeriodicity = in.readInt(); |
| 237 | mMccMncs = new ArrayList<>(); |
| 238 | in.readStringList(mMccMncs); |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public boolean equals (Object o) { |
| 243 | NetworkScanRequest nsr; |
| 244 | |
| 245 | try { |
| 246 | nsr = (NetworkScanRequest) o; |
| 247 | } catch (ClassCastException ex) { |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | if (o == null) { |
| 252 | return false; |
| 253 | } |
| 254 | |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 255 | return (mScanType == nsr.mScanType |
| 256 | && Arrays.equals(mSpecifiers, nsr.mSpecifiers) |
| 257 | && mSearchPeriodicity == nsr.mSearchPeriodicity |
| 258 | && mMaxSearchTime == nsr.mMaxSearchTime |
| 259 | && mIncrementalResults == nsr.mIncrementalResults |
| 260 | && mIncrementalResultsPeriodicity == nsr.mIncrementalResultsPeriodicity |
| 261 | && (((mMccMncs != null) |
| 262 | && mMccMncs.equals(nsr.mMccMncs)))); |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public int hashCode () { |
yinxu | bbc3d36 | 2017-11-30 14:58:36 -0800 | [diff] [blame] | 267 | return ((mScanType * 31) |
| 268 | + (Arrays.hashCode(mSpecifiers)) * 37 |
| 269 | + (mSearchPeriodicity * 41) |
| 270 | + (mMaxSearchTime * 43) |
| 271 | + ((mIncrementalResults == true? 1 : 0) * 47) |
| 272 | + (mIncrementalResultsPeriodicity * 53) |
| 273 | + (mMccMncs.hashCode() * 59)); |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 276 | public static final @android.annotation.NonNull Creator<NetworkScanRequest> CREATOR = |
yinxu | f19bc1a | 2017-04-12 16:09:54 -0700 | [diff] [blame] | 277 | new Creator<NetworkScanRequest>() { |
| 278 | @Override |
| 279 | public NetworkScanRequest createFromParcel(Parcel in) { |
| 280 | return new NetworkScanRequest(in); |
| 281 | } |
| 282 | |
| 283 | @Override |
| 284 | public NetworkScanRequest[] newArray(int size) { |
| 285 | return new NetworkScanRequest[size]; |
| 286 | } |
| 287 | }; |
| 288 | } |