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 19 import android.annotation.IntDef; 20 import android.annotation.IntRange; 21 import android.annotation.NonNull; 22 import android.annotation.SystemApi; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.RetentionPolicy; 28 import java.util.ArrayList; 29 import java.util.Arrays; 30 import java.util.List; 31 import java.util.Objects; 32 33 /** 34 * Phone capability which describes the data connection capability of modem. 35 * It's used to evaluate possible phone config change, for example from single 36 * SIM device to multi-SIM device. 37 * @hide 38 */ 39 @SystemApi 40 public final class PhoneCapability implements Parcelable { 41 // Hardcoded default DSDS capability. 42 /** @hide */ 43 public static final PhoneCapability DEFAULT_DSDS_CAPABILITY; 44 // Hardcoded default Single SIM single standby capability. 45 /** @hide */ 46 public static final PhoneCapability DEFAULT_SSSS_CAPABILITY; 47 48 /** @hide */ 49 @Retention(RetentionPolicy.SOURCE) 50 @IntDef(prefix = { "DEVICE_NR_CAPABILITY_" }, value = { 51 DEVICE_NR_CAPABILITY_NSA, 52 DEVICE_NR_CAPABILITY_SA, 53 }) 54 public @interface DeviceNrCapability {} 55 56 /** 57 * Indicates DEVICE_NR_CAPABILITY_NSA determine that the device enable the non-standalone 58 * (NSA) mode of 5G NR. 59 * @hide 60 */ 61 @SystemApi 62 public static final int DEVICE_NR_CAPABILITY_NSA = 1; 63 64 /** 65 * Indicates DEVICE_NR_CAPABILITY_SA determine that the device enable the standalone (SA) 66 * mode of 5G NR. 67 * @hide 68 */ 69 @SystemApi 70 public static final int DEVICE_NR_CAPABILITY_SA = 2; 71 72 static { 73 ModemInfo modemInfo1 = new ModemInfo(0, 0, true, true); 74 ModemInfo modemInfo2 = new ModemInfo(1, 0, true, true); 75 76 List<ModemInfo> logicalModemList = new ArrayList<>(); 77 logicalModemList.add(modemInfo1); 78 logicalModemList.add(modemInfo2); 79 int[] deviceNrCapabilities = new int[0]; 80 81 DEFAULT_DSDS_CAPABILITY = new PhoneCapability(1, 1, logicalModemList, false, 82 deviceNrCapabilities); 83 84 logicalModemList = new ArrayList<>(); 85 logicalModemList.add(modemInfo1); 86 DEFAULT_SSSS_CAPABILITY = new PhoneCapability(1, 1, logicalModemList, false, 87 deviceNrCapabilities); 88 } 89 90 /** 91 * mMaxActiveVoiceSubscriptions defines the maximum subscriptions that can support 92 * simultaneous voice calls. For a dual sim dual standby (DSDS) device it would be one, but 93 * for a dual sim dual active device it would be 2. 94 * 95 * @hide 96 */ 97 private final int mMaxActiveVoiceSubscriptions; 98 99 /** 100 * mMaxActiveDataSubscriptions defines the maximum subscriptions that can support 101 * simultaneous data connections. 102 * For example, for L+L device it should be 2. 103 * 104 * @hide 105 */ 106 private final int mMaxActiveDataSubscriptions; 107 108 /** 109 * Whether modem supports both internet PDN up so 110 * that we can do ping test before tearing down the 111 * other one. 112 * 113 * @hide 114 */ 115 private final boolean mNetworkValidationBeforeSwitchSupported; 116 117 /** @hide */ 118 private final List<ModemInfo> mLogicalModemList; 119 120 /** 121 * List of logical modem information. 122 * 123 * @hide 124 */ 125 private final int[] mDeviceNrCapabilities; 126 127 /** @hide */ PhoneCapability(int maxActiveVoiceSubscriptions, int maxActiveDataSubscriptions, List<ModemInfo> logicalModemList, boolean networkValidationBeforeSwitchSupported, int[] deviceNrCapabilities)128 public PhoneCapability(int maxActiveVoiceSubscriptions, int maxActiveDataSubscriptions, 129 List<ModemInfo> logicalModemList, boolean networkValidationBeforeSwitchSupported, 130 int[] deviceNrCapabilities) { 131 this.mMaxActiveVoiceSubscriptions = maxActiveVoiceSubscriptions; 132 this.mMaxActiveDataSubscriptions = maxActiveDataSubscriptions; 133 // Make sure it's not null. 134 this.mLogicalModemList = logicalModemList == null ? new ArrayList<>() : logicalModemList; 135 this.mNetworkValidationBeforeSwitchSupported = networkValidationBeforeSwitchSupported; 136 this.mDeviceNrCapabilities = deviceNrCapabilities; 137 } 138 139 @Override toString()140 public String toString() { 141 return "mMaxActiveVoiceSubscriptions=" + mMaxActiveVoiceSubscriptions 142 + " mMaxActiveDataSubscriptions=" + mMaxActiveDataSubscriptions 143 + " mNetworkValidationBeforeSwitchSupported=" 144 + mNetworkValidationBeforeSwitchSupported 145 + " mDeviceNrCapability " + Arrays.toString(mDeviceNrCapabilities); 146 } 147 PhoneCapability(Parcel in)148 private PhoneCapability(Parcel in) { 149 mMaxActiveVoiceSubscriptions = in.readInt(); 150 mMaxActiveDataSubscriptions = in.readInt(); 151 mNetworkValidationBeforeSwitchSupported = in.readBoolean(); 152 mLogicalModemList = new ArrayList<>(); 153 in.readList(mLogicalModemList, ModemInfo.class.getClassLoader()); 154 mDeviceNrCapabilities = in.createIntArray(); 155 } 156 157 @Override hashCode()158 public int hashCode() { 159 return Objects.hash(mMaxActiveVoiceSubscriptions, 160 mMaxActiveDataSubscriptions, 161 mLogicalModemList, 162 mNetworkValidationBeforeSwitchSupported, 163 Arrays.hashCode(mDeviceNrCapabilities)); 164 } 165 166 @Override equals(Object o)167 public boolean equals(Object o) { 168 if (o == null || !(o instanceof PhoneCapability) || hashCode() != o.hashCode()) { 169 return false; 170 } 171 172 if (this == o) { 173 return true; 174 } 175 176 PhoneCapability s = (PhoneCapability) o; 177 178 return (mMaxActiveVoiceSubscriptions == s.mMaxActiveVoiceSubscriptions 179 && mMaxActiveDataSubscriptions == s.mMaxActiveDataSubscriptions 180 && mNetworkValidationBeforeSwitchSupported 181 == s.mNetworkValidationBeforeSwitchSupported 182 && mLogicalModemList.equals(s.mLogicalModemList) 183 && Arrays.equals(mDeviceNrCapabilities, s.mDeviceNrCapabilities)); 184 } 185 186 /** 187 * {@link Parcelable#describeContents} 188 */ describeContents()189 public int describeContents() { 190 return 0; 191 } 192 193 /** 194 * {@link Parcelable#writeToParcel} 195 */ writeToParcel(@onNull Parcel dest, @Parcelable.WriteFlags int flags)196 public void writeToParcel(@NonNull Parcel dest, @Parcelable.WriteFlags int flags) { 197 dest.writeInt(mMaxActiveVoiceSubscriptions); 198 dest.writeInt(mMaxActiveDataSubscriptions); 199 dest.writeBoolean(mNetworkValidationBeforeSwitchSupported); 200 dest.writeList(mLogicalModemList); 201 dest.writeIntArray(mDeviceNrCapabilities); 202 } 203 204 public static final @android.annotation.NonNull Parcelable.Creator<PhoneCapability> CREATOR = 205 new Parcelable.Creator() { 206 public PhoneCapability createFromParcel(Parcel in) { 207 return new PhoneCapability(in); 208 } 209 210 public PhoneCapability[] newArray(int size) { 211 return new PhoneCapability[size]; 212 } 213 }; 214 215 /** 216 * @return the maximum subscriptions that can support simultaneous voice calls. For a dual 217 * sim dual standby (DSDS) device it would be one, but for a dual sim dual active device it 218 * would be 2. 219 * @hide 220 */ 221 @SystemApi getMaxActiveVoiceSubscriptions()222 public @IntRange(from = 1) int getMaxActiveVoiceSubscriptions() { 223 return mMaxActiveVoiceSubscriptions; 224 } 225 226 /** 227 * @return the maximum subscriptions that can support simultaneous data connections. 228 * For example, for L+L device it should be 2. 229 * @hide 230 */ 231 @SystemApi getMaxActiveDataSubscriptions()232 public @IntRange(from = 1) int getMaxActiveDataSubscriptions() { 233 return mMaxActiveDataSubscriptions; 234 } 235 236 /** 237 * @return Check whether the Citizens Broadband Radio Service(CBRS) network validation before 238 * CBRS switch is supported or not. 239 * 240 * @hide 241 */ isNetworkValidationBeforeSwitchSupported()242 public boolean isNetworkValidationBeforeSwitchSupported() { 243 return mNetworkValidationBeforeSwitchSupported; 244 } 245 246 /** 247 * @return The list of logical modem information. 248 * @hide 249 */ getLogicalModemList()250 public List<ModemInfo> getLogicalModemList() { 251 return mLogicalModemList; 252 } 253 254 /** 255 * Return List of the device's NR capability. If the device doesn't support NR capability, 256 * then this api return empty array. 257 * @see DEVICE_NR_CAPABILITY_NSA 258 * @see DEVICE_NR_CAPABILITY_SA 259 * 260 * @return List of the device's NR capability. 261 * @hide 262 */ 263 @SystemApi getDeviceNrCapabilities()264 public @NonNull @DeviceNrCapability int[] getDeviceNrCapabilities() { 265 return mDeviceNrCapabilities == null ? (new int[0]) : mDeviceNrCapabilities; 266 } 267 } 268