blob: a403095eeceb75e0b5539165197ca5d899afb38e [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},
Sarah Chin21e9c632019-11-05 13:30:10 -0800100 * {@link AccessNetworkConstants.UtranBand}, {@link AccessNetworkConstants.EutranBand},
101 * and {@link AccessNetworkConstants.NgranBands}, and it depends on
102 * the returned value of {@link #getRadioAccessNetwork()}.
yinxubbc3d362017-11-30 14:58:36 -0800103 */
104 public int[] getBands() {
yinxuf45c9462018-01-09 16:27:10 -0800105 return mBands == null ? null : mBands.clone();
yinxubbc3d362017-11-30 14:58:36 -0800106 }
107
108 /** Returns the frequency channels that need to be scanned. */
109 public int[] getChannels() {
yinxuf45c9462018-01-09 16:27:10 -0800110 return mChannels == null ? null : mChannels.clone();
yinxufdfb6f42017-04-12 16:09:54 -0700111 }
112
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700113 public static final @android.annotation.NonNull Parcelable.Creator<RadioAccessSpecifier> CREATOR =
yinxufdfb6f42017-04-12 16:09:54 -0700114 new Parcelable.Creator<RadioAccessSpecifier> (){
115 @Override
116 public RadioAccessSpecifier createFromParcel(Parcel in) {
117 return new RadioAccessSpecifier(in);
118 }
119
120 @Override
121 public RadioAccessSpecifier[] newArray(int size) {
122 return new RadioAccessSpecifier[size];
123 }
124 };
125
126 @Override
127 public int describeContents() {
128 return 0;
129 }
130
131 @Override
132 public void writeToParcel(Parcel dest, int flags) {
yinxubbc3d362017-11-30 14:58:36 -0800133 dest.writeInt(mRadioAccessNetwork);
134 dest.writeIntArray(mBands);
135 dest.writeIntArray(mChannels);
yinxufdfb6f42017-04-12 16:09:54 -0700136 }
137
138 private RadioAccessSpecifier(Parcel in) {
yinxubbc3d362017-11-30 14:58:36 -0800139 mRadioAccessNetwork = in.readInt();
140 mBands = in.createIntArray();
141 mChannels = in.createIntArray();
yinxufdfb6f42017-04-12 16:09:54 -0700142 }
143
144 @Override
145 public boolean equals (Object o) {
146 RadioAccessSpecifier ras;
147
148 try {
149 ras = (RadioAccessSpecifier) o;
150 } catch (ClassCastException ex) {
151 return false;
152 }
153
154 if (o == null) {
155 return false;
156 }
157
yinxubbc3d362017-11-30 14:58:36 -0800158 return (mRadioAccessNetwork == ras.mRadioAccessNetwork
159 && Arrays.equals(mBands, ras.mBands)
160 && Arrays.equals(mChannels, ras.mChannels));
yinxufdfb6f42017-04-12 16:09:54 -0700161 }
162
163 @Override
164 public int hashCode () {
yinxubbc3d362017-11-30 14:58:36 -0800165 return ((mRadioAccessNetwork * 31)
166 + (Arrays.hashCode(mBands) * 37)
167 + (Arrays.hashCode(mChannels)) * 39);
yinxufdfb6f42017-04-12 16:09:54 -0700168 }
169}