blob: 690e44a52647ec0e445793a8a123acea2b7219bf [file] [log] [blame]
yinxufdfb6f42017-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
19import android.os.Parcel;
20import android.os.Parcelable;
21
22import java.util.Arrays;
23
24/**
25 * Describes a particular radio access network to be scanned.
26 *
27 * The scan can be performed on either bands or channels for a specific radio access network type.
yinxufdfb6f42017-04-12 16:09:54 -070028 */
29public final class RadioAccessSpecifier implements Parcelable {
30
31 /**
32 * The radio access network that needs to be scanned
33 *
yinxubbc3d362017-11-30 14:58:36 -080034 * This parameter must be provided or else the scan will be rejected.
35 *
Malcolm Chen51695b22018-01-03 12:10:33 -080036 * See {@link AccessNetworkConstants.AccessNetworkType} for details.
yinxufdfb6f42017-04-12 16:09:54 -070037 */
yinxubbc3d362017-11-30 14:58:36 -080038 private int mRadioAccessNetwork;
yinxufdfb6f42017-04-12 16:09:54 -070039
40 /**
41 * The frequency bands that need to be scanned
42 *
yinxubbc3d362017-11-30 14:58:36 -080043 * When no specific bands are specified (empty array or null), all the frequency bands
44 * supported by the modem will be scanned.
yinxufdfb6f42017-04-12 16:09:54 -070045 *
Malcolm Chen51695b22018-01-03 12:10:33 -080046 * See {@link AccessNetworkConstants} for details.
yinxufdfb6f42017-04-12 16:09:54 -070047 */
yinxubbc3d362017-11-30 14:58:36 -080048 private int[] mBands;
yinxufdfb6f42017-04-12 16:09:54 -070049
50 /**
51 * The frequency channels that need to be scanned
52 *
yinxubbc3d362017-11-30 14:58:36 -080053 * When any specific channels are provided for scan, the corresponding frequency bands that
54 * contains those channels must also be provided, or else the channels will be ignored.
yinxufdfb6f42017-04-12 16:09:54 -070055 *
yinxubbc3d362017-11-30 14:58:36 -080056 * When no specific channels are specified (empty array or null), all the frequency channels
57 * supported by the modem will be scanned.
58 *
Malcolm Chen51695b22018-01-03 12:10:33 -080059 * See {@link AccessNetworkConstants} for details.
yinxufdfb6f42017-04-12 16:09:54 -070060 */
yinxubbc3d362017-11-30 14:58:36 -080061 private int[] mChannels;
yinxufdfb6f42017-04-12 16:09:54 -070062
63 /**
64 * Creates a new RadioAccessSpecifier with radio network, bands and channels
65 *
66 * The user must specify the radio network type, and at least specify either of frequency
67 * bands or channels.
68 *
69 * @param ran The type of the radio access network
70 * @param bands the frequency bands to be scanned
71 * @param channels the frequency bands to be scanned
72 */
73 public RadioAccessSpecifier(int ran, int[] bands, int[] channels) {
yinxubbc3d362017-11-30 14:58:36 -080074 this.mRadioAccessNetwork = ran;
yinxuf45c9462018-01-09 16:27:10 -080075 if (bands != null) {
76 this.mBands = bands.clone();
77 } else {
78 this.mBands = null;
79 }
80 if (channels != null) {
81 this.mChannels = channels.clone();
82 } else {
83 this.mChannels = null;
84 }
yinxubbc3d362017-11-30 14:58:36 -080085 }
86
87 /**
88 * Returns the radio access network that needs to be scanned.
89 *
Malcolm Chen51695b22018-01-03 12:10:33 -080090 * The returned value is define in {@link AccessNetworkConstants.AccessNetworkType};
yinxubbc3d362017-11-30 14:58:36 -080091 */
92 public int getRadioAccessNetwork() {
93 return mRadioAccessNetwork;
94 }
95
96 /**
97 * Returns the frequency bands that need to be scanned.
98 *
Malcolm Chen51695b22018-01-03 12:10:33 -080099 * The returned value is defined in either of {@link AccessNetworkConstants.GeranBand},
100 * {@link AccessNetworkConstants.UtranBand} and {@link AccessNetworkConstants.EutranBand}, and
yinxubbc3d362017-11-30 14:58:36 -0800101 * it depends on the returned value of {@link #getRadioAccessNetwork()}.
102 */
103 public int[] getBands() {
yinxuf45c9462018-01-09 16:27:10 -0800104 return mBands == null ? null : mBands.clone();
yinxubbc3d362017-11-30 14:58:36 -0800105 }
106
107 /** Returns the frequency channels that need to be scanned. */
108 public int[] getChannels() {
yinxuf45c9462018-01-09 16:27:10 -0800109 return mChannels == null ? null : mChannels.clone();
yinxufdfb6f42017-04-12 16:09:54 -0700110 }
111
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700112 public static final @android.annotation.NonNull Parcelable.Creator<RadioAccessSpecifier> CREATOR =
yinxufdfb6f42017-04-12 16:09:54 -0700113 new Parcelable.Creator<RadioAccessSpecifier> (){
114 @Override
115 public RadioAccessSpecifier createFromParcel(Parcel in) {
116 return new RadioAccessSpecifier(in);
117 }
118
119 @Override
120 public RadioAccessSpecifier[] newArray(int size) {
121 return new RadioAccessSpecifier[size];
122 }
123 };
124
125 @Override
126 public int describeContents() {
127 return 0;
128 }
129
130 @Override
131 public void writeToParcel(Parcel dest, int flags) {
yinxubbc3d362017-11-30 14:58:36 -0800132 dest.writeInt(mRadioAccessNetwork);
133 dest.writeIntArray(mBands);
134 dest.writeIntArray(mChannels);
yinxufdfb6f42017-04-12 16:09:54 -0700135 }
136
137 private RadioAccessSpecifier(Parcel in) {
yinxubbc3d362017-11-30 14:58:36 -0800138 mRadioAccessNetwork = in.readInt();
139 mBands = in.createIntArray();
140 mChannels = in.createIntArray();
yinxufdfb6f42017-04-12 16:09:54 -0700141 }
142
143 @Override
144 public boolean equals (Object o) {
145 RadioAccessSpecifier ras;
146
147 try {
148 ras = (RadioAccessSpecifier) o;
149 } catch (ClassCastException ex) {
150 return false;
151 }
152
153 if (o == null) {
154 return false;
155 }
156
yinxubbc3d362017-11-30 14:58:36 -0800157 return (mRadioAccessNetwork == ras.mRadioAccessNetwork
158 && Arrays.equals(mBands, ras.mBands)
159 && Arrays.equals(mChannels, ras.mChannels));
yinxufdfb6f42017-04-12 16:09:54 -0700160 }
161
162 @Override
163 public int hashCode () {
yinxubbc3d362017-11-30 14:58:36 -0800164 return ((mRadioAccessNetwork * 31)
165 + (Arrays.hashCode(mBands) * 37)
166 + (Arrays.hashCode(mChannels)) * 39);
yinxufdfb6f42017-04-12 16:09:54 -0700167 }
168}