blob: c8b8ffb9846b1ea716f2e4c96e868dc0694cbbeb [file] [log] [blame]
yinxuf19bc1a2017-04-12 16:09:54 -07001/*
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
17package android.telephony;
18
yinxubbc3d362017-11-30 14:58:36 -080019import android.annotation.IntDef;
yinxuf19bc1a2017-04-12 16:09:54 -070020import android.os.Parcel;
21import android.os.Parcelable;
22
yinxubbc3d362017-11-30 14:58:36 -080023import java.lang.annotation.Retention;
24import java.lang.annotation.RetentionPolicy;
Sooraj Sasindranbdca31b2019-12-10 19:29:01 -080025import java.util.ArrayList;
26import java.util.Arrays;
yinxuf19bc1a2017-04-12 16:09:54 -070027
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.
yinxuf19bc1a2017-04-12 16:09:54 -070034 */
35public final class NetworkScanRequest implements Parcelable {
36
yinxua88d1992017-05-30 18:04:19 -070037 // 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 Sasindran6e2226d2017-07-20 02:43:58 -070044 /** @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;
yinxua88d1992017-05-30 18:04:19 -070058
yinxubbc3d362017-11-30 14:58:36 -080059 /** @hide */
60 @Retention(RetentionPolicy.SOURCE)
61 @IntDef({
62 SCAN_TYPE_ONE_SHOT,
63 SCAN_TYPE_PERIODIC,
64 })
65 public @interface ScanType {}
66
yinxuf19bc1a2017-04-12 16:09:54 -070067 /** 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 Sasindran6e2226d2017-07-20 02:43:58 -070074 */
yinxuf19bc1a2017-04-12 16:09:54 -070075 public static final int SCAN_TYPE_PERIODIC = 1;
76
77 /** Defines the type of the scan. */
yinxubbc3d362017-11-30 14:58:36 -080078 private int mScanType;
yinxuf19bc1a2017-04-12 16:09:54 -070079
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -070080 /**
81 * Search periodicity (in seconds).
82 * Expected range for the input is [5s - 300s]
yinxubbc3d362017-11-30 14:58:36 -080083 * This value must be less than or equal to mMaxSearchTime
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -070084 */
yinxubbc3d362017-11-30 14:58:36 -080085 private int mSearchPeriodicity;
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -070086
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 */
yinxubbc3d362017-11-30 14:58:36 -080092 private int mMaxSearchTime;
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -070093
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 */
yinxubbc3d362017-11-30 14:58:36 -0800100 private boolean mIncrementalResults;
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -0700101
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]
yinxubbc3d362017-11-30 14:58:36 -0800106 * This value must be less than or equal to mMaxSearchTime
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -0700107 */
yinxubbc3d362017-11-30 14:58:36 -0800108 private int mIncrementalResultsPeriodicity;
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -0700109
yinxuf19bc1a2017-04-12 16:09:54 -0700110 /** Describes the radio access technologies with bands or channels that need to be scanned. */
yinxubbc3d362017-11-30 14:58:36 -0800111 private RadioAccessSpecifier[] mSpecifiers;
yinxuf19bc1a2017-04-12 16:09:54 -0700112
113 /**
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -0700114 * 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 */
yinxubbc3d362017-11-30 14:58:36 -0800120 private ArrayList<String> mMccMncs;
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -0700121
122 /**
yinxubbc3d362017-11-30 14:58:36 -0800123 * Creates a new NetworkScanRequest with mScanType and network mSpecifiers
yinxuf19bc1a2017-04-12 16:09:54 -0700124 *
yinxubbc3d362017-11-30 14:58:36 -0800125 * @param scanType The type of the scan, can be either one shot or periodic
yinxuf19bc1a2017-04-12 16:09:54 -0700126 * @param specifiers the radio network with bands / channels to be scanned
yinxubbc3d362017-11-30 14:58:36 -0800127 * @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 Sasindran6e2226d2017-07-20 02:43:58 -0700131 * @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
yinxubbc3d362017-11-30 14:58:36 -0800134 * 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.
yinxuf19bc1a2017-04-12 16:09:54 -0700138 */
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -0700139 public NetworkScanRequest(int scanType, RadioAccessSpecifier[] specifiers,
140 int searchPeriodicity,
141 int maxSearchTime,
142 boolean incrementalResults,
143 int incrementalResultsPeriodicity,
144 ArrayList<String> mccMncs) {
yinxubbc3d362017-11-30 14:58:36 -0800145 this.mScanType = scanType;
yinxuf45c9462018-01-09 16:27:10 -0800146 if (specifiers != null) {
147 this.mSpecifiers = specifiers.clone();
148 } else {
149 this.mSpecifiers = null;
150 }
yinxubbc3d362017-11-30 14:58:36 -0800151 this.mSearchPeriodicity = searchPeriodicity;
152 this.mMaxSearchTime = maxSearchTime;
153 this.mIncrementalResults = incrementalResults;
154 this.mIncrementalResultsPeriodicity = incrementalResultsPeriodicity;
Cassie5f460b62018-04-17 09:20:08 -0700155 if (mccMncs != null) {
yinxubbc3d362017-11-30 14:58:36 -0800156 this.mMccMncs = (ArrayList<String>) mccMncs.clone();
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -0700157 } else {
yinxubbc3d362017-11-30 14:58:36 -0800158 this.mMccMncs = new ArrayList<>();
Sooraj Sasindran6e2226d2017-07-20 02:43:58 -0700159 }
yinxuf19bc1a2017-04-12 16:09:54 -0700160 }
161
yinxubbc3d362017-11-30 14:58:36 -0800162 /** 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() {
yinxuf45c9462018-01-09 16:27:10 -0800194 return mSpecifiers == null ? null : mSpecifiers.clone();
yinxubbc3d362017-11-30 14:58:36 -0800195 }
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
yinxuf19bc1a2017-04-12 16:09:54 -0700206 @Override
207 public int describeContents() {
208 return 0;
209 }
210
211 @Override
212 public void writeToParcel(Parcel dest, int flags) {
yinxubbc3d362017-11-30 14:58:36 -0800213 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);
yinxuf19bc1a2017-04-12 16:09:54 -0700220 }
221
222 private NetworkScanRequest(Parcel in) {
yinxubbc3d362017-11-30 14:58:36 -0800223 mScanType = in.readInt();
Sooraj Sasindranbdca31b2019-12-10 19:29:01 -0800224 Parcelable[] tempSpecifiers = in.readParcelableArray(Object.class.getClassLoader());
Sooraj Sasindran8dcbd642019-12-16 16:46:55 -0800225 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 Sasindranbdca31b2019-12-10 19:29:01 -0800232 }
yinxubbc3d362017-11-30 14:58:36 -0800233 mSearchPeriodicity = in.readInt();
234 mMaxSearchTime = in.readInt();
235 mIncrementalResults = in.readBoolean();
236 mIncrementalResultsPeriodicity = in.readInt();
237 mMccMncs = new ArrayList<>();
238 in.readStringList(mMccMncs);
yinxuf19bc1a2017-04-12 16:09:54 -0700239 }
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
yinxubbc3d362017-11-30 14:58:36 -0800255 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))));
yinxuf19bc1a2017-04-12 16:09:54 -0700263 }
264
265 @Override
266 public int hashCode () {
yinxubbc3d362017-11-30 14:58:36 -0800267 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));
yinxuf19bc1a2017-04-12 16:09:54 -0700274 }
275
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700276 public static final @android.annotation.NonNull Creator<NetworkScanRequest> CREATOR =
yinxuf19bc1a2017-04-12 16:09:54 -0700277 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}