blob: a1c5bbefbbe15e82d6e38d23543ec2e63031540a [file] [log] [blame]
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -07001/*
2 * Copyright (C) 2018 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
Sooraj Sasindran40e6f902019-03-07 15:52:59 -080019import android.annotation.NonNull;
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -070020import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.util.ArrayList;
24import java.util.Arrays;
25import java.util.List;
26import java.util.Objects;
27
28/**
29 * Defines available network information which includes corresponding subscription id,
Sooraj Sasindran4c91deb2019-03-22 15:14:12 -070030 * network plmns and corresponding priority to be used for network selection by Opportunistic
31 * Network Service when passed through {@link TelephonyManager#updateAvailableNetworks}
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -070032 */
33public final class AvailableNetworkInfo implements Parcelable {
34
35 /*
36 * Defines number of priority level high.
37 */
38 public static final int PRIORITY_HIGH = 1;
39
40 /*
41 * Defines number of priority level medium.
42 */
43 public static final int PRIORITY_MED = 2;
44
45 /*
46 * Defines number of priority level low.
47 */
48 public static final int PRIORITY_LOW = 3;
49
50 /**
51 * subscription Id of the available network. This value must be one of the entry retrieved from
52 * {@link SubscriptionManager#getOpportunisticSubscriptions}
53 */
54 private int mSubId;
55
56 /**
57 * Priority for the subscription id.
Sooraj Sasindran4c91deb2019-03-22 15:14:12 -070058 * Priorities are in the range of {@link AvailableNetworkInfo#PRIORITY_LOW} to
59 * {@link AvailableNetworkInfo#PRIORITY_HIGH}
60 * Among all networks available after network scan, subId with highest priority is chosen
61 * for network selection. If there are more than one subId with highest priority then the
62 * network with highest RSRP is chosen.
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -070063 */
64 private int mPriority;
65
66 /**
67 * Describes the List of PLMN ids (MCC-MNC) associated with mSubId.
Sooraj Sasindran4c91deb2019-03-22 15:14:12 -070068 * Opportunistic Network Service will scan and verify specified PLMNs are available.
69 * If this entry is left empty, then the Opportunistic Network Service will not scan the network
70 * to validate the network availability.
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -070071 */
72 private ArrayList<String> mMccMncs;
73
74 /**
Sooraj Sasindran40e6f902019-03-07 15:52:59 -080075 * Returns the frequency bands associated with the {@link #getMccMncs() MCC/MNCs}.
76 * Opportunistic network service will use these bands to scan.
77 *
Sooraj Sasindran4c91deb2019-03-22 15:14:12 -070078 * When no specific bands are specified (empty array or null) CBRS band
79 * {@link AccessNetworkConstants.EutranBand.BAND_48} will be used for network scan.
Sooraj Sasindran40e6f902019-03-07 15:52:59 -080080 *
81 * See {@link AccessNetworkConstants} for details.
82 */
83 private ArrayList<Integer> mBands;
84
85 /**
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -070086 * Return subscription Id of the available network.
87 * This value must be one of the entry retrieved from
88 * {@link SubscriptionManager#getOpportunisticSubscriptions}
89 * @return subscription id
90 */
91 public int getSubId() {
92 return mSubId;
93 }
94
95 /**
Sooraj Sasindran4c91deb2019-03-22 15:14:12 -070096 * Return priority for the subscription id.
97 * Priorities are in the range of {@link AvailableNetworkInfo#PRIORITY_LOW} to
98 * {@link AvailableNetworkInfo#PRIORITY_HIGH}
99 * Among all networks available after network scan, subId with highest priority is chosen
100 * for network selection. If there are more than one subId with highest priority then the
101 * network with highest RSRP is chosen.
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700102 * @return priority level
103 */
104 public int getPriority() {
105 return mPriority;
106 }
107
108 /**
109 * Return List of PLMN ids (MCC-MNC) associated with the sub ID.
Sooraj Sasindran4c91deb2019-03-22 15:14:12 -0700110 * Opportunistic Network Service will scan and verify specified PLMNs are available.
111 * If this entry is left empty, then the Opportunistic Network Service will not scan the network
112 * to validate the network availability.
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700113 * @return list of PLMN ids
114 */
Sooraj Sasindran40e6f902019-03-07 15:52:59 -0800115 public @NonNull List<String> getMccMncs() {
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700116 return (List<String>) mMccMncs.clone();
117 }
118
Sooraj Sasindran40e6f902019-03-07 15:52:59 -0800119 /**
120 * Returns the frequency bands that need to be scanned by opportunistic network service
121 *
122 * The returned value is defined in either of {@link AccessNetworkConstants.GeranBand},
123 * {@link AccessNetworkConstants.UtranBand} and {@link AccessNetworkConstants.EutranBand}
Sooraj Sasindran4c91deb2019-03-22 15:14:12 -0700124 * See {@link AccessNetworkConstants.AccessNetworkType} for details regarding different network
125 * types. When no specific bands are specified (empty array or null) CBRS band
126 * {@link AccessNetworkConstants.EutranBand#BAND_48} will be used for network scan.
Sooraj Sasindran40e6f902019-03-07 15:52:59 -0800127 */
128 public @NonNull List<Integer> getBands() {
129 return (List<Integer>) mBands.clone();
130 }
131
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700132 @Override
133 public int describeContents() {
134 return 0;
135 }
136
137 @Override
138 public void writeToParcel(Parcel dest, int flags) {
139 dest.writeInt(mSubId);
140 dest.writeInt(mPriority);
141 dest.writeStringList(mMccMncs);
Sooraj Sasindran40e6f902019-03-07 15:52:59 -0800142 dest.writeList(mBands);
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700143 }
144
145 private AvailableNetworkInfo(Parcel in) {
146 mSubId = in.readInt();
147 mPriority = in.readInt();
Sooraj Sasindran760a2402019-01-15 14:53:52 -0800148 mMccMncs = new ArrayList<>();
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700149 in.readStringList(mMccMncs);
Sooraj Sasindran40e6f902019-03-07 15:52:59 -0800150 mBands = new ArrayList<>();
151 in.readList(mBands, Integer.class.getClassLoader());
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700152 }
153
Sooraj Sasindran40e6f902019-03-07 15:52:59 -0800154 public AvailableNetworkInfo(int subId, int priority, @NonNull List<String> mccMncs,
155 @NonNull List<Integer> bands) {
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700156 mSubId = subId;
157 mPriority = priority;
158 mMccMncs = new ArrayList<String>(mccMncs);
Sooraj Sasindran40e6f902019-03-07 15:52:59 -0800159 mBands = new ArrayList<Integer>(bands);
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700160 }
161
162 @Override
163 public boolean equals(Object o) {
164 AvailableNetworkInfo ani;
165
166 try {
167 ani = (AvailableNetworkInfo) o;
168 } catch (ClassCastException ex) {
169 return false;
170 }
171
172 if (o == null) {
173 return false;
174 }
175
176 return (mSubId == ani.mSubId
Sooraj Sasindran40e6f902019-03-07 15:52:59 -0800177 && mPriority == ani.mPriority
178 && (((mMccMncs != null)
179 && mMccMncs.equals(ani.mMccMncs)))
180 && mBands.equals(ani.mBands));
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700181 }
182
183 @Override
184 public int hashCode() {
Sooraj Sasindran40e6f902019-03-07 15:52:59 -0800185 return Objects.hash(mSubId, mPriority, mMccMncs, mBands);
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700186 }
187
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700188 public static final @android.annotation.NonNull Parcelable.Creator<AvailableNetworkInfo> CREATOR =
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700189 new Creator<AvailableNetworkInfo>() {
190 @Override
191 public AvailableNetworkInfo createFromParcel(Parcel in) {
192 return new AvailableNetworkInfo(in);
193 }
194
195 @Override
196 public AvailableNetworkInfo[] newArray(int size) {
197 return new AvailableNetworkInfo[size];
198 }
199 };
200
201 @Override
202 public String toString() {
203 return ("AvailableNetworkInfo:"
Sooraj Sasindran40e6f902019-03-07 15:52:59 -0800204 + " mSubId: " + mSubId
205 + " mPriority: " + mPriority
206 + " mMccMncs: " + Arrays.toString(mMccMncs.toArray())
207 + " mBands: " + Arrays.toString(mBands.toArray()));
Sooraj Sasindrana3ab8582018-10-30 09:42:53 -0700208 }
209}