Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.telephony; |
| 18 | |
Sooraj Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | import java.util.ArrayList; |
| 24 | import java.util.Arrays; |
| 25 | import java.util.List; |
| 26 | import java.util.Objects; |
| 27 | |
| 28 | /** |
| 29 | * Defines available network information which includes corresponding subscription id, |
Sooraj Sasindran | 4c91deb | 2019-03-22 15:14:12 -0700 | [diff] [blame] | 30 | * network plmns and corresponding priority to be used for network selection by Opportunistic |
| 31 | * Network Service when passed through {@link TelephonyManager#updateAvailableNetworks} |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 32 | */ |
| 33 | public 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 Sasindran | 4c91deb | 2019-03-22 15:14:12 -0700 | [diff] [blame] | 58 | * 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 Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 63 | */ |
| 64 | private int mPriority; |
| 65 | |
| 66 | /** |
| 67 | * Describes the List of PLMN ids (MCC-MNC) associated with mSubId. |
Sooraj Sasindran | 4c91deb | 2019-03-22 15:14:12 -0700 | [diff] [blame] | 68 | * 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 Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 71 | */ |
| 72 | private ArrayList<String> mMccMncs; |
| 73 | |
| 74 | /** |
Sooraj Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 75 | * Returns the frequency bands associated with the {@link #getMccMncs() MCC/MNCs}. |
| 76 | * Opportunistic network service will use these bands to scan. |
| 77 | * |
Sooraj Sasindran | 4c91deb | 2019-03-22 15:14:12 -0700 | [diff] [blame] | 78 | * 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 Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 80 | * |
| 81 | * See {@link AccessNetworkConstants} for details. |
| 82 | */ |
| 83 | private ArrayList<Integer> mBands; |
| 84 | |
| 85 | /** |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 86 | * 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 Sasindran | 4c91deb | 2019-03-22 15:14:12 -0700 | [diff] [blame] | 96 | * 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 Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 102 | * @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 Sasindran | 4c91deb | 2019-03-22 15:14:12 -0700 | [diff] [blame] | 110 | * 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 Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 113 | * @return list of PLMN ids |
| 114 | */ |
Sooraj Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 115 | public @NonNull List<String> getMccMncs() { |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 116 | return (List<String>) mMccMncs.clone(); |
| 117 | } |
| 118 | |
Sooraj Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 119 | /** |
| 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 Sasindran | 4c91deb | 2019-03-22 15:14:12 -0700 | [diff] [blame] | 124 | * 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 Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 127 | */ |
| 128 | public @NonNull List<Integer> getBands() { |
| 129 | return (List<Integer>) mBands.clone(); |
| 130 | } |
| 131 | |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 132 | @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 Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 142 | dest.writeList(mBands); |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | private AvailableNetworkInfo(Parcel in) { |
| 146 | mSubId = in.readInt(); |
| 147 | mPriority = in.readInt(); |
Sooraj Sasindran | 760a240 | 2019-01-15 14:53:52 -0800 | [diff] [blame] | 148 | mMccMncs = new ArrayList<>(); |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 149 | in.readStringList(mMccMncs); |
Sooraj Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 150 | mBands = new ArrayList<>(); |
| 151 | in.readList(mBands, Integer.class.getClassLoader()); |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Sooraj Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 154 | public AvailableNetworkInfo(int subId, int priority, @NonNull List<String> mccMncs, |
| 155 | @NonNull List<Integer> bands) { |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 156 | mSubId = subId; |
| 157 | mPriority = priority; |
| 158 | mMccMncs = new ArrayList<String>(mccMncs); |
Sooraj Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 159 | mBands = new ArrayList<Integer>(bands); |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 160 | } |
| 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 Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 177 | && mPriority == ani.mPriority |
| 178 | && (((mMccMncs != null) |
| 179 | && mMccMncs.equals(ani.mMccMncs))) |
| 180 | && mBands.equals(ani.mBands)); |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public int hashCode() { |
Sooraj Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 185 | return Objects.hash(mSubId, mPriority, mMccMncs, mBands); |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 188 | public static final @android.annotation.NonNull Parcelable.Creator<AvailableNetworkInfo> CREATOR = |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 189 | 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 Sasindran | 40e6f90 | 2019-03-07 15:52:59 -0800 | [diff] [blame] | 204 | + " mSubId: " + mSubId |
| 205 | + " mPriority: " + mPriority |
| 206 | + " mMccMncs: " + Arrays.toString(mMccMncs.toArray()) |
| 207 | + " mBands: " + Arrays.toString(mBands.toArray())); |
Sooraj Sasindran | a3ab858 | 2018-10-30 09:42:53 -0700 | [diff] [blame] | 208 | } |
| 209 | } |