1 /* 2 * Copyright (C) 2015 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 com.android.internal.telephony; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.app.BroadcastOptions; 22 import android.compat.annotation.UnsupportedAppUsage; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.content.SharedPreferences; 26 import android.content.res.Configuration; 27 import android.net.LinkProperties; 28 import android.net.NetworkCapabilities; 29 import android.net.Uri; 30 import android.os.AsyncResult; 31 import android.os.Build; 32 import android.os.Handler; 33 import android.os.Looper; 34 import android.os.Message; 35 import android.os.PersistableBundle; 36 import android.os.Registrant; 37 import android.os.RegistrantList; 38 import android.os.SystemClock; 39 import android.os.SystemProperties; 40 import android.os.WorkSource; 41 import android.preference.PreferenceManager; 42 import android.sysprop.TelephonyProperties; 43 import android.telecom.VideoProfile; 44 import android.telephony.AccessNetworkConstants; 45 import android.telephony.Annotation.ApnType; 46 import android.telephony.CarrierConfigManager; 47 import android.telephony.CarrierRestrictionRules; 48 import android.telephony.CellIdentity; 49 import android.telephony.CellInfo; 50 import android.telephony.ClientRequestStats; 51 import android.telephony.ImsiEncryptionInfo; 52 import android.telephony.LinkCapacityEstimate; 53 import android.telephony.PhoneStateListener; 54 import android.telephony.PhysicalChannelConfig; 55 import android.telephony.PreciseDataConnectionState; 56 import android.telephony.RadioAccessFamily; 57 import android.telephony.RadioAccessSpecifier; 58 import android.telephony.ServiceState; 59 import android.telephony.SignalStrength; 60 import android.telephony.SubscriptionManager; 61 import android.telephony.TelephonyDisplayInfo; 62 import android.telephony.TelephonyManager; 63 import android.telephony.data.ApnSetting; 64 import android.telephony.emergency.EmergencyNumber; 65 import android.telephony.ims.RegistrationManager; 66 import android.telephony.ims.stub.ImsRegistrationImplBase; 67 import android.text.TextUtils; 68 import android.util.LocalLog; 69 import android.util.SparseArray; 70 import android.util.Xml; 71 72 import com.android.ims.ImsCall; 73 import com.android.ims.ImsConfig; 74 import com.android.ims.ImsException; 75 import com.android.ims.ImsManager; 76 import com.android.internal.R; 77 import com.android.internal.annotations.VisibleForTesting; 78 import com.android.internal.telephony.dataconnection.DataConnectionReasons; 79 import com.android.internal.telephony.dataconnection.DataEnabledSettings; 80 import com.android.internal.telephony.dataconnection.DcTracker; 81 import com.android.internal.telephony.dataconnection.LinkBandwidthEstimator; 82 import com.android.internal.telephony.dataconnection.TransportManager; 83 import com.android.internal.telephony.emergency.EmergencyNumberTracker; 84 import com.android.internal.telephony.imsphone.ImsPhone; 85 import com.android.internal.telephony.imsphone.ImsPhoneCall; 86 import com.android.internal.telephony.metrics.SmsStats; 87 import com.android.internal.telephony.metrics.VoiceCallSessionStats; 88 import com.android.internal.telephony.test.SimulatedRadioControl; 89 import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; 90 import com.android.internal.telephony.uicc.IccFileHandler; 91 import com.android.internal.telephony.uicc.IccRecords; 92 import com.android.internal.telephony.uicc.IsimRecords; 93 import com.android.internal.telephony.uicc.UiccCard; 94 import com.android.internal.telephony.uicc.UiccCardApplication; 95 import com.android.internal.telephony.uicc.UiccController; 96 import com.android.internal.telephony.uicc.UsimServiceTable; 97 import com.android.internal.telephony.util.TelephonyUtils; 98 import com.android.internal.util.XmlUtils; 99 import com.android.telephony.Rlog; 100 101 import org.xmlpull.v1.XmlPullParser; 102 import org.xmlpull.v1.XmlPullParserException; 103 104 import java.io.File; 105 import java.io.FileDescriptor; 106 import java.io.FileNotFoundException; 107 import java.io.FileReader; 108 import java.io.IOException; 109 import java.io.PrintWriter; 110 import java.util.ArrayList; 111 import java.util.Arrays; 112 import java.util.Collections; 113 import java.util.HashMap; 114 import java.util.HashSet; 115 import java.util.List; 116 import java.util.Locale; 117 import java.util.Map; 118 import java.util.Set; 119 import java.util.concurrent.atomic.AtomicReference; 120 import java.util.function.Consumer; 121 import java.util.stream.Collectors; 122 123 /** 124 * (<em>Not for SDK use</em>) 125 * A base implementation for the com.android.internal.telephony.Phone interface. 126 * 127 * Note that implementations of Phone.java are expected to be used 128 * from a single application thread. This should be the same thread that 129 * originally called PhoneFactory to obtain the interface. 130 * 131 * {@hide} 132 * 133 */ 134 135 public abstract class Phone extends Handler implements PhoneInternalInterface { 136 private static final String LOG_TAG = "Phone"; 137 138 protected final static Object lockForRadioTechnologyChange = new Object(); 139 140 protected final int USSD_MAX_QUEUE = 10; 141 142 // Key used to read and write the saved network selection numeric value 143 public static final String NETWORK_SELECTION_KEY = "network_selection_key"; 144 // Key used to read and write the saved network selection operator name 145 public static final String NETWORK_SELECTION_NAME_KEY = "network_selection_name_key"; 146 // Key used to read and write the saved network selection operator short name 147 public static final String NETWORK_SELECTION_SHORT_KEY = "network_selection_short_key"; 148 149 150 // Key used to read/write "disable data connection on boot" pref (used for testing) 151 public static final String DATA_DISABLED_ON_BOOT_KEY = "disabled_on_boot_key"; 152 153 // Key used to read/write data_roaming_is_user_setting pref 154 public static final String DATA_ROAMING_IS_USER_SETTING_KEY = 155 "data_roaming_is_user_setting_key"; 156 157 // Default value when there has been no last emergency SMS time recorded yet. 158 private static final int EMERGENCY_SMS_NO_TIME_RECORDED = -1; 159 // The max timer value that the platform can be in emergency SMS mode (5 minutes). 160 private static final int EMERGENCY_SMS_TIMER_MAX_MS = 300000; 161 162 /* Event Constants */ 163 protected static final int EVENT_RADIO_AVAILABLE = 1; 164 /** Supplementary Service Notification received. */ 165 protected static final int EVENT_SSN = 2; 166 protected static final int EVENT_SIM_RECORDS_LOADED = 3; 167 private static final int EVENT_MMI_DONE = 4; 168 protected static final int EVENT_RADIO_ON = 5; 169 protected static final int EVENT_GET_BASEBAND_VERSION_DONE = 6; 170 protected static final int EVENT_USSD = 7; 171 protected static final int EVENT_RADIO_OFF_OR_NOT_AVAILABLE = 8; 172 protected static final int EVENT_GET_IMEI_DONE = 9; 173 protected static final int EVENT_GET_IMEISV_DONE = 10; 174 private static final int EVENT_GET_SIM_STATUS_DONE = 11; 175 protected static final int EVENT_SET_CALL_FORWARD_DONE = 12; 176 protected static final int EVENT_GET_CALL_FORWARD_DONE = 13; 177 protected static final int EVENT_CALL_RING = 14; 178 private static final int EVENT_CALL_RING_CONTINUE = 15; 179 180 // Used to intercept the carrier selection calls so that 181 // we can save the values. 182 private static final int EVENT_SET_NETWORK_MANUAL_COMPLETE = 16; 183 private static final int EVENT_SET_NETWORK_AUTOMATIC_COMPLETE = 17; 184 protected static final int EVENT_SET_CLIR_COMPLETE = 18; 185 protected static final int EVENT_REGISTERED_TO_NETWORK = 19; 186 protected static final int EVENT_SET_VM_NUMBER_DONE = 20; 187 // Events for CDMA support 188 protected static final int EVENT_GET_DEVICE_IDENTITY_DONE = 21; 189 protected static final int EVENT_RUIM_RECORDS_LOADED = 22; 190 protected static final int EVENT_NV_READY = 23; 191 private static final int EVENT_SET_ENHANCED_VP = 24; 192 @VisibleForTesting 193 public static final int EVENT_EMERGENCY_CALLBACK_MODE_ENTER = 25; 194 protected static final int EVENT_EXIT_EMERGENCY_CALLBACK_RESPONSE = 26; 195 protected static final int EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED = 27; 196 // other 197 protected static final int EVENT_SET_NETWORK_AUTOMATIC = 28; 198 protected static final int EVENT_ICC_RECORD_EVENTS = 29; 199 @VisibleForTesting 200 protected static final int EVENT_ICC_CHANGED = 30; 201 // Single Radio Voice Call Continuity 202 @VisibleForTesting 203 protected static final int EVENT_SRVCC_STATE_CHANGED = 31; 204 private static final int EVENT_INITIATE_SILENT_REDIAL = 32; 205 private static final int EVENT_RADIO_NOT_AVAILABLE = 33; 206 private static final int EVENT_UNSOL_OEM_HOOK_RAW = 34; 207 protected static final int EVENT_GET_RADIO_CAPABILITY = 35; 208 protected static final int EVENT_SS = 36; 209 private static final int EVENT_CONFIG_LCE = 37; 210 private static final int EVENT_CHECK_FOR_NETWORK_AUTOMATIC = 38; 211 protected static final int EVENT_VOICE_RADIO_TECH_CHANGED = 39; 212 protected static final int EVENT_REQUEST_VOICE_RADIO_TECH_DONE = 40; 213 protected static final int EVENT_RIL_CONNECTED = 41; 214 protected static final int EVENT_UPDATE_PHONE_OBJECT = 42; 215 protected static final int EVENT_CARRIER_CONFIG_CHANGED = 43; 216 // Carrier's CDMA prefer mode setting 217 protected static final int EVENT_SET_ROAMING_PREFERENCE_DONE = 44; 218 protected static final int EVENT_MODEM_RESET = 45; 219 protected static final int EVENT_VRS_OR_RAT_CHANGED = 46; 220 // Radio state change 221 protected static final int EVENT_RADIO_STATE_CHANGED = 47; 222 protected static final int EVENT_SET_CARRIER_DATA_ENABLED = 48; 223 protected static final int EVENT_DEVICE_PROVISIONED_CHANGE = 49; 224 protected static final int EVENT_DEVICE_PROVISIONING_DATA_SETTING_CHANGE = 50; 225 protected static final int EVENT_GET_AVAILABLE_NETWORKS_DONE = 51; 226 227 private static final int EVENT_ALL_DATA_DISCONNECTED = 52; 228 protected static final int EVENT_UICC_APPS_ENABLEMENT_STATUS_CHANGED = 53; 229 protected static final int EVENT_UICC_APPS_ENABLEMENT_SETTING_CHANGED = 54; 230 protected static final int EVENT_GET_UICC_APPS_ENABLEMENT_DONE = 55; 231 protected static final int EVENT_REAPPLY_UICC_APPS_ENABLEMENT_DONE = 56; 232 protected static final int EVENT_REGISTRATION_FAILED = 57; 233 protected static final int EVENT_BARRING_INFO_CHANGED = 58; 234 protected static final int EVENT_LINK_CAPACITY_CHANGED = 59; 235 protected static final int EVENT_RESET_CARRIER_KEY_IMSI_ENCRYPTION = 60; 236 protected static final int EVENT_SET_VONR_ENABLED_DONE = 61; 237 238 protected static final int EVENT_LAST = EVENT_SET_VONR_ENABLED_DONE; 239 240 // For shared prefs. 241 private static final String GSM_ROAMING_LIST_OVERRIDE_PREFIX = "gsm_roaming_list_"; 242 private static final String GSM_NON_ROAMING_LIST_OVERRIDE_PREFIX = "gsm_non_roaming_list_"; 243 private static final String CDMA_ROAMING_LIST_OVERRIDE_PREFIX = "cdma_roaming_list_"; 244 private static final String CDMA_NON_ROAMING_LIST_OVERRIDE_PREFIX = "cdma_non_roaming_list_"; 245 246 // Key used to read/write current CLIR setting 247 public static final String CLIR_KEY = "clir_sub_key"; 248 249 // Key used for storing voice mail count 250 private static final String VM_COUNT = "vm_count_key"; 251 // Key used to read/write the ID for storing the voice mail 252 private static final String VM_ID = "vm_id_key"; 253 254 // Key used for storing call forwarding status 255 public static final String CF_STATUS = "cf_status_key"; 256 // Key used to read/write the ID for storing the call forwarding status 257 public static final String CF_ID = "cf_id_key"; 258 259 // Key used to read/write "disable DNS server check" pref (used for testing) 260 private static final String DNS_SERVER_CHECK_DISABLED_KEY = "dns_server_check_disabled_key"; 261 262 // Integer used to let the calling application know that the we are ignoring auto mode switch. 263 private static final int ALREADY_IN_AUTO_SELECTION = 1; 264 265 /** 266 * This method is invoked when the Phone exits Emergency Callback Mode. 267 */ handleExitEmergencyCallbackMode()268 protected void handleExitEmergencyCallbackMode() { 269 } 270 271 /** 272 * Small container class used to hold information relevant to 273 * the carrier selection process. operatorNumeric can be "" 274 * if we are looking for automatic selection. operatorAlphaLong is the 275 * corresponding operator name. 276 */ 277 protected static class NetworkSelectMessage { 278 public Message message; 279 public String operatorNumeric; 280 public String operatorAlphaLong; 281 public String operatorAlphaShort; 282 } 283 284 public static class SilentRedialParam { 285 public String dialString; 286 public int causeCode; 287 public DialArgs dialArgs; 288 SilentRedialParam(String dialString, int causeCode, DialArgs dialArgs)289 public SilentRedialParam(String dialString, int causeCode, DialArgs dialArgs) { 290 this.dialString = dialString; 291 this.causeCode = causeCode; 292 this.dialArgs = dialArgs; 293 } 294 } 295 296 /* Instance Variables */ 297 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 298 public CommandsInterface mCi; 299 protected int mVmCount = 0; 300 private boolean mDnsCheckDisabled; 301 // Data connection trackers. For each transport type (e.g. WWAN, WLAN), there will be a 302 // corresponding DcTracker. The WWAN DcTracker is for cellular data connections while 303 // WLAN DcTracker is for IWLAN data connection. For IWLAN legacy mode, only one (WWAN) DcTracker 304 // will be created. 305 protected final SparseArray<DcTracker> mDcTrackers = new SparseArray<>(); 306 /* Used for dispatching signals to configured carrier apps */ 307 protected CarrierSignalAgent mCarrierSignalAgent; 308 /* Used for dispatching carrier action from carrier apps */ 309 protected CarrierActionAgent mCarrierActionAgent; 310 private boolean mDoesRilSendMultipleCallRing; 311 private int mCallRingContinueToken; 312 private int mCallRingDelay; 313 private boolean mIsVoiceCapable = true; 314 private final AppSmsManager mAppSmsManager; 315 private SimActivationTracker mSimActivationTracker; 316 // Keep track of whether or not the phone is in Emergency Callback Mode for Phone and 317 // subclasses 318 protected boolean mIsPhoneInEcmState = false; 319 // Keep track of the case where ECM was cancelled to place another outgoing emergency call. 320 // We will need to restart it after the emergency call ends. 321 protected boolean mEcmCanceledForEmergency = false; 322 private volatile long mTimeLastEmergencySmsSentMs = EMERGENCY_SMS_NO_TIME_RECORDED; 323 324 // Variable to cache the video capability. When RAT changes, we lose this info and are unable 325 // to recover from the state. We cache it and notify listeners when they register. 326 protected boolean mIsVideoCapable = false; 327 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 328 protected UiccController mUiccController = null; 329 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 330 protected final AtomicReference<IccRecords> mIccRecords = new AtomicReference<IccRecords>(); 331 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 332 public SmsStorageMonitor mSmsStorageMonitor; 333 public SmsUsageMonitor mSmsUsageMonitor; 334 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 335 protected AtomicReference<UiccCardApplication> mUiccApplication = 336 new AtomicReference<UiccCardApplication>(); 337 TelephonyTester mTelephonyTester; 338 private String mName; 339 private final String mActionDetached; 340 private final String mActionAttached; 341 protected DeviceStateMonitor mDeviceStateMonitor; 342 protected DisplayInfoController mDisplayInfoController; 343 protected TransportManager mTransportManager; 344 protected DataEnabledSettings mDataEnabledSettings; 345 // Used for identify the carrier of current subscription 346 protected CarrierResolver mCarrierResolver; 347 348 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 349 protected int mPhoneId; 350 351 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 352 protected Phone mImsPhone = null; 353 354 private final AtomicReference<RadioCapability> mRadioCapability = 355 new AtomicReference<RadioCapability>(); 356 357 private static final int DEFAULT_REPORT_INTERVAL_MS = 200; 358 private static final boolean LCE_PULL_MODE = true; 359 private int mLceStatus = RILConstants.LCE_NOT_AVAILABLE; 360 protected TelephonyComponentFactory mTelephonyComponentFactory; 361 362 //IMS 363 /** 364 * {@link CallStateException} message text used to indicate that an IMS call has failed because 365 * it needs to be retried using GSM or CDMA (e.g. CS fallback). 366 * TODO: Replace this with a proper exception; {@link CallStateException} doesn't make sense. 367 */ 368 public static final String CS_FALLBACK = "cs_fallback"; 369 370 // Used for retry over cs for supplementary services 371 public static final String CS_FALLBACK_SS = "cs_fallback_ss"; 372 373 /** 374 * @deprecated Use {@link android.telephony.ims.ImsManager#EXTRA_WFC_REGISTRATION_FAILURE_TITLE} 375 * instead. 376 */ 377 @Deprecated 378 public static final String EXTRA_KEY_ALERT_TITLE = 379 android.telephony.ims.ImsManager.EXTRA_WFC_REGISTRATION_FAILURE_TITLE; 380 /** 381 * @deprecated Use 382 * {@link android.telephony.ims.ImsManager#EXTRA_WFC_REGISTRATION_FAILURE_MESSAGE} instead. 383 */ 384 @Deprecated 385 public static final String EXTRA_KEY_ALERT_MESSAGE = 386 android.telephony.ims.ImsManager.EXTRA_WFC_REGISTRATION_FAILURE_MESSAGE; 387 public static final String EXTRA_KEY_ALERT_SHOW = "alertShow"; 388 public static final String EXTRA_KEY_NOTIFICATION_MESSAGE = "notificationMessage"; 389 390 private final RegistrantList mPreciseCallStateRegistrants = new RegistrantList(); 391 392 private final RegistrantList mHandoverRegistrants = new RegistrantList(); 393 394 private final RegistrantList mNewRingingConnectionRegistrants = new RegistrantList(); 395 396 private final RegistrantList mIncomingRingRegistrants = new RegistrantList(); 397 398 protected final RegistrantList mDisconnectRegistrants = new RegistrantList(); 399 400 private final RegistrantList mServiceStateRegistrants = new RegistrantList(); 401 402 protected final RegistrantList mMmiCompleteRegistrants = new RegistrantList(); 403 404 @UnsupportedAppUsage 405 protected final RegistrantList mMmiRegistrants = new RegistrantList(); 406 407 protected final RegistrantList mUnknownConnectionRegistrants = new RegistrantList(); 408 409 protected final RegistrantList mSuppServiceFailedRegistrants = new RegistrantList(); 410 411 protected final RegistrantList mRadioOffOrNotAvailableRegistrants = new RegistrantList(); 412 413 protected final RegistrantList mSimRecordsLoadedRegistrants = new RegistrantList(); 414 415 private final RegistrantList mVideoCapabilityChangedRegistrants = new RegistrantList(); 416 417 protected final RegistrantList mEmergencyCallToggledRegistrants = new RegistrantList(); 418 419 private final RegistrantList mAllDataDisconnectedRegistrants = new RegistrantList(); 420 421 private final RegistrantList mCellInfoRegistrants = new RegistrantList(); 422 423 private final RegistrantList mRedialRegistrants = new RegistrantList(); 424 425 private final RegistrantList mPhysicalChannelConfigRegistrants = new RegistrantList(); 426 427 private final RegistrantList mOtaspRegistrants = new RegistrantList(); 428 429 private final RegistrantList mPreferredNetworkTypeRegistrants = new RegistrantList(); 430 431 protected Registrant mPostDialHandler; 432 433 protected final LocalLog mLocalLog; 434 435 private Looper mLooper; /* to insure registrants are in correct thread*/ 436 437 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 438 protected final Context mContext; 439 440 /** 441 * PhoneNotifier is an abstraction for all system-wide 442 * state change notification. DefaultPhoneNotifier is 443 * used here unless running we're inside a unit test. 444 */ 445 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 446 protected PhoneNotifier mNotifier; 447 448 protected SimulatedRadioControl mSimulatedRadioControl; 449 450 private Map<Integer, Long> mAllowedNetworkTypesForReasons = new HashMap<>(); 451 private static final String ALLOWED_NETWORK_TYPES_TEXT_USER = "user"; 452 private static final String ALLOWED_NETWORK_TYPES_TEXT_POWER = "power"; 453 private static final String ALLOWED_NETWORK_TYPES_TEXT_CARRIER = "carrier"; 454 private static final String ALLOWED_NETWORK_TYPES_TEXT_ENABLE_2G = "enable_2g"; 455 private static final int INVALID_ALLOWED_NETWORK_TYPES = -1; 456 protected boolean mIsCarrierNrSupported = false; 457 protected boolean mIsAllowedNetworkTypesLoadedFromDb = false; 458 private boolean mUnitTestMode; 459 private CarrierPrivilegesTracker mCarrierPrivilegesTracker = null; 460 461 protected VoiceCallSessionStats mVoiceCallSessionStats; 462 protected SmsStats mSmsStats; 463 464 protected LinkBandwidthEstimator mLinkBandwidthEstimator; 465 getIccRecords()466 public IccRecords getIccRecords() { 467 return mIccRecords.get(); 468 } 469 470 /** 471 * Returns a string identifier for this phone interface for parties 472 * outside the phone app process. 473 * @return The string name. 474 */ 475 @UnsupportedAppUsage getPhoneName()476 public String getPhoneName() { 477 return mName; 478 } 479 setPhoneName(String name)480 protected void setPhoneName(String name) { 481 mName = name; 482 } 483 484 /** 485 * Retrieves Nai for phones. Returns null if Nai is not set. 486 */ 487 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getNai()488 public String getNai(){ 489 return null; 490 } 491 492 /** 493 * Return the ActionDetached string. When this action is received by components 494 * they are to simulate detaching from the network. 495 * 496 * @return com.android.internal.telephony.{mName}.action_detached 497 * {mName} is GSM, CDMA ... 498 */ getActionDetached()499 public String getActionDetached() { 500 return mActionDetached; 501 } 502 503 /** 504 * Return the ActionAttached string. When this action is received by components 505 * they are to simulate attaching to the network. 506 * 507 * @return com.android.internal.telephony.{mName}.action_detached 508 * {mName} is GSM, CDMA ... 509 */ getActionAttached()510 public String getActionAttached() { 511 return mActionAttached; 512 } 513 514 /** 515 * Set a system property, unless we're in unit test mode 516 */ 517 // CAF_MSIM TODO this need to be replated with TelephonyManager API ? 518 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getSystemProperty(String property, String defValue)519 public String getSystemProperty(String property, String defValue) { 520 if(getUnitTestMode()) { 521 return null; 522 } 523 return SystemProperties.get(property, defValue); 524 } 525 526 /** 527 * Constructs a Phone in normal (non-unit test) mode. 528 * 529 * @param notifier An instance of DefaultPhoneNotifier, 530 * @param context Context object from hosting application 531 * unless unit testing. 532 * @param ci is CommandsInterface 533 * @param unitTestMode when true, prevents notifications 534 * of state change events 535 */ Phone(String name, PhoneNotifier notifier, Context context, CommandsInterface ci, boolean unitTestMode)536 protected Phone(String name, PhoneNotifier notifier, Context context, CommandsInterface ci, 537 boolean unitTestMode) { 538 this(name, notifier, context, ci, unitTestMode, SubscriptionManager.DEFAULT_PHONE_INDEX, 539 TelephonyComponentFactory.getInstance()); 540 } 541 542 /** 543 * Constructs a Phone in normal (non-unit test) mode. 544 * 545 * @param notifier An instance of DefaultPhoneNotifier, 546 * @param context Context object from hosting application 547 * unless unit testing. 548 * @param ci is CommandsInterface 549 * @param unitTestMode when true, prevents notifications 550 * of state change events 551 * @param phoneId the phone-id of this phone. 552 */ Phone(String name, PhoneNotifier notifier, Context context, CommandsInterface ci, boolean unitTestMode, int phoneId, TelephonyComponentFactory telephonyComponentFactory)553 protected Phone(String name, PhoneNotifier notifier, Context context, CommandsInterface ci, 554 boolean unitTestMode, int phoneId, 555 TelephonyComponentFactory telephonyComponentFactory) { 556 mPhoneId = phoneId; 557 mName = name; 558 mNotifier = notifier; 559 mContext = context; 560 mLooper = Looper.myLooper(); 561 mCi = ci; 562 mActionDetached = this.getClass().getPackage().getName() + ".action_detached"; 563 mActionAttached = this.getClass().getPackage().getName() + ".action_attached"; 564 mAppSmsManager = telephonyComponentFactory.inject(AppSmsManager.class.getName()) 565 .makeAppSmsManager(context); 566 mLocalLog = new LocalLog(64); 567 568 if (TelephonyUtils.IS_DEBUGGABLE) { 569 mTelephonyTester = new TelephonyTester(this); 570 } 571 572 setUnitTestMode(unitTestMode); 573 574 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); 575 mDnsCheckDisabled = sp.getBoolean(DNS_SERVER_CHECK_DISABLED_KEY, false); 576 mCi.setOnCallRing(this, EVENT_CALL_RING, null); 577 578 /* "Voice capable" means that this device supports circuit-switched 579 * (i.e. voice) phone calls over the telephony network, and is allowed 580 * to display the in-call UI while a cellular voice call is active. 581 * This will be false on "data only" devices which can't make voice 582 * calls and don't support any in-call UI. 583 */ 584 mIsVoiceCapable = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)) 585 .isVoiceCapable(); 586 587 /** 588 * Some RIL's don't always send RIL_UNSOL_CALL_RING so it needs 589 * to be generated locally. Ideally all ring tones should be loops 590 * and this wouldn't be necessary. But to minimize changes to upper 591 * layers it is requested that it be generated by lower layers. 592 * 593 * By default old phones won't have the property set but do generate 594 * the RIL_UNSOL_CALL_RING so the default if there is no property is 595 * true. 596 */ 597 mDoesRilSendMultipleCallRing = TelephonyProperties.ril_sends_multiple_call_ring() 598 .orElse(true); 599 Rlog.d(LOG_TAG, "mDoesRilSendMultipleCallRing=" + mDoesRilSendMultipleCallRing); 600 601 mCallRingDelay = TelephonyProperties.call_ring_delay().orElse(3000); 602 Rlog.d(LOG_TAG, "mCallRingDelay=" + mCallRingDelay); 603 604 // Initialize SMS stats 605 mSmsStats = new SmsStats(this); 606 607 if (getPhoneType() == PhoneConstants.PHONE_TYPE_IMS) { 608 return; 609 } 610 611 // Initialize device storage and outgoing SMS usage monitors for SMSDispatchers. 612 mTelephonyComponentFactory = telephonyComponentFactory; 613 mSmsStorageMonitor = mTelephonyComponentFactory.inject(SmsStorageMonitor.class.getName()) 614 .makeSmsStorageMonitor(this); 615 mSmsUsageMonitor = mTelephonyComponentFactory.inject(SmsUsageMonitor.class.getName()) 616 .makeSmsUsageMonitor(context); 617 mUiccController = UiccController.getInstance(); 618 mUiccController.registerForIccChanged(this, EVENT_ICC_CHANGED, null); 619 mSimActivationTracker = mTelephonyComponentFactory 620 .inject(SimActivationTracker.class.getName()) 621 .makeSimActivationTracker(this); 622 mCarrierPrivilegesTracker = new CarrierPrivilegesTracker(mLooper, this, mContext); 623 if (getPhoneType() != PhoneConstants.PHONE_TYPE_SIP) { 624 mCi.registerForSrvccStateChanged(this, EVENT_SRVCC_STATE_CHANGED, null); 625 } 626 mCi.startLceService(DEFAULT_REPORT_INTERVAL_MS, LCE_PULL_MODE, 627 obtainMessage(EVENT_CONFIG_LCE)); 628 } 629 630 /** 631 * Start setup of ImsPhone, which will start trying to connect to the ImsResolver. Will not be 632 * called if this device does not support FEATURE_IMS_TELEPHONY. 633 */ createImsPhone()634 public void createImsPhone() { 635 if (getPhoneType() == PhoneConstants.PHONE_TYPE_SIP) { 636 return; 637 } 638 639 synchronized(Phone.lockForRadioTechnologyChange) { 640 if (mImsPhone == null) { 641 mImsPhone = PhoneFactory.makeImsPhone(mNotifier, this); 642 CallManager.getInstance().registerPhone(mImsPhone); 643 mImsPhone.registerForSilentRedial( 644 this, EVENT_INITIATE_SILENT_REDIAL, null); 645 } 646 } 647 } 648 649 /** 650 * Checks if device should convert CDMA Caller ID restriction related MMI codes to 651 * equivalent 3GPP MMI Codes that provide same functionality when device is roaming. 652 * This method should only return true on multi-mode devices when carrier requires this 653 * conversion to be done on the device. 654 * 655 * @return true when carrier config 656 * "KEY_CONVERT_CDMA_CALLER_ID_MMI_CODES_WHILE_ROAMING_ON_3GPP_BOOL" is set to true 657 */ supportsConversionOfCdmaCallerIdMmiCodesWhileRoaming()658 public boolean supportsConversionOfCdmaCallerIdMmiCodesWhileRoaming() { 659 CarrierConfigManager configManager = (CarrierConfigManager) 660 getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); 661 PersistableBundle b = configManager.getConfigForSubId(getSubId()); 662 if (b != null) { 663 return b.getBoolean( 664 CarrierConfigManager 665 .KEY_CONVERT_CDMA_CALLER_ID_MMI_CODES_WHILE_ROAMING_ON_3GPP_BOOL, 666 false); 667 } else { 668 // Default value set in CarrierConfigManager 669 return false; 670 } 671 } 672 673 /** 674 * Check if sending CLIR activation("*31#") and deactivation("#31#") code only without dialing 675 * number is prevented. 676 * 677 * @return {@code true} when carrier config 678 * "KEY_PREVENT_CLIR_ACTIVATION_AND_DEACTIVATION_CODE_BOOL" is set to {@code true} 679 */ isClirActivationAndDeactivationPrevented()680 public boolean isClirActivationAndDeactivationPrevented() { 681 CarrierConfigManager configManager = (CarrierConfigManager) 682 getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); 683 PersistableBundle b = configManager.getConfigForSubId(getSubId()); 684 if (b == null) { 685 b = CarrierConfigManager.getDefaultConfig(); 686 } 687 return b.getBoolean( 688 CarrierConfigManager.KEY_PREVENT_CLIR_ACTIVATION_AND_DEACTIVATION_CODE_BOOL); 689 } 690 691 /** 692 * When overridden the derived class needs to call 693 * super.handleMessage(msg) so this method has a 694 * a chance to process the message. 695 * 696 * @param msg 697 */ 698 @Override handleMessage(Message msg)699 public void handleMessage(Message msg) { 700 AsyncResult ar; 701 702 // messages to be handled whether or not the phone is being destroyed 703 // should only include messages which are being re-directed and do not use 704 // resources of the phone being destroyed 705 switch (msg.what) { 706 // handle the select network completion callbacks. 707 case EVENT_SET_NETWORK_MANUAL_COMPLETE: 708 case EVENT_SET_NETWORK_AUTOMATIC_COMPLETE: 709 handleSetSelectNetwork((AsyncResult) msg.obj); 710 return; 711 } 712 713 switch(msg.what) { 714 case EVENT_CALL_RING: 715 Rlog.d(LOG_TAG, "Event EVENT_CALL_RING Received state=" + getState()); 716 ar = (AsyncResult)msg.obj; 717 if (ar.exception == null) { 718 PhoneConstants.State state = getState(); 719 if ((!mDoesRilSendMultipleCallRing) 720 && ((state == PhoneConstants.State.RINGING) || 721 (state == PhoneConstants.State.IDLE))) { 722 mCallRingContinueToken += 1; 723 sendIncomingCallRingNotification(mCallRingContinueToken); 724 } else { 725 notifyIncomingRing(); 726 } 727 } 728 break; 729 730 case EVENT_CALL_RING_CONTINUE: 731 Rlog.d(LOG_TAG, "Event EVENT_CALL_RING_CONTINUE Received state=" + getState()); 732 if (getState() == PhoneConstants.State.RINGING) { 733 sendIncomingCallRingNotification(msg.arg1); 734 } 735 break; 736 737 case EVENT_ICC_CHANGED: 738 onUpdateIccAvailability(); 739 break; 740 741 case EVENT_INITIATE_SILENT_REDIAL: 742 // This is an ImsPhone -> GsmCdmaPhone redial 743 // See ImsPhone#initiateSilentRedial 744 Rlog.d(LOG_TAG, "Event EVENT_INITIATE_SILENT_REDIAL Received"); 745 ar = (AsyncResult) msg.obj; 746 if ((ar.exception == null) && (ar.result != null)) { 747 SilentRedialParam result = (SilentRedialParam) ar.result; 748 String dialString = result.dialString; 749 int causeCode = result.causeCode; 750 DialArgs dialArgs = result.dialArgs; 751 if (TextUtils.isEmpty(dialString)) return; 752 try { 753 Connection cn = dialInternal(dialString, dialArgs); 754 // The ImsPhoneConnection that is owned by the ImsPhone is currently the 755 // one with a callback registered to TelephonyConnection. Notify the 756 // redial happened over that Phone so that it can be replaced with the 757 // new GSM/CDMA Connection. 758 Rlog.d(LOG_TAG, "Notify redial connection changed cn: " + cn); 759 if (mImsPhone != null) { 760 // Don't care it is null or not. 761 mImsPhone.notifyRedialConnectionChanged(cn); 762 } 763 } catch (CallStateException e) { 764 Rlog.e(LOG_TAG, "silent redial failed: " + e); 765 if (mImsPhone != null) { 766 mImsPhone.notifyRedialConnectionChanged(null); 767 } 768 } 769 } 770 break; 771 772 case EVENT_SRVCC_STATE_CHANGED: 773 ar = (AsyncResult)msg.obj; 774 if (ar.exception == null) { 775 handleSrvccStateChanged((int[]) ar.result); 776 } else { 777 Rlog.e(LOG_TAG, "Srvcc exception: " + ar.exception); 778 } 779 break; 780 781 case EVENT_UNSOL_OEM_HOOK_RAW: 782 // deprecated, ignore 783 break; 784 785 case EVENT_CONFIG_LCE: 786 ar = (AsyncResult) msg.obj; 787 if (ar.exception != null) { 788 Rlog.d(LOG_TAG, "config LCE service failed: " + ar.exception); 789 } else { 790 final ArrayList<Integer> statusInfo = (ArrayList<Integer>)ar.result; 791 mLceStatus = statusInfo.get(0); 792 } 793 break; 794 795 case EVENT_CHECK_FOR_NETWORK_AUTOMATIC: { 796 onCheckForNetworkSelectionModeAutomatic(msg); 797 break; 798 } 799 800 case EVENT_ALL_DATA_DISCONNECTED: 801 if (areAllDataDisconnected()) { 802 mAllDataDisconnectedRegistrants.notifyRegistrants(); 803 } 804 break; 805 default: 806 throw new RuntimeException("unexpected event not handled"); 807 } 808 } 809 getHandoverConnection()810 public ArrayList<Connection> getHandoverConnection() { 811 return null; 812 } 813 notifySrvccState(Call.SrvccState state)814 public void notifySrvccState(Call.SrvccState state) { 815 } 816 registerForSilentRedial(Handler h, int what, Object obj)817 public void registerForSilentRedial(Handler h, int what, Object obj) { 818 } 819 unregisterForSilentRedial(Handler h)820 public void unregisterForSilentRedial(Handler h) { 821 } 822 registerForVolteSilentRedial(Handler h, int what, Object obj)823 public void registerForVolteSilentRedial(Handler h, int what, Object obj) { 824 } 825 unregisterForVolteSilentRedial(Handler h)826 public void unregisterForVolteSilentRedial(Handler h) { 827 } 828 handleSrvccStateChanged(int[] ret)829 private void handleSrvccStateChanged(int[] ret) { 830 Rlog.d(LOG_TAG, "handleSrvccStateChanged"); 831 832 ArrayList<Connection> conn = null; 833 Phone imsPhone = mImsPhone; 834 Call.SrvccState srvccState = Call.SrvccState.NONE; 835 if (ret != null && ret.length != 0) { 836 int state = ret[0]; 837 switch(state) { 838 case TelephonyManager.SRVCC_STATE_HANDOVER_STARTED: 839 srvccState = Call.SrvccState.STARTED; 840 if (imsPhone != null) { 841 conn = imsPhone.getHandoverConnection(); 842 migrateFrom(imsPhone); 843 } else { 844 Rlog.d(LOG_TAG, "HANDOVER_STARTED: mImsPhone null"); 845 } 846 break; 847 case TelephonyManager.SRVCC_STATE_HANDOVER_COMPLETED: 848 srvccState = Call.SrvccState.COMPLETED; 849 if (imsPhone != null) { 850 imsPhone.notifySrvccState(srvccState); 851 } else { 852 Rlog.d(LOG_TAG, "HANDOVER_COMPLETED: mImsPhone null"); 853 } 854 break; 855 case TelephonyManager.SRVCC_STATE_HANDOVER_FAILED: 856 case TelephonyManager.SRVCC_STATE_HANDOVER_CANCELED: 857 srvccState = Call.SrvccState.FAILED; 858 break; 859 860 default: 861 //ignore invalid state 862 return; 863 } 864 865 getCallTracker().notifySrvccState(srvccState, conn); 866 867 notifySrvccStateChanged(state); 868 } 869 } 870 871 /** 872 * Gets the context for the phone, as set at initialization time. 873 */ 874 @UnsupportedAppUsage getContext()875 public Context getContext() { 876 return mContext; 877 } 878 879 // Will be called when icc changed onUpdateIccAvailability()880 protected abstract void onUpdateIccAvailability(); 881 882 /** 883 * Disables the DNS check (i.e., allows "0.0.0.0"). 884 * Useful for lab testing environment. 885 * @param b true disables the check, false enables. 886 */ disableDnsCheck(boolean b)887 public void disableDnsCheck(boolean b) { 888 mDnsCheckDisabled = b; 889 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); 890 SharedPreferences.Editor editor = sp.edit(); 891 editor.putBoolean(DNS_SERVER_CHECK_DISABLED_KEY, b); 892 editor.apply(); 893 } 894 895 /** 896 * Returns true if the DNS check is currently disabled. 897 */ isDnsCheckDisabled()898 public boolean isDnsCheckDisabled() { 899 return mDnsCheckDisabled; 900 } 901 902 /** 903 * Register for getting notifications for change in the Call State {@link Call.State} 904 * This is called PreciseCallState because the call state is more precise than the 905 * {@link PhoneConstants.State} which can be obtained using the {@link PhoneStateListener} 906 * 907 * Resulting events will have an AsyncResult in <code>Message.obj</code>. 908 * AsyncResult.userData will be set to the obj argument here. 909 * The <em>h</em> parameter is held only by a weak reference. 910 */ 911 @UnsupportedAppUsage registerForPreciseCallStateChanged(Handler h, int what, Object obj)912 public void registerForPreciseCallStateChanged(Handler h, int what, Object obj) { 913 checkCorrectThread(h); 914 915 mPreciseCallStateRegistrants.addUnique(h, what, obj); 916 } 917 918 /** 919 * Unregisters for voice call state change notifications. 920 * Extraneous calls are tolerated silently. 921 */ 922 @UnsupportedAppUsage unregisterForPreciseCallStateChanged(Handler h)923 public void unregisterForPreciseCallStateChanged(Handler h) { 924 mPreciseCallStateRegistrants.remove(h); 925 } 926 927 /** 928 * Subclasses of Phone probably want to replace this with a 929 * version scoped to their packages 930 */ notifyPreciseCallStateChangedP()931 protected void notifyPreciseCallStateChangedP() { 932 AsyncResult ar = new AsyncResult(null, this, null); 933 mPreciseCallStateRegistrants.notifyRegistrants(ar); 934 935 mNotifier.notifyPreciseCallState(this); 936 } 937 938 /** 939 * Notifies when a Handover happens due to SRVCC or Silent Redial 940 */ registerForHandoverStateChanged(Handler h, int what, Object obj)941 public void registerForHandoverStateChanged(Handler h, int what, Object obj) { 942 checkCorrectThread(h); 943 mHandoverRegistrants.addUnique(h, what, obj); 944 } 945 946 /** 947 * Unregisters for handover state notifications 948 */ unregisterForHandoverStateChanged(Handler h)949 public void unregisterForHandoverStateChanged(Handler h) { 950 mHandoverRegistrants.remove(h); 951 } 952 953 /** 954 * Subclasses of Phone probably want to replace this with a 955 * version scoped to their packages 956 */ notifyHandoverStateChanged(Connection cn)957 public void notifyHandoverStateChanged(Connection cn) { 958 AsyncResult ar = new AsyncResult(null, cn, null); 959 mHandoverRegistrants.notifyRegistrants(ar); 960 } 961 962 /** 963 * Notifies when a Handover happens due to Silent Redial 964 */ registerForRedialConnectionChanged(Handler h, int what, Object obj)965 public void registerForRedialConnectionChanged(Handler h, int what, Object obj) { 966 checkCorrectThread(h); 967 mRedialRegistrants.addUnique(h, what, obj); 968 } 969 970 /** 971 * Unregisters for redial connection notifications 972 */ unregisterForRedialConnectionChanged(Handler h)973 public void unregisterForRedialConnectionChanged(Handler h) { 974 mRedialRegistrants.remove(h); 975 } 976 977 /** 978 * Subclasses of Phone probably want to replace this with a 979 * version scoped to their packages 980 */ notifyRedialConnectionChanged(Connection cn)981 public void notifyRedialConnectionChanged(Connection cn) { 982 AsyncResult ar = new AsyncResult(null, cn, null); 983 mRedialRegistrants.notifyRegistrants(ar); 984 } 985 setIsInEmergencyCall()986 protected void setIsInEmergencyCall() { 987 } 988 989 /** 990 * Notify the phone that an SMS has been sent. This will be used determine if the SMS was sent 991 * to an emergency address. 992 * @param destinationAddress the address that the SMS was sent to. 993 */ notifySmsSent(String destinationAddress)994 public void notifySmsSent(String destinationAddress) { 995 TelephonyManager m = (TelephonyManager) getContext().getSystemService( 996 Context.TELEPHONY_SERVICE); 997 if (m != null && m.isEmergencyNumber(destinationAddress)) { 998 mLocalLog.log("Emergency SMS detected, recording time."); 999 mTimeLastEmergencySmsSentMs = SystemClock.elapsedRealtime(); 1000 } 1001 } 1002 1003 /** 1004 * Determine if the Phone has recently sent an emergency SMS and is still in the interval of 1005 * time defined by a carrier that we may need to do perform special actions, for example 1006 * override user setting for location so the carrier can find the user's location for emergency 1007 * services. 1008 * 1009 * @return true if the device is in emergency SMS mode, false otherwise. 1010 */ isInEmergencySmsMode()1011 public boolean isInEmergencySmsMode() { 1012 long lastSmsTimeMs = mTimeLastEmergencySmsSentMs; 1013 if (lastSmsTimeMs == EMERGENCY_SMS_NO_TIME_RECORDED) { 1014 // an emergency SMS hasn't been sent since the last check. 1015 return false; 1016 } 1017 CarrierConfigManager configManager = (CarrierConfigManager) 1018 getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); 1019 PersistableBundle b = configManager.getConfigForSubId(getSubId()); 1020 if (b == null) { 1021 // default for KEY_EMERGENCY_SMS_MODE_TIMER_MS_INT is 0 and CarrierConfig isn't 1022 // available, so return false. 1023 return false; 1024 } 1025 int eSmsTimerMs = b.getInt(CarrierConfigManager.KEY_EMERGENCY_SMS_MODE_TIMER_MS_INT, 0); 1026 if (eSmsTimerMs == 0) { 1027 // We do not support this feature for this carrier. 1028 return false; 1029 } 1030 if (eSmsTimerMs > EMERGENCY_SMS_TIMER_MAX_MS) { 1031 eSmsTimerMs = EMERGENCY_SMS_TIMER_MAX_MS; 1032 } 1033 boolean isInEmergencySmsMode = SystemClock.elapsedRealtime() 1034 <= (lastSmsTimeMs + eSmsTimerMs); 1035 if (!isInEmergencySmsMode) { 1036 // Shortcut this next time so we do not have to waste time if another emergency SMS 1037 // hasn't been sent since the last query. 1038 mTimeLastEmergencySmsSentMs = EMERGENCY_SMS_NO_TIME_RECORDED; 1039 } else { 1040 mLocalLog.log("isInEmergencySmsMode: queried while eSMS mode is active."); 1041 } 1042 return isInEmergencySmsMode; 1043 } 1044 migrateFrom(Phone from)1045 protected void migrateFrom(Phone from) { 1046 migrate(mHandoverRegistrants, from.mHandoverRegistrants); 1047 migrate(mPreciseCallStateRegistrants, from.mPreciseCallStateRegistrants); 1048 migrate(mNewRingingConnectionRegistrants, from.mNewRingingConnectionRegistrants); 1049 migrate(mIncomingRingRegistrants, from.mIncomingRingRegistrants); 1050 migrate(mDisconnectRegistrants, from.mDisconnectRegistrants); 1051 migrate(mServiceStateRegistrants, from.mServiceStateRegistrants); 1052 migrate(mMmiCompleteRegistrants, from.mMmiCompleteRegistrants); 1053 migrate(mMmiRegistrants, from.mMmiRegistrants); 1054 migrate(mUnknownConnectionRegistrants, from.mUnknownConnectionRegistrants); 1055 migrate(mSuppServiceFailedRegistrants, from.mSuppServiceFailedRegistrants); 1056 migrate(mCellInfoRegistrants, from.mCellInfoRegistrants); 1057 migrate(mRedialRegistrants, from.mRedialRegistrants); 1058 // The emergency state of IMS phone will be cleared in ImsPhone#notifySrvccState after 1059 // receive SRVCC completed 1060 if (from.isInEmergencyCall()) { 1061 setIsInEmergencyCall(); 1062 } 1063 setEcmCanceledForEmergency(from.isEcmCanceledForEmergency()); 1064 } 1065 migrate(RegistrantList to, RegistrantList from)1066 protected void migrate(RegistrantList to, RegistrantList from) { 1067 if (from == null) { 1068 // May be null in some cases, such as testing. 1069 return; 1070 } 1071 from.removeCleared(); 1072 for (int i = 0, n = from.size(); i < n; i++) { 1073 Registrant r = (Registrant) from.get(i); 1074 Message msg = r.messageForRegistrant(); 1075 // Since CallManager has already registered with both CS and IMS phones, 1076 // the migrate should happen only for those registrants which are not 1077 // registered with CallManager.Hence the below check is needed to add 1078 // only those registrants to the registrant list which are not 1079 // coming from the CallManager. 1080 if (msg != null) { 1081 if (msg.obj == CallManager.getInstance().getRegistrantIdentifier()) { 1082 continue; 1083 } else { 1084 to.add((Registrant) from.get(i)); 1085 } 1086 } else { 1087 Rlog.d(LOG_TAG, "msg is null"); 1088 } 1089 } 1090 } 1091 1092 /** 1093 * Notifies when a previously untracked non-ringing/waiting connection has appeared. 1094 * This is likely due to some other entity (eg, SIM card application) initiating a call. 1095 */ 1096 @UnsupportedAppUsage registerForUnknownConnection(Handler h, int what, Object obj)1097 public void registerForUnknownConnection(Handler h, int what, Object obj) { 1098 checkCorrectThread(h); 1099 1100 mUnknownConnectionRegistrants.addUnique(h, what, obj); 1101 } 1102 1103 /** 1104 * Unregisters for unknown connection notifications. 1105 */ 1106 @UnsupportedAppUsage unregisterForUnknownConnection(Handler h)1107 public void unregisterForUnknownConnection(Handler h) { 1108 mUnknownConnectionRegistrants.remove(h); 1109 } 1110 1111 /** 1112 * Notifies when a new ringing or waiting connection has appeared.<p> 1113 * 1114 * Messages received from this: 1115 * Message.obj will be an AsyncResult 1116 * AsyncResult.userObj = obj 1117 * AsyncResult.result = a Connection. <p> 1118 * Please check Connection.isRinging() to make sure the Connection 1119 * has not dropped since this message was posted. 1120 * If Connection.isRinging() is true, then 1121 * Connection.getCall() == Phone.getRingingCall() 1122 */ 1123 @UnsupportedAppUsage registerForNewRingingConnection( Handler h, int what, Object obj)1124 public void registerForNewRingingConnection( 1125 Handler h, int what, Object obj) { 1126 checkCorrectThread(h); 1127 1128 mNewRingingConnectionRegistrants.addUnique(h, what, obj); 1129 } 1130 1131 /** 1132 * Unregisters for new ringing connection notification. 1133 * Extraneous calls are tolerated silently 1134 */ 1135 @UnsupportedAppUsage unregisterForNewRingingConnection(Handler h)1136 public void unregisterForNewRingingConnection(Handler h) { 1137 mNewRingingConnectionRegistrants.remove(h); 1138 } 1139 1140 /** 1141 * Notifies when phone's video capabilities changes <p> 1142 * 1143 * Messages received from this: 1144 * Message.obj will be an AsyncResult 1145 * AsyncResult.userObj = obj 1146 * AsyncResult.result = true if phone supports video calling <p> 1147 */ registerForVideoCapabilityChanged( Handler h, int what, Object obj)1148 public void registerForVideoCapabilityChanged( 1149 Handler h, int what, Object obj) { 1150 checkCorrectThread(h); 1151 1152 mVideoCapabilityChangedRegistrants.addUnique(h, what, obj); 1153 1154 // Notify any registrants of the cached video capability as soon as they register. 1155 notifyForVideoCapabilityChanged(mIsVideoCapable); 1156 } 1157 1158 /** 1159 * Unregisters for video capability changed notification. 1160 * Extraneous calls are tolerated silently 1161 */ unregisterForVideoCapabilityChanged(Handler h)1162 public void unregisterForVideoCapabilityChanged(Handler h) { 1163 mVideoCapabilityChangedRegistrants.remove(h); 1164 } 1165 1166 /** 1167 * Register for notifications when a sInCall VoicePrivacy is enabled 1168 * 1169 * @param h Handler that receives the notification message. 1170 * @param what User-defined message code. 1171 * @param obj User object. 1172 */ registerForInCallVoicePrivacyOn(Handler h, int what, Object obj)1173 public void registerForInCallVoicePrivacyOn(Handler h, int what, Object obj){ 1174 mCi.registerForInCallVoicePrivacyOn(h, what, obj); 1175 } 1176 1177 /** 1178 * Unegister for notifications when a sInCall VoicePrivacy is enabled 1179 * 1180 * @param h Handler to be removed from the registrant list. 1181 */ unregisterForInCallVoicePrivacyOn(Handler h)1182 public void unregisterForInCallVoicePrivacyOn(Handler h){ 1183 mCi.unregisterForInCallVoicePrivacyOn(h); 1184 } 1185 1186 /** 1187 * Register for notifications when a sInCall VoicePrivacy is disabled 1188 * 1189 * @param h Handler that receives the notification message. 1190 * @param what User-defined message code. 1191 * @param obj User object. 1192 */ registerForInCallVoicePrivacyOff(Handler h, int what, Object obj)1193 public void registerForInCallVoicePrivacyOff(Handler h, int what, Object obj){ 1194 mCi.registerForInCallVoicePrivacyOff(h, what, obj); 1195 } 1196 1197 /** 1198 * Unregister for notifications when a sInCall VoicePrivacy is disabled 1199 * 1200 * @param h Handler to be removed from the registrant list. 1201 */ unregisterForInCallVoicePrivacyOff(Handler h)1202 public void unregisterForInCallVoicePrivacyOff(Handler h){ 1203 mCi.unregisterForInCallVoicePrivacyOff(h); 1204 } 1205 1206 /** 1207 * Notifies when an incoming call rings.<p> 1208 * 1209 * Messages received from this: 1210 * Message.obj will be an AsyncResult 1211 * AsyncResult.userObj = obj 1212 * AsyncResult.result = a Connection. <p> 1213 */ 1214 @UnsupportedAppUsage registerForIncomingRing( Handler h, int what, Object obj)1215 public void registerForIncomingRing( 1216 Handler h, int what, Object obj) { 1217 checkCorrectThread(h); 1218 1219 mIncomingRingRegistrants.addUnique(h, what, obj); 1220 } 1221 1222 /** 1223 * Unregisters for ring notification. 1224 * Extraneous calls are tolerated silently 1225 */ 1226 @UnsupportedAppUsage unregisterForIncomingRing(Handler h)1227 public void unregisterForIncomingRing(Handler h) { 1228 mIncomingRingRegistrants.remove(h); 1229 } 1230 1231 /** 1232 * Notifies when a voice connection has disconnected, either due to local 1233 * or remote hangup or error. 1234 * 1235 * Messages received from this will have the following members:<p> 1236 * <ul><li>Message.obj will be an AsyncResult</li> 1237 * <li>AsyncResult.userObj = obj</li> 1238 * <li>AsyncResult.result = a Connection object that is 1239 * no longer connected.</li></ul> 1240 */ 1241 @UnsupportedAppUsage registerForDisconnect(Handler h, int what, Object obj)1242 public void registerForDisconnect(Handler h, int what, Object obj) { 1243 checkCorrectThread(h); 1244 1245 mDisconnectRegistrants.addUnique(h, what, obj); 1246 } 1247 1248 /** 1249 * Unregisters for voice disconnection notification. 1250 * Extraneous calls are tolerated silently 1251 */ 1252 @UnsupportedAppUsage unregisterForDisconnect(Handler h)1253 public void unregisterForDisconnect(Handler h) { 1254 mDisconnectRegistrants.remove(h); 1255 } 1256 1257 /** 1258 * Register for notifications when a supplementary service attempt fails. 1259 * Message.obj will contain an AsyncResult. 1260 * 1261 * @param h Handler that receives the notification message. 1262 * @param what User-defined message code. 1263 * @param obj User object. 1264 */ registerForSuppServiceFailed(Handler h, int what, Object obj)1265 public void registerForSuppServiceFailed(Handler h, int what, Object obj) { 1266 checkCorrectThread(h); 1267 1268 mSuppServiceFailedRegistrants.addUnique(h, what, obj); 1269 } 1270 1271 /** 1272 * Unregister for notifications when a supplementary service attempt fails. 1273 * Extraneous calls are tolerated silently 1274 * 1275 * @param h Handler to be removed from the registrant list. 1276 */ unregisterForSuppServiceFailed(Handler h)1277 public void unregisterForSuppServiceFailed(Handler h) { 1278 mSuppServiceFailedRegistrants.remove(h); 1279 } 1280 1281 /** 1282 * Register for notifications of initiation of a new MMI code request. 1283 * MMI codes for GSM are discussed in 3GPP TS 22.030.<p> 1284 * 1285 * Example: If Phone.dial is called with "*#31#", then the app will 1286 * be notified here.<p> 1287 * 1288 * The returned <code>Message.obj</code> will contain an AsyncResult. 1289 * 1290 * <code>obj.result</code> will be an "MmiCode" object. 1291 */ 1292 @UnsupportedAppUsage registerForMmiInitiate(Handler h, int what, Object obj)1293 public void registerForMmiInitiate(Handler h, int what, Object obj) { 1294 checkCorrectThread(h); 1295 1296 mMmiRegistrants.addUnique(h, what, obj); 1297 } 1298 1299 /** 1300 * Unregisters for new MMI initiate notification. 1301 * Extraneous calls are tolerated silently 1302 */ 1303 @UnsupportedAppUsage unregisterForMmiInitiate(Handler h)1304 public void unregisterForMmiInitiate(Handler h) { 1305 mMmiRegistrants.remove(h); 1306 } 1307 1308 /** 1309 * Register for notifications that an MMI request has completed 1310 * its network activity and is in its final state. This may mean a state 1311 * of COMPLETE, FAILED, or CANCELLED. 1312 * 1313 * <code>Message.obj</code> will contain an AsyncResult. 1314 * <code>obj.result</code> will be an "MmiCode" object 1315 */ 1316 @UnsupportedAppUsage registerForMmiComplete(Handler h, int what, Object obj)1317 public void registerForMmiComplete(Handler h, int what, Object obj) { 1318 checkCorrectThread(h); 1319 1320 mMmiCompleteRegistrants.addUnique(h, what, obj); 1321 } 1322 1323 /** 1324 * Unregisters for MMI complete notification. 1325 * Extraneous calls are tolerated silently 1326 */ 1327 @UnsupportedAppUsage unregisterForMmiComplete(Handler h)1328 public void unregisterForMmiComplete(Handler h) { 1329 checkCorrectThread(h); 1330 1331 mMmiCompleteRegistrants.remove(h); 1332 } 1333 1334 /** 1335 * Registration point for Sim records loaded 1336 * @param h handler to notify 1337 * @param what what code of message when delivered 1338 * @param obj placed in Message.obj 1339 */ 1340 @UnsupportedAppUsage registerForSimRecordsLoaded(Handler h, int what, Object obj)1341 public void registerForSimRecordsLoaded(Handler h, int what, Object obj) { 1342 } 1343 1344 /** 1345 * Unregister for notifications for Sim records loaded 1346 * @param h Handler to be removed from the registrant list. 1347 */ 1348 @UnsupportedAppUsage unregisterForSimRecordsLoaded(Handler h)1349 public void unregisterForSimRecordsLoaded(Handler h) { 1350 } 1351 1352 /** 1353 * Register for TTY mode change notifications from the network. 1354 * Message.obj will contain an AsyncResult. 1355 * AsyncResult.result will be an Integer containing new mode. 1356 * 1357 * @param h Handler that receives the notification message. 1358 * @param what User-defined message code. 1359 * @param obj User object. 1360 */ registerForTtyModeReceived(Handler h, int what, Object obj)1361 public void registerForTtyModeReceived(Handler h, int what, Object obj) { 1362 } 1363 1364 /** 1365 * Unregisters for TTY mode change notifications. 1366 * Extraneous calls are tolerated silently 1367 * 1368 * @param h Handler to be removed from the registrant list. 1369 */ unregisterForTtyModeReceived(Handler h)1370 public void unregisterForTtyModeReceived(Handler h) { 1371 } 1372 1373 /** 1374 * Switches network selection mode to "automatic", re-scanning and 1375 * re-selecting a network if appropriate. 1376 * 1377 * @param response The message to dispatch when the network selection 1378 * is complete. 1379 * 1380 * @see #selectNetworkManually(OperatorInfo, boolean, android.os.Message) 1381 */ 1382 @UnsupportedAppUsage setNetworkSelectionModeAutomatic(Message response)1383 public void setNetworkSelectionModeAutomatic(Message response) { 1384 Rlog.d(LOG_TAG, "setNetworkSelectionModeAutomatic, querying current mode"); 1385 // we don't want to do this unecesarily - it acutally causes 1386 // the radio to repeate network selection and is costly 1387 // first check if we're already in automatic mode 1388 Message msg = obtainMessage(EVENT_CHECK_FOR_NETWORK_AUTOMATIC); 1389 msg.obj = response; 1390 mCi.getNetworkSelectionMode(msg); 1391 } 1392 onCheckForNetworkSelectionModeAutomatic(Message fromRil)1393 private void onCheckForNetworkSelectionModeAutomatic(Message fromRil) { 1394 AsyncResult ar = (AsyncResult)fromRil.obj; 1395 Message response = (Message)ar.userObj; 1396 boolean doAutomatic = true; 1397 if (ar.exception == null && ar.result != null) { 1398 try { 1399 int[] modes = (int[])ar.result; 1400 if (modes[0] == 0) { 1401 // already confirmed to be in automatic mode - don't resend 1402 doAutomatic = false; 1403 } 1404 } catch (Exception e) { 1405 // send the setting on error 1406 } 1407 } 1408 1409 // wrap the response message in our own message along with 1410 // an empty string (to indicate automatic selection) for the 1411 // operator's id. 1412 NetworkSelectMessage nsm = new NetworkSelectMessage(); 1413 nsm.message = response; 1414 nsm.operatorNumeric = ""; 1415 nsm.operatorAlphaLong = ""; 1416 nsm.operatorAlphaShort = ""; 1417 1418 if (doAutomatic) { 1419 Message msg = obtainMessage(EVENT_SET_NETWORK_AUTOMATIC_COMPLETE, nsm); 1420 mCi.setNetworkSelectionModeAutomatic(msg); 1421 } else { 1422 Rlog.d(LOG_TAG, "setNetworkSelectionModeAutomatic - already auto, ignoring"); 1423 // let the calling application know that the we are ignoring automatic mode switch. 1424 if (nsm.message != null) { 1425 nsm.message.arg1 = ALREADY_IN_AUTO_SELECTION; 1426 } 1427 1428 ar.userObj = nsm; 1429 handleSetSelectNetwork(ar); 1430 } 1431 1432 updateSavedNetworkOperator(nsm); 1433 } 1434 1435 /** 1436 * Query the radio for the current network selection mode. 1437 * 1438 * Return values: 1439 * 0 - automatic. 1440 * 1 - manual. 1441 */ getNetworkSelectionMode(Message message)1442 public void getNetworkSelectionMode(Message message) { 1443 mCi.getNetworkSelectionMode(message); 1444 } 1445 getClientRequestStats()1446 public List<ClientRequestStats> getClientRequestStats() { 1447 return mCi.getClientRequestStats(); 1448 } 1449 1450 /** 1451 * Manually selects a network. <code>response</code> is 1452 * dispatched when this is complete. <code>response.obj</code> will be 1453 * an AsyncResult, and <code>response.obj.exception</code> will be non-null 1454 * on failure. 1455 * 1456 * @see #setNetworkSelectionModeAutomatic(Message) 1457 */ 1458 @UnsupportedAppUsage selectNetworkManually(OperatorInfo network, boolean persistSelection, Message response)1459 public void selectNetworkManually(OperatorInfo network, boolean persistSelection, 1460 Message response) { 1461 // wrap the response message in our own message along with 1462 // the operator's id. 1463 NetworkSelectMessage nsm = new NetworkSelectMessage(); 1464 nsm.message = response; 1465 nsm.operatorNumeric = network.getOperatorNumeric(); 1466 nsm.operatorAlphaLong = network.getOperatorAlphaLong(); 1467 nsm.operatorAlphaShort = network.getOperatorAlphaShort(); 1468 1469 Message msg = obtainMessage(EVENT_SET_NETWORK_MANUAL_COMPLETE, nsm); 1470 mCi.setNetworkSelectionModeManual(network.getOperatorNumeric(), network.getRan(), msg); 1471 1472 if (persistSelection) { 1473 updateSavedNetworkOperator(nsm); 1474 } else { 1475 clearSavedNetworkSelection(); 1476 updateManualNetworkSelection(nsm); 1477 } 1478 } 1479 1480 /** 1481 * Registration point for emergency call/callback mode start. Message.obj is AsyncResult and 1482 * Message.obj.result will be Integer indicating start of call by value 1 or end of call by 1483 * value 0 1484 * @param h handler to notify 1485 * @param what what code of message when delivered 1486 * @param obj placed in Message.obj.userObj 1487 */ registerForEmergencyCallToggle(Handler h, int what, Object obj)1488 public void registerForEmergencyCallToggle(Handler h, int what, Object obj) { 1489 Registrant r = new Registrant(h, what, obj); 1490 mEmergencyCallToggledRegistrants.add(r); 1491 } 1492 unregisterForEmergencyCallToggle(Handler h)1493 public void unregisterForEmergencyCallToggle(Handler h) { 1494 mEmergencyCallToggledRegistrants.remove(h); 1495 } 1496 updateSavedNetworkOperator(NetworkSelectMessage nsm)1497 private void updateSavedNetworkOperator(NetworkSelectMessage nsm) { 1498 int subId = getSubId(); 1499 if (SubscriptionManager.isValidSubscriptionId(subId)) { 1500 // open the shared preferences editor, and write the value. 1501 // nsm.operatorNumeric is "" if we're in automatic.selection. 1502 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); 1503 SharedPreferences.Editor editor = sp.edit(); 1504 editor.putString(NETWORK_SELECTION_KEY + subId, nsm.operatorNumeric); 1505 editor.putString(NETWORK_SELECTION_NAME_KEY + subId, nsm.operatorAlphaLong); 1506 editor.putString(NETWORK_SELECTION_SHORT_KEY + subId, nsm.operatorAlphaShort); 1507 1508 // commit and log the result. 1509 if (!editor.commit()) { 1510 Rlog.e(LOG_TAG, "failed to commit network selection preference"); 1511 } 1512 } else { 1513 Rlog.e(LOG_TAG, "Cannot update network selection preference due to invalid subId " + 1514 subId); 1515 } 1516 } 1517 1518 /** 1519 * Update non-perisited manual network selection. 1520 * 1521 * @param nsm PLMN info of the selected network 1522 */ updateManualNetworkSelection(NetworkSelectMessage nsm)1523 protected void updateManualNetworkSelection(NetworkSelectMessage nsm) { 1524 Rlog.e(LOG_TAG, "updateManualNetworkSelection() should be overridden"); 1525 } 1526 1527 /** 1528 * Used to track the settings upon completion of the network change. 1529 */ handleSetSelectNetwork(AsyncResult ar)1530 private void handleSetSelectNetwork(AsyncResult ar) { 1531 // look for our wrapper within the asyncresult, skip the rest if it 1532 // is null. 1533 if (!(ar.userObj instanceof NetworkSelectMessage)) { 1534 Rlog.e(LOG_TAG, "unexpected result from user object."); 1535 return; 1536 } 1537 1538 NetworkSelectMessage nsm = (NetworkSelectMessage) ar.userObj; 1539 1540 // found the object, now we send off the message we had originally 1541 // attached to the request. 1542 if (nsm.message != null) { 1543 AsyncResult.forMessage(nsm.message, ar.result, ar.exception); 1544 nsm.message.sendToTarget(); 1545 } 1546 } 1547 1548 /** 1549 * Method to retrieve the saved operator from the Shared Preferences 1550 */ 1551 @NonNull getSavedNetworkSelection()1552 public OperatorInfo getSavedNetworkSelection() { 1553 // open the shared preferences and search with our key. 1554 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); 1555 String numeric = sp.getString(NETWORK_SELECTION_KEY + getSubId(), ""); 1556 String name = sp.getString(NETWORK_SELECTION_NAME_KEY + getSubId(), ""); 1557 String shrt = sp.getString(NETWORK_SELECTION_SHORT_KEY + getSubId(), ""); 1558 return new OperatorInfo(name, shrt, numeric); 1559 } 1560 1561 /** 1562 * Clears the saved network selection. 1563 */ clearSavedNetworkSelection()1564 private void clearSavedNetworkSelection() { 1565 // open the shared preferences and search with our key. 1566 PreferenceManager.getDefaultSharedPreferences(getContext()).edit(). 1567 remove(NETWORK_SELECTION_KEY + getSubId()). 1568 remove(NETWORK_SELECTION_NAME_KEY + getSubId()). 1569 remove(NETWORK_SELECTION_SHORT_KEY + getSubId()).commit(); 1570 } 1571 1572 /** 1573 * Method to restore the previously saved operator id, or reset to 1574 * automatic selection, all depending upon the value in the shared 1575 * preferences. 1576 */ restoreSavedNetworkSelection(Message response)1577 private void restoreSavedNetworkSelection(Message response) { 1578 // retrieve the operator 1579 OperatorInfo networkSelection = getSavedNetworkSelection(); 1580 1581 // set to auto if the id is empty, otherwise select the network. 1582 if (networkSelection == null || TextUtils.isEmpty(networkSelection.getOperatorNumeric())) { 1583 setNetworkSelectionModeAutomatic(response); 1584 } else { 1585 selectNetworkManually(networkSelection, true, response); 1586 } 1587 } 1588 1589 /** 1590 * Saves CLIR setting so that we can re-apply it as necessary 1591 * (in case the RIL resets it across reboots). 1592 */ saveClirSetting(int commandInterfaceCLIRMode)1593 public void saveClirSetting(int commandInterfaceCLIRMode) { 1594 // Open the shared preferences editor, and write the value. 1595 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); 1596 SharedPreferences.Editor editor = sp.edit(); 1597 editor.putInt(CLIR_KEY + getSubId(), commandInterfaceCLIRMode); 1598 Rlog.i(LOG_TAG, "saveClirSetting: " + CLIR_KEY + getSubId() + "=" 1599 + commandInterfaceCLIRMode); 1600 1601 // Commit and log the result. 1602 if (!editor.commit()) { 1603 Rlog.e(LOG_TAG, "Failed to commit CLIR preference"); 1604 } 1605 } 1606 1607 /** 1608 * For unit tests; don't send notifications to "Phone" 1609 * mailbox registrants if true. 1610 */ setUnitTestMode(boolean f)1611 private void setUnitTestMode(boolean f) { 1612 mUnitTestMode = f; 1613 } 1614 1615 /** 1616 * @return true If unit test mode is enabled 1617 */ getUnitTestMode()1618 public boolean getUnitTestMode() { 1619 return mUnitTestMode; 1620 } 1621 1622 /** 1623 * To be invoked when a voice call Connection disconnects. 1624 * 1625 * Subclasses of Phone probably want to replace this with a 1626 * version scoped to their packages 1627 */ notifyDisconnectP(Connection cn)1628 protected void notifyDisconnectP(Connection cn) { 1629 AsyncResult ar = new AsyncResult(null, cn, null); 1630 mDisconnectRegistrants.notifyRegistrants(ar); 1631 } 1632 1633 /** 1634 * Register for ServiceState changed. 1635 * Message.obj will contain an AsyncResult. 1636 * AsyncResult.result will be a ServiceState instance 1637 */ 1638 @UnsupportedAppUsage registerForServiceStateChanged( Handler h, int what, Object obj)1639 public void registerForServiceStateChanged( 1640 Handler h, int what, Object obj) { 1641 mServiceStateRegistrants.add(h, what, obj); 1642 } 1643 1644 /** 1645 * Unregisters for ServiceStateChange notification. 1646 * Extraneous calls are tolerated silently 1647 */ 1648 @UnsupportedAppUsage unregisterForServiceStateChanged(Handler h)1649 public void unregisterForServiceStateChanged(Handler h) { 1650 mServiceStateRegistrants.remove(h); 1651 } 1652 1653 /** 1654 * Notifies when out-band ringback tone is needed.<p> 1655 * 1656 * Messages received from this: 1657 * Message.obj will be an AsyncResult 1658 * AsyncResult.userObj = obj 1659 * AsyncResult.result = boolean, true to start play ringback tone 1660 * and false to stop. <p> 1661 */ 1662 @UnsupportedAppUsage registerForRingbackTone(Handler h, int what, Object obj)1663 public void registerForRingbackTone(Handler h, int what, Object obj) { 1664 mCi.registerForRingbackTone(h, what, obj); 1665 } 1666 1667 /** 1668 * Unregisters for ringback tone notification. 1669 */ 1670 @UnsupportedAppUsage unregisterForRingbackTone(Handler h)1671 public void unregisterForRingbackTone(Handler h) { 1672 mCi.unregisterForRingbackTone(h); 1673 } 1674 1675 /** 1676 * Notifies when out-band on-hold tone is needed.<p> 1677 * 1678 * Messages received from this: 1679 * Message.obj will be an AsyncResult 1680 * AsyncResult.userObj = obj 1681 * AsyncResult.result = boolean, true to start play on-hold tone 1682 * and false to stop. <p> 1683 */ registerForOnHoldTone(Handler h, int what, Object obj)1684 public void registerForOnHoldTone(Handler h, int what, Object obj) { 1685 } 1686 1687 /** 1688 * Unregisters for on-hold tone notification. 1689 */ unregisterForOnHoldTone(Handler h)1690 public void unregisterForOnHoldTone(Handler h) { 1691 } 1692 1693 /** 1694 * Registers the handler to reset the uplink mute state to get 1695 * uplink audio. 1696 */ registerForResendIncallMute(Handler h, int what, Object obj)1697 public void registerForResendIncallMute(Handler h, int what, Object obj) { 1698 mCi.registerForResendIncallMute(h, what, obj); 1699 } 1700 1701 /** 1702 * Unregisters for resend incall mute notifications. 1703 */ unregisterForResendIncallMute(Handler h)1704 public void unregisterForResendIncallMute(Handler h) { 1705 mCi.unregisterForResendIncallMute(h); 1706 } 1707 1708 /** 1709 * Registers for CellInfo changed. 1710 * Message.obj will contain an AsyncResult. 1711 * AsyncResult.result will be a List<CellInfo> instance 1712 */ registerForCellInfo( Handler h, int what, Object obj)1713 public void registerForCellInfo( 1714 Handler h, int what, Object obj) { 1715 mCellInfoRegistrants.add(h, what, obj); 1716 } 1717 1718 /** 1719 * Unregisters for CellInfo notification. 1720 * Extraneous calls are tolerated silently 1721 */ unregisterForCellInfo(Handler h)1722 public void unregisterForCellInfo(Handler h) { 1723 mCellInfoRegistrants.remove(h); 1724 } 1725 1726 /** 1727 * Enables or disables echo suppression. 1728 */ setEchoSuppressionEnabled()1729 public void setEchoSuppressionEnabled() { 1730 // no need for regular phone 1731 } 1732 1733 /** 1734 * Subclasses of Phone probably want to replace this with a 1735 * version scoped to their packages 1736 */ notifyServiceStateChangedP(ServiceState ss)1737 protected void notifyServiceStateChangedP(ServiceState ss) { 1738 AsyncResult ar = new AsyncResult(null, ss, null); 1739 mServiceStateRegistrants.notifyRegistrants(ar); 1740 1741 mNotifier.notifyServiceState(this); 1742 } 1743 1744 /** 1745 * Version of notifyServiceStateChangedP which allows us to specify the subId. This is used when 1746 * we send out a final ServiceState update when a phone's subId becomes invalid. 1747 */ notifyServiceStateChangedPForSubId(ServiceState ss, int subId)1748 protected void notifyServiceStateChangedPForSubId(ServiceState ss, int subId) { 1749 AsyncResult ar = new AsyncResult(null, ss, null); 1750 mServiceStateRegistrants.notifyRegistrants(ar); 1751 1752 mNotifier.notifyServiceStateForSubId(this, ss, subId); 1753 } 1754 1755 /** 1756 * If this is a simulated phone interface, returns a SimulatedRadioControl. 1757 * @return SimulatedRadioControl if this is a simulated interface; 1758 * otherwise, null. 1759 */ getSimulatedRadioControl()1760 public SimulatedRadioControl getSimulatedRadioControl() { 1761 return mSimulatedRadioControl; 1762 } 1763 1764 /** 1765 * Verifies the current thread is the same as the thread originally 1766 * used in the initialization of this instance. Throws RuntimeException 1767 * if not. 1768 * 1769 * @exception RuntimeException if the current thread is not 1770 * the thread that originally obtained this Phone instance. 1771 */ checkCorrectThread(Handler h)1772 private void checkCorrectThread(Handler h) { 1773 if (h.getLooper() != mLooper) { 1774 throw new RuntimeException( 1775 "com.android.internal.telephony.Phone must be used from within one thread"); 1776 } 1777 } 1778 1779 /** 1780 * Set the properties by matching the carrier string in 1781 * a string-array resource 1782 */ getLocaleFromCarrierProperties()1783 @Nullable Locale getLocaleFromCarrierProperties() { 1784 String carrier = SystemProperties.get("ro.carrier"); 1785 1786 if (null == carrier || 0 == carrier.length() || "unknown".equals(carrier)) { 1787 return null; 1788 } 1789 1790 CharSequence[] carrierLocales = mContext.getResources().getTextArray( 1791 R.array.carrier_properties); 1792 1793 for (int i = 0; i < carrierLocales.length; i+=3) { 1794 String c = carrierLocales[i].toString(); 1795 if (carrier.equals(c)) { 1796 return Locale.forLanguageTag(carrierLocales[i + 1].toString().replace('_', '-')); 1797 } 1798 } 1799 1800 return null; 1801 } 1802 1803 /** 1804 * Get current coarse-grained voice call state. 1805 * Use {@link #registerForPreciseCallStateChanged(Handler, int, Object) 1806 * registerForPreciseCallStateChanged()} for change notification. <p> 1807 * If the phone has an active call and call waiting occurs, 1808 * then the phone state is RINGING not OFFHOOK 1809 * <strong>Note:</strong> 1810 * This registration point provides notification of finer-grained 1811 * changes.<p> 1812 */ 1813 @UnsupportedAppUsage getState()1814 public abstract PhoneConstants.State getState(); 1815 1816 /** 1817 * Retrieves the IccFileHandler of the Phone instance 1818 */ 1819 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getIccFileHandler()1820 public IccFileHandler getIccFileHandler(){ 1821 UiccCardApplication uiccApplication = mUiccApplication.get(); 1822 IccFileHandler fh; 1823 1824 if (uiccApplication == null) { 1825 Rlog.d(LOG_TAG, "getIccFileHandler: uiccApplication == null, return null"); 1826 fh = null; 1827 } else { 1828 fh = uiccApplication.getIccFileHandler(); 1829 } 1830 1831 Rlog.d(LOG_TAG, "getIccFileHandler: fh=" + fh); 1832 return fh; 1833 } 1834 1835 /* 1836 * Retrieves the Handler of the Phone instance 1837 */ getHandler()1838 public Handler getHandler() { 1839 return this; 1840 } 1841 1842 /** 1843 * Update the phone object if the voice radio technology has changed 1844 * 1845 * @param voiceRadioTech The new voice radio technology 1846 */ updatePhoneObject(int voiceRadioTech)1847 public void updatePhoneObject(int voiceRadioTech) { 1848 } 1849 1850 /** 1851 * Retrieves the ServiceStateTracker of the phone instance. 1852 */ 1853 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getServiceStateTracker()1854 public ServiceStateTracker getServiceStateTracker() { 1855 return null; 1856 } 1857 1858 /** 1859 * Check whether the radio is off for thermal reason. 1860 * 1861 * @return {@code true} only if thermal mitigation is one of the reason for which radio is off. 1862 */ isRadioOffForThermalMitigation()1863 public boolean isRadioOffForThermalMitigation() { 1864 ServiceStateTracker sst = getServiceStateTracker(); 1865 return sst != null && sst.getRadioPowerOffReasons() 1866 .contains(Phone.RADIO_POWER_REASON_THERMAL); 1867 } 1868 1869 /** 1870 * Retrieves the EmergencyNumberTracker of the phone instance. 1871 */ getEmergencyNumberTracker()1872 public EmergencyNumberTracker getEmergencyNumberTracker() { 1873 return null; 1874 } 1875 1876 /** 1877 * Get call tracker 1878 */ 1879 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getCallTracker()1880 public CallTracker getCallTracker() { 1881 return null; 1882 } 1883 1884 /** 1885 * @return The instance of transport manager 1886 */ getTransportManager()1887 public TransportManager getTransportManager() { 1888 return null; 1889 } 1890 1891 /** 1892 * Retrieves the DeviceStateMonitor of the phone instance. 1893 */ getDeviceStateMonitor()1894 public DeviceStateMonitor getDeviceStateMonitor() { 1895 return null; 1896 } 1897 1898 /** 1899 * Retrieves the DisplayInfoController of the phone instance. 1900 */ getDisplayInfoController()1901 public DisplayInfoController getDisplayInfoController() { 1902 return null; 1903 } 1904 1905 /** 1906 * Update voice activation state 1907 */ setVoiceActivationState(int state)1908 public void setVoiceActivationState(int state) { 1909 mSimActivationTracker.setVoiceActivationState(state); 1910 } 1911 /** 1912 * Update data activation state 1913 */ setDataActivationState(int state)1914 public void setDataActivationState(int state) { 1915 mSimActivationTracker.setDataActivationState(state); 1916 } 1917 1918 /** 1919 * Returns voice activation state 1920 */ getVoiceActivationState()1921 public int getVoiceActivationState() { 1922 return mSimActivationTracker.getVoiceActivationState(); 1923 } 1924 /** 1925 * Returns data activation state 1926 */ getDataActivationState()1927 public int getDataActivationState() { 1928 return mSimActivationTracker.getDataActivationState(); 1929 } 1930 1931 /** 1932 * Update voice mail count related fields and notify listeners 1933 */ updateVoiceMail()1934 public void updateVoiceMail() { 1935 Rlog.e(LOG_TAG, "updateVoiceMail() should be overridden"); 1936 } 1937 getCurrentUiccAppType()1938 public AppType getCurrentUiccAppType() { 1939 UiccCardApplication currentApp = mUiccApplication.get(); 1940 if (currentApp != null) { 1941 return currentApp.getType(); 1942 } 1943 return AppType.APPTYPE_UNKNOWN; 1944 } 1945 1946 /** 1947 * Returns the ICC card interface for this phone, or null 1948 * if not applicable to underlying technology. 1949 */ 1950 @UnsupportedAppUsage getIccCard()1951 public IccCard getIccCard() { 1952 return null; 1953 //throw new Exception("getIccCard Shouldn't be called from Phone"); 1954 } 1955 1956 /** 1957 * Retrieves the serial number of the ICC, if applicable. Returns only the decimal digits before 1958 * the first hex digit in the ICC ID. 1959 */ 1960 @UnsupportedAppUsage getIccSerialNumber()1961 public String getIccSerialNumber() { 1962 IccRecords r = mIccRecords.get(); 1963 return (r != null) ? r.getIccId() : null; 1964 } 1965 1966 /** 1967 * Retrieves the full serial number of the ICC (including hex digits), if applicable. 1968 */ getFullIccSerialNumber()1969 public String getFullIccSerialNumber() { 1970 IccRecords r = mIccRecords.get(); 1971 return (r != null) ? r.getFullIccId() : null; 1972 } 1973 1974 /** 1975 * Returns SIM record load state. Use 1976 * <code>getSimCard().registerForReady()</code> for change notification. 1977 * 1978 * @return true if records from the SIM have been loaded and are 1979 * available (if applicable). If not applicable to the underlying 1980 * technology, returns true as well. 1981 */ getIccRecordsLoaded()1982 public boolean getIccRecordsLoaded() { 1983 IccRecords r = mIccRecords.get(); 1984 return (r != null) ? r.getRecordsLoaded() : false; 1985 } 1986 1987 /** Set the minimum interval for CellInfo requests to the modem */ setCellInfoMinInterval(int interval)1988 public void setCellInfoMinInterval(int interval) { 1989 getServiceStateTracker().setCellInfoMinInterval(interval); 1990 } 1991 1992 /** 1993 * @return the last known CellInfo 1994 */ getAllCellInfo()1995 public List<CellInfo> getAllCellInfo() { 1996 return getServiceStateTracker().getAllCellInfo(); 1997 } 1998 1999 /** 2000 * @param workSource calling WorkSource 2001 * @param rspMsg the response message containing the cell info 2002 */ requestCellInfoUpdate(WorkSource workSource, Message rspMsg)2003 public void requestCellInfoUpdate(WorkSource workSource, Message rspMsg) { 2004 getServiceStateTracker().requestAllCellInfo(workSource, rspMsg); 2005 } 2006 2007 /** 2008 * Returns the current CellIdentity if known 2009 */ getCurrentCellIdentity()2010 public CellIdentity getCurrentCellIdentity() { 2011 return getServiceStateTracker().getCellIdentity(); 2012 } 2013 2014 /** 2015 * @param workSource calling WorkSource 2016 * @param rspMsg the response message containing the cell location 2017 */ getCellIdentity(WorkSource workSource, Message rspMsg)2018 public void getCellIdentity(WorkSource workSource, Message rspMsg) { 2019 getServiceStateTracker().requestCellIdentity(workSource, rspMsg); 2020 } 2021 2022 /** 2023 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2024 * PhoneStateListener.onCellInfoChanged} will be invoked. 2025 * 2026 * The default, 0, means invoke onCellInfoChanged when any of the reported 2027 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2028 * A onCellInfoChanged. 2029 * 2030 * @param rateInMillis the rate 2031 * @param workSource calling WorkSource 2032 */ setCellInfoListRate(int rateInMillis, WorkSource workSource)2033 public void setCellInfoListRate(int rateInMillis, WorkSource workSource) { 2034 mCi.setCellInfoListRate(rateInMillis, null, workSource); 2035 } 2036 2037 /** 2038 * Get voice message waiting indicator status. No change notification 2039 * available on this interface. Use PhoneStateNotifier or similar instead. 2040 * 2041 * @return true if there is a voice message waiting 2042 */ getMessageWaitingIndicator()2043 public boolean getMessageWaitingIndicator() { 2044 return mVmCount != 0; 2045 } 2046 2047 /** 2048 * Retrieves manually selected network info. 2049 */ getManualNetworkSelectionPlmn()2050 public String getManualNetworkSelectionPlmn() { 2051 return null; 2052 } 2053 2054 getCallForwardingIndicatorFromSharedPref()2055 private int getCallForwardingIndicatorFromSharedPref() { 2056 int status = IccRecords.CALL_FORWARDING_STATUS_DISABLED; 2057 int subId = getSubId(); 2058 if (SubscriptionManager.isValidSubscriptionId(subId)) { 2059 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); 2060 status = sp.getInt(CF_STATUS + subId, IccRecords.CALL_FORWARDING_STATUS_UNKNOWN); 2061 Rlog.d(LOG_TAG, "getCallForwardingIndicatorFromSharedPref: for subId " + subId + "= " + 2062 status); 2063 // Check for old preference if status is UNKNOWN for current subId. This part of the 2064 // code is needed only when upgrading from M to N. 2065 if (status == IccRecords.CALL_FORWARDING_STATUS_UNKNOWN) { 2066 String subscriberId = sp.getString(CF_ID, null); 2067 if (subscriberId != null) { 2068 String currentSubscriberId = getSubscriberId(); 2069 2070 if (subscriberId.equals(currentSubscriberId)) { 2071 // get call forwarding status from preferences 2072 status = sp.getInt(CF_STATUS, IccRecords.CALL_FORWARDING_STATUS_DISABLED); 2073 setCallForwardingIndicatorInSharedPref( 2074 status == IccRecords.CALL_FORWARDING_STATUS_ENABLED ? true : false); 2075 Rlog.d(LOG_TAG, "getCallForwardingIndicatorFromSharedPref: " + status); 2076 } else { 2077 Rlog.d(LOG_TAG, "getCallForwardingIndicatorFromSharedPref: returning " + 2078 "DISABLED as status for matching subscriberId not found"); 2079 } 2080 2081 // get rid of old preferences. 2082 SharedPreferences.Editor editor = sp.edit(); 2083 editor.remove(CF_ID); 2084 editor.remove(CF_STATUS); 2085 editor.apply(); 2086 } 2087 } 2088 } else { 2089 Rlog.e(LOG_TAG, "getCallForwardingIndicatorFromSharedPref: invalid subId " + subId); 2090 } 2091 return status; 2092 } 2093 setCallForwardingIndicatorInSharedPref(boolean enable)2094 private void setCallForwardingIndicatorInSharedPref(boolean enable) { 2095 int status = enable ? IccRecords.CALL_FORWARDING_STATUS_ENABLED : 2096 IccRecords.CALL_FORWARDING_STATUS_DISABLED; 2097 int subId = getSubId(); 2098 Rlog.i(LOG_TAG, "setCallForwardingIndicatorInSharedPref: Storing status = " + status + 2099 " in pref " + CF_STATUS + subId); 2100 2101 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); 2102 SharedPreferences.Editor editor = sp.edit(); 2103 editor.putInt(CF_STATUS + subId, status); 2104 editor.apply(); 2105 } 2106 setVoiceCallForwardingFlag(int line, boolean enable, String number)2107 public void setVoiceCallForwardingFlag(int line, boolean enable, String number) { 2108 setCallForwardingIndicatorInSharedPref(enable); 2109 IccRecords r = getIccRecords(); 2110 if (r != null) { 2111 r.setVoiceCallForwardingFlag(line, enable, number); 2112 } 2113 notifyCallForwardingIndicator(); 2114 } 2115 2116 /** 2117 * Set the voice call forwarding flag for GSM/UMTS and the like SIMs 2118 * 2119 * @param r to enable/disable 2120 * @param line to enable/disable 2121 * @param enable 2122 * @param number to which CFU is enabled 2123 */ setVoiceCallForwardingFlag(IccRecords r, int line, boolean enable, String number)2124 public void setVoiceCallForwardingFlag(IccRecords r, int line, boolean enable, 2125 String number) { 2126 setCallForwardingIndicatorInSharedPref(enable); 2127 if (r != null) { 2128 r.setVoiceCallForwardingFlag(line, enable, number); 2129 } 2130 notifyCallForwardingIndicator(); 2131 } 2132 2133 /** 2134 * Get voice call forwarding indicator status. No change notification 2135 * available on this interface. Use PhoneStateNotifier or similar instead. 2136 * 2137 * @return true if there is a voice call forwarding 2138 */ getCallForwardingIndicator()2139 public boolean getCallForwardingIndicator() { 2140 if (getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { 2141 Rlog.e(LOG_TAG, "getCallForwardingIndicator: not possible in CDMA"); 2142 return false; 2143 } 2144 IccRecords r = getIccRecords(); 2145 int callForwardingIndicator = IccRecords.CALL_FORWARDING_STATUS_UNKNOWN; 2146 if (r != null) { 2147 callForwardingIndicator = r.getVoiceCallForwardingFlag(); 2148 } 2149 if (callForwardingIndicator == IccRecords.CALL_FORWARDING_STATUS_UNKNOWN) { 2150 callForwardingIndicator = getCallForwardingIndicatorFromSharedPref(); 2151 } 2152 Rlog.v(LOG_TAG, "getCallForwardingIndicator: iccForwardingFlag=" + (r != null 2153 ? r.getVoiceCallForwardingFlag() : "null") + ", sharedPrefFlag=" 2154 + getCallForwardingIndicatorFromSharedPref()); 2155 return (callForwardingIndicator == IccRecords.CALL_FORWARDING_STATUS_ENABLED); 2156 } 2157 getCarrierSignalAgent()2158 public CarrierSignalAgent getCarrierSignalAgent() { 2159 return mCarrierSignalAgent; 2160 } 2161 getCarrierActionAgent()2162 public CarrierActionAgent getCarrierActionAgent() { 2163 return mCarrierActionAgent; 2164 } 2165 2166 /** 2167 * Query the CDMA roaming preference setting. 2168 * 2169 * @param response is callback message to report one of TelephonyManager#CDMA_ROAMING_MODE_* 2170 */ queryCdmaRoamingPreference(Message response)2171 public void queryCdmaRoamingPreference(Message response) { 2172 mCi.queryCdmaRoamingPreference(response); 2173 } 2174 2175 /** 2176 * Get the CDMA subscription mode setting. 2177 * 2178 * @param response is callback message to report one of TelephonyManager#CDMA_SUBSCRIPTION_* 2179 */ queryCdmaSubscriptionMode(Message response)2180 public void queryCdmaSubscriptionMode(Message response) { 2181 mCi.getCdmaSubscriptionSource(response); 2182 } 2183 2184 /** 2185 * Get current signal strength. No change notification available on this 2186 * interface. Use <code>PhoneStateNotifier</code> or an equivalent. 2187 * An ASU is 0-31 or -1 if unknown (for GSM, dBm = -113 - 2 * asu). 2188 * The following special values are defined:</p> 2189 * <ul><li>0 means "-113 dBm or less".</li> 2190 * <li>31 means "-51 dBm or greater".</li></ul> 2191 * 2192 * @return Current signal strength as SignalStrength 2193 */ getSignalStrength()2194 public SignalStrength getSignalStrength() { 2195 ServiceStateTracker sst = getServiceStateTracker(); 2196 if (sst == null) { 2197 return new SignalStrength(); 2198 } else { 2199 return sst.getSignalStrength(); 2200 } 2201 } 2202 2203 /** 2204 * @return true, if the device is in a state where both voice and data 2205 * are supported simultaneously. This can change based on location or network condition. 2206 */ isConcurrentVoiceAndDataAllowed()2207 public boolean isConcurrentVoiceAndDataAllowed() { 2208 ServiceStateTracker sst = getServiceStateTracker(); 2209 return sst == null ? false : sst.isConcurrentVoiceAndDataAllowed(); 2210 } 2211 2212 /** 2213 * Requests to set the CDMA roaming preference 2214 * @param cdmaRoamingType one of TelephonyManager#CDMA_ROAMING_MODE_* 2215 * @param response is callback message 2216 */ setCdmaRoamingPreference(int cdmaRoamingType, Message response)2217 public void setCdmaRoamingPreference(int cdmaRoamingType, Message response) { 2218 mCi.setCdmaRoamingPreference(cdmaRoamingType, response); 2219 } 2220 2221 /** 2222 * Requests to set the CDMA subscription mode 2223 * @param cdmaSubscriptionType one of TelephonyManager#CDMA_SUBSCRIPTION_* 2224 * @param response is callback message 2225 */ setCdmaSubscriptionMode(int cdmaSubscriptionType, Message response)2226 public void setCdmaSubscriptionMode(int cdmaSubscriptionType, Message response) { 2227 mCi.setCdmaSubscriptionSource(cdmaSubscriptionType, response); 2228 } 2229 2230 /** 2231 * Get the effective allowed network types on the device. 2232 * 2233 * @return effective network type 2234 */ getEffectiveAllowedNetworkTypes()2235 private @TelephonyManager.NetworkTypeBitMask long getEffectiveAllowedNetworkTypes() { 2236 long allowedNetworkTypes = TelephonyManager.getAllNetworkTypesBitmask(); 2237 synchronized (mAllowedNetworkTypesForReasons) { 2238 for (long networkTypes : mAllowedNetworkTypesForReasons.values()) { 2239 allowedNetworkTypes = allowedNetworkTypes & networkTypes; 2240 } 2241 } 2242 if (!mIsCarrierNrSupported) { 2243 allowedNetworkTypes &= ~TelephonyManager.NETWORK_TYPE_BITMASK_NR; 2244 } 2245 logd("SubId" + getSubId() + ",getEffectiveAllowedNetworkTypes: " 2246 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); 2247 return allowedNetworkTypes; 2248 } 2249 2250 /** 2251 * Notify the latest allowed network types changed. 2252 */ notifyAllowedNetworkTypesChanged( @elephonyManager.AllowedNetworkTypesReason int reason)2253 public void notifyAllowedNetworkTypesChanged( 2254 @TelephonyManager.AllowedNetworkTypesReason int reason) { 2255 logd("SubId" + getSubId() + ",notifyAllowedNetworkTypesChanged: reason: " + reason 2256 + " value:" + TelephonyManager.convertNetworkTypeBitmaskToString( 2257 getAllowedNetworkTypes(reason))); 2258 mNotifier.notifyAllowedNetworkTypesChanged(this, reason, getAllowedNetworkTypes(reason)); 2259 } 2260 2261 /** 2262 * Is E-UTRA-NR Dual Connectivity enabled 2263 */ isNrDualConnectivityEnabled(Message message, WorkSource workSource)2264 public void isNrDualConnectivityEnabled(Message message, WorkSource workSource) { 2265 mCi.isNrDualConnectivityEnabled(message, workSource); 2266 } 2267 2268 /** 2269 * Enable/Disable E-UTRA-NR Dual Connectivity 2270 * @param nrDualConnectivityState expected NR dual connectivity state 2271 * This can be passed following states 2272 * <ol> 2273 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} 2274 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} 2275 * <li>Disable NR dual connectivity and force secondary cell to be released 2276 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} 2277 * </ol> 2278 */ setNrDualConnectivityState( @elephonyManager.NrDualConnectivityState int nrDualConnectivityState, Message message, WorkSource workSource)2279 public void setNrDualConnectivityState( 2280 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState, 2281 Message message, WorkSource workSource) { 2282 mCi.setNrDualConnectivityState(nrDualConnectivityState, message, workSource); 2283 } 2284 2285 /** 2286 * Get the allowed network types for a certain reason. 2287 * @param reason reason to configure allowed network types 2288 * @return the allowed network types. 2289 */ getAllowedNetworkTypes( @elephonyManager.AllowedNetworkTypesReason int reason)2290 public @TelephonyManager.NetworkTypeBitMask long getAllowedNetworkTypes( 2291 @TelephonyManager.AllowedNetworkTypesReason int reason) { 2292 long allowedNetworkTypes; 2293 long defaultAllowedNetworkTypes = RadioAccessFamily.getRafFromNetworkType( 2294 RILConstants.PREFERRED_NETWORK_MODE); 2295 2296 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { 2297 throw new IllegalArgumentException("AllowedNetworkTypes NumberFormat exception"); 2298 } 2299 2300 synchronized (mAllowedNetworkTypesForReasons) { 2301 allowedNetworkTypes = mAllowedNetworkTypesForReasons.getOrDefault( 2302 reason, 2303 defaultAllowedNetworkTypes); 2304 } 2305 if (!mIsCarrierNrSupported 2306 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER) { 2307 allowedNetworkTypes = updateAllowedNetworkTypeForCarrierWithCarrierConfig(); 2308 } 2309 logd("SubId" + getSubId() + ",get allowed network types " 2310 + convertAllowedNetworkTypeMapIndexToDbName(reason) 2311 + ": value = " + TelephonyManager.convertNetworkTypeBitmaskToString( 2312 allowedNetworkTypes)); 2313 return allowedNetworkTypes; 2314 } 2315 2316 /** 2317 * Loads the allowed network type from subscription database. 2318 */ loadAllowedNetworksFromSubscriptionDatabase()2319 public void loadAllowedNetworksFromSubscriptionDatabase() { 2320 // Try to load ALLOWED_NETWORK_TYPES from SIMINFO. 2321 if (SubscriptionController.getInstance() == null) { 2322 return; 2323 } 2324 2325 String result = SubscriptionController.getInstance().getSubscriptionProperty( 2326 getSubId(), 2327 SubscriptionManager.ALLOWED_NETWORK_TYPES); 2328 // After fw load network type from DB, do unlock if subId is valid. 2329 mIsAllowedNetworkTypesLoadedFromDb = SubscriptionManager.isValidSubscriptionId(getSubId()); 2330 if (result == null) { 2331 return; 2332 } 2333 2334 logd("SubId" + getSubId() + ",load allowed network types : value = " + result); 2335 Map<Integer, Long> oldAllowedNetworkTypes = new HashMap<>(mAllowedNetworkTypesForReasons); 2336 mAllowedNetworkTypesForReasons.clear(); 2337 try { 2338 // Format: "REASON=VALUE,REASON2=VALUE2" 2339 for (String pair : result.trim().split(",")) { 2340 String[] networkTypesValues = (pair.trim().toLowerCase()).split("="); 2341 if (networkTypesValues.length != 2) { 2342 Rlog.e(LOG_TAG, "Invalid ALLOWED_NETWORK_TYPES from DB, value = " + pair); 2343 continue; 2344 } 2345 int key = convertAllowedNetworkTypeDbNameToMapIndex(networkTypesValues[0]); 2346 long value = Long.parseLong(networkTypesValues[1]); 2347 if (key != INVALID_ALLOWED_NETWORK_TYPES 2348 && value != INVALID_ALLOWED_NETWORK_TYPES) { 2349 synchronized (mAllowedNetworkTypesForReasons) { 2350 mAllowedNetworkTypesForReasons.put(key, value); 2351 } 2352 if (!oldAllowedNetworkTypes.containsKey(key) 2353 || oldAllowedNetworkTypes.get(key) != value) { 2354 if (oldAllowedNetworkTypes.containsKey(key)) { 2355 oldAllowedNetworkTypes.remove(key); 2356 } 2357 notifyAllowedNetworkTypesChanged(key); 2358 } 2359 } 2360 } 2361 } catch (NumberFormatException e) { 2362 Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception" + e); 2363 } 2364 2365 for (int key : oldAllowedNetworkTypes.keySet()) { 2366 notifyAllowedNetworkTypesChanged(key); 2367 } 2368 } 2369 convertAllowedNetworkTypeDbNameToMapIndex(String name)2370 private int convertAllowedNetworkTypeDbNameToMapIndex(String name) { 2371 switch (name) { 2372 case ALLOWED_NETWORK_TYPES_TEXT_USER: 2373 return TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER; 2374 case ALLOWED_NETWORK_TYPES_TEXT_POWER: 2375 return TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER; 2376 case ALLOWED_NETWORK_TYPES_TEXT_CARRIER: 2377 return TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER; 2378 case ALLOWED_NETWORK_TYPES_TEXT_ENABLE_2G: 2379 return TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G; 2380 default: 2381 return INVALID_ALLOWED_NETWORK_TYPES; 2382 } 2383 } 2384 convertAllowedNetworkTypeMapIndexToDbName(int reason)2385 private String convertAllowedNetworkTypeMapIndexToDbName(int reason) { 2386 switch (reason) { 2387 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER: 2388 return ALLOWED_NETWORK_TYPES_TEXT_USER; 2389 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER: 2390 return ALLOWED_NETWORK_TYPES_TEXT_POWER; 2391 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER: 2392 return ALLOWED_NETWORK_TYPES_TEXT_CARRIER; 2393 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G: 2394 return ALLOWED_NETWORK_TYPES_TEXT_ENABLE_2G; 2395 default: 2396 return Integer.toString(INVALID_ALLOWED_NETWORK_TYPES); 2397 } 2398 } 2399 2400 private @TelephonyManager.NetworkTypeBitMask long updateAllowedNetworkTypeForCarrierWithCarrierConfig()2401 updateAllowedNetworkTypeForCarrierWithCarrierConfig() { 2402 long defaultAllowedNetworkTypes = RadioAccessFamily.getRafFromNetworkType( 2403 RILConstants.PREFERRED_NETWORK_MODE); 2404 long allowedNetworkTypes; 2405 synchronized (mAllowedNetworkTypesForReasons) { 2406 allowedNetworkTypes = mAllowedNetworkTypesForReasons.getOrDefault( 2407 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, 2408 defaultAllowedNetworkTypes); 2409 } 2410 if (mIsCarrierNrSupported) { 2411 return allowedNetworkTypes; 2412 } 2413 allowedNetworkTypes = allowedNetworkTypes & ~TelephonyManager.NETWORK_TYPE_BITMASK_NR; 2414 2415 logd("Allowed network types for 'carrier' reason is changed by carrier config = " 2416 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); 2417 return allowedNetworkTypes; 2418 } 2419 2420 /** 2421 * Requests to set the allowed network types for a specific reason 2422 * 2423 * @param reason reason to configure allowed network type 2424 * @param networkTypes one of the network types 2425 */ setAllowedNetworkTypes(@elephonyManager.AllowedNetworkTypesReason int reason, @TelephonyManager.NetworkTypeBitMask long networkTypes, Message response)2426 public void setAllowedNetworkTypes(@TelephonyManager.AllowedNetworkTypesReason int reason, 2427 @TelephonyManager.NetworkTypeBitMask long networkTypes, Message response) { 2428 int subId = getSubId(); 2429 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { 2430 loge("setAllowedNetworkTypes: Invalid allowed network type reason: " + reason); 2431 AsyncResult.forMessage(response, null, 2432 new CommandException(CommandException.Error.INVALID_ARGUMENTS)); 2433 response.sendToTarget(); 2434 return; 2435 } 2436 if (!SubscriptionManager.isUsableSubscriptionId(subId) 2437 || !mIsAllowedNetworkTypesLoadedFromDb) { 2438 loge("setAllowedNetworkTypes: no sim or network type is not loaded. SubscriptionId: " 2439 + subId + ", isNetworkTypeLoaded" + mIsAllowedNetworkTypesLoadedFromDb); 2440 AsyncResult.forMessage(response, null, 2441 new CommandException(CommandException.Error.MISSING_RESOURCE)); 2442 response.sendToTarget(); 2443 return; 2444 } 2445 String mapAsString = ""; 2446 synchronized (mAllowedNetworkTypesForReasons) { 2447 mAllowedNetworkTypesForReasons.put(reason, networkTypes); 2448 mapAsString = mAllowedNetworkTypesForReasons.keySet().stream() 2449 .map(key -> convertAllowedNetworkTypeMapIndexToDbName(key) + "=" 2450 + mAllowedNetworkTypesForReasons.get(key)) 2451 .collect(Collectors.joining(",")); 2452 } 2453 SubscriptionManager.setSubscriptionProperty(subId, 2454 SubscriptionManager.ALLOWED_NETWORK_TYPES, 2455 mapAsString); 2456 logd("setAllowedNetworkTypes: SubId" + subId + ",setAllowedNetworkTypes " + mapAsString); 2457 2458 updateAllowedNetworkTypes(response); 2459 notifyAllowedNetworkTypesChanged(reason); 2460 } 2461 updateAllowedNetworkTypes(Message response)2462 protected void updateAllowedNetworkTypes(Message response) { 2463 int modemRaf = getRadioAccessFamily(); 2464 if (modemRaf == RadioAccessFamily.RAF_UNKNOWN) { 2465 Rlog.d(LOG_TAG, "setPreferredNetworkType: Abort, unknown RAF: " 2466 + modemRaf); 2467 if (response != null) { 2468 CommandException ex; 2469 ex = new CommandException(CommandException.Error.GENERIC_FAILURE); 2470 AsyncResult.forMessage(response, null, ex); 2471 response.sendToTarget(); 2472 } 2473 return; 2474 } 2475 2476 int filteredRaf = (int) (modemRaf & getEffectiveAllowedNetworkTypes()); 2477 2478 logd("setAllowedNetworkTypes: modemRafBitMask = " + modemRaf 2479 + " ,modemRaf = " + TelephonyManager.convertNetworkTypeBitmaskToString(modemRaf) 2480 + " ,filteredRafBitMask = " + filteredRaf 2481 + " ,filteredRaf = " + TelephonyManager.convertNetworkTypeBitmaskToString( 2482 filteredRaf)); 2483 mCi.setAllowedNetworkTypesBitmap(filteredRaf, response); 2484 mPreferredNetworkTypeRegistrants.notifyRegistrants(); 2485 } 2486 2487 /** 2488 * Query the allowed network types bitmask setting 2489 * 2490 * @param response is callback message to report network types bitmask 2491 */ getAllowedNetworkTypesBitmask(Message response)2492 public void getAllowedNetworkTypesBitmask(Message response) { 2493 mCi.getAllowedNetworkTypesBitmap(response); 2494 } 2495 2496 /** 2497 * Register for preferred network type changes 2498 * 2499 * @param h Handler that receives the notification message. 2500 * @param what User-defined message code. 2501 * @param obj User object. 2502 */ registerForPreferredNetworkTypeChanged(Handler h, int what, Object obj)2503 public void registerForPreferredNetworkTypeChanged(Handler h, int what, Object obj) { 2504 checkCorrectThread(h); 2505 mPreferredNetworkTypeRegistrants.addUnique(h, what, obj); 2506 } 2507 2508 /** 2509 * Unregister for preferred network type changes. 2510 * 2511 * @param h Handler that should be unregistered. 2512 */ unregisterForPreferredNetworkTypeChanged(Handler h)2513 public void unregisterForPreferredNetworkTypeChanged(Handler h) { 2514 mPreferredNetworkTypeRegistrants.remove(h); 2515 } 2516 2517 /** 2518 * Get the cached value of the preferred network type setting 2519 */ getCachedAllowedNetworkTypesBitmask()2520 public int getCachedAllowedNetworkTypesBitmask() { 2521 if (mCi != null && mCi instanceof BaseCommands) { 2522 return ((BaseCommands) mCi).mAllowedNetworkTypesBitmask; 2523 } else { 2524 return RadioAccessFamily.getRafFromNetworkType(RILConstants.PREFERRED_NETWORK_MODE); 2525 } 2526 } 2527 2528 /** 2529 * Gets the default SMSC address. 2530 * 2531 * @param result Callback message contains the SMSC address. 2532 */ 2533 @UnsupportedAppUsage getSmscAddress(Message result)2534 public void getSmscAddress(Message result) { 2535 mCi.getSmscAddress(result); 2536 } 2537 2538 /** 2539 * Sets the default SMSC address. 2540 * 2541 * @param address new SMSC address 2542 * @param result Callback message is empty on completion 2543 */ 2544 @UnsupportedAppUsage setSmscAddress(String address, Message result)2545 public void setSmscAddress(String address, Message result) { 2546 mCi.setSmscAddress(address, result); 2547 } 2548 2549 /** 2550 * setTTYMode 2551 * sets a TTY mode option. 2552 * @param ttyMode is a one of the following: 2553 * - {@link com.android.internal.telephony.Phone#TTY_MODE_OFF} 2554 * - {@link com.android.internal.telephony.Phone#TTY_MODE_FULL} 2555 * - {@link com.android.internal.telephony.Phone#TTY_MODE_HCO} 2556 * - {@link com.android.internal.telephony.Phone#TTY_MODE_VCO} 2557 * @param onComplete a callback message when the action is completed 2558 */ setTTYMode(int ttyMode, Message onComplete)2559 public void setTTYMode(int ttyMode, Message onComplete) { 2560 mCi.setTTYMode(ttyMode, onComplete); 2561 } 2562 2563 /** 2564 * setUiTTYMode 2565 * sets a TTY mode option. 2566 * @param ttyMode is a one of the following: 2567 * - {@link com.android.internal.telephony.Phone#TTY_MODE_OFF} 2568 * - {@link com.android.internal.telephony.Phone#TTY_MODE_FULL} 2569 * - {@link com.android.internal.telephony.Phone#TTY_MODE_HCO} 2570 * - {@link com.android.internal.telephony.Phone#TTY_MODE_VCO} 2571 * @param onComplete a callback message when the action is completed 2572 */ setUiTTYMode(int uiTtyMode, Message onComplete)2573 public void setUiTTYMode(int uiTtyMode, Message onComplete) { 2574 Rlog.d(LOG_TAG, "unexpected setUiTTYMode method call"); 2575 } 2576 2577 /** 2578 * queryTTYMode 2579 * query the status of the TTY mode 2580 * 2581 * @param onComplete a callback message when the action is completed. 2582 */ queryTTYMode(Message onComplete)2583 public void queryTTYMode(Message onComplete) { 2584 mCi.queryTTYMode(onComplete); 2585 } 2586 2587 /** 2588 * Enable or disable enhanced Voice Privacy (VP). If enhanced VP is 2589 * disabled, normal VP is enabled. 2590 * 2591 * @param enable whether true or false to enable or disable. 2592 * @param onComplete a callback message when the action is completed. 2593 */ enableEnhancedVoicePrivacy(boolean enable, Message onComplete)2594 public void enableEnhancedVoicePrivacy(boolean enable, Message onComplete) { 2595 } 2596 2597 /** 2598 * Get the currently set Voice Privacy (VP) mode. 2599 * 2600 * @param onComplete a callback message when the action is completed. 2601 */ getEnhancedVoicePrivacy(Message onComplete)2602 public void getEnhancedVoicePrivacy(Message onComplete) { 2603 } 2604 2605 /** 2606 * Assign a specified band for RF configuration. 2607 * 2608 * @param bandMode one of BM_*_BAND 2609 * @param response is callback message 2610 */ setBandMode(int bandMode, Message response)2611 public void setBandMode(int bandMode, Message response) { 2612 mCi.setBandMode(bandMode, response); 2613 } 2614 2615 /** 2616 * Query the list of band mode supported by RF. 2617 * 2618 * @param response is callback message 2619 * ((AsyncResult)response.obj).result is an int[] where int[0] is 2620 * the size of the array and the rest of each element representing 2621 * one available BM_*_BAND 2622 */ queryAvailableBandMode(Message response)2623 public void queryAvailableBandMode(Message response) { 2624 mCi.queryAvailableBandMode(response); 2625 } 2626 2627 /** 2628 * Invokes RIL_REQUEST_OEM_HOOK_RAW on RIL implementation. 2629 * 2630 * @param data The data for the request. 2631 * @param response <strong>On success</strong>, 2632 * (byte[])(((AsyncResult)response.obj).result) 2633 * <strong>On failure</strong>, 2634 * (((AsyncResult)response.obj).result) == null and 2635 * (((AsyncResult)response.obj).exception) being an instance of 2636 * com.android.internal.telephony.gsm.CommandException 2637 * 2638 * @see #invokeOemRilRequestRaw(byte[], android.os.Message) 2639 * @deprecated OEM needs a vendor-extension hal and their apps should use that instead 2640 */ 2641 @UnsupportedAppUsage 2642 @Deprecated invokeOemRilRequestRaw(byte[] data, Message response)2643 public void invokeOemRilRequestRaw(byte[] data, Message response) { 2644 mCi.invokeOemRilRequestRaw(data, response); 2645 } 2646 2647 /** 2648 * Invokes RIL_REQUEST_OEM_HOOK_Strings on RIL implementation. 2649 * 2650 * @param strings The strings to make available as the request data. 2651 * @param response <strong>On success</strong>, "response" bytes is 2652 * made available as: 2653 * (String[])(((AsyncResult)response.obj).result). 2654 * <strong>On failure</strong>, 2655 * (((AsyncResult)response.obj).result) == null and 2656 * (((AsyncResult)response.obj).exception) being an instance of 2657 * com.android.internal.telephony.gsm.CommandException 2658 * 2659 * @see #invokeOemRilRequestStrings(java.lang.String[], android.os.Message) 2660 * @deprecated OEM needs a vendor-extension hal and their apps should use that instead 2661 */ 2662 @UnsupportedAppUsage 2663 @Deprecated invokeOemRilRequestStrings(String[] strings, Message response)2664 public void invokeOemRilRequestStrings(String[] strings, Message response) { 2665 mCi.invokeOemRilRequestStrings(strings, response); 2666 } 2667 2668 /** 2669 * Read one of the NV items defined in {@link RadioNVItems} / {@code ril_nv_items.h}. 2670 * Used for device configuration by some CDMA operators. 2671 * 2672 * @param itemID the ID of the item to read 2673 * @param response callback message with the String response in the obj field 2674 * @param workSource calling WorkSource 2675 */ nvReadItem(int itemID, Message response, WorkSource workSource)2676 public void nvReadItem(int itemID, Message response, WorkSource workSource) { 2677 mCi.nvReadItem(itemID, response, workSource); 2678 } 2679 2680 /** 2681 * Write one of the NV items defined in {@link RadioNVItems} / {@code ril_nv_items.h}. 2682 * Used for device configuration by some CDMA operators. 2683 * 2684 * @param itemID the ID of the item to read 2685 * @param itemValue the value to write, as a String 2686 * @param response Callback message. 2687 * @param workSource calling WorkSource 2688 */ nvWriteItem(int itemID, String itemValue, Message response, WorkSource workSource)2689 public void nvWriteItem(int itemID, String itemValue, Message response, 2690 WorkSource workSource) { 2691 mCi.nvWriteItem(itemID, itemValue, response, workSource); 2692 } 2693 2694 /** 2695 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 2696 * Used for device configuration by some CDMA operators. 2697 * 2698 * @param preferredRoamingList byte array containing the new PRL 2699 * @param response Callback message. 2700 */ nvWriteCdmaPrl(byte[] preferredRoamingList, Message response)2701 public void nvWriteCdmaPrl(byte[] preferredRoamingList, Message response) { 2702 mCi.nvWriteCdmaPrl(preferredRoamingList, response); 2703 } 2704 2705 /** 2706 * Perform the radio modem reboot. The radio will be taken offline. Used for device 2707 * configuration by some CDMA operators. 2708 * TODO: reuse nvResetConfig for now, should move to separate HAL API. 2709 * 2710 * @param response Callback message. 2711 */ rebootModem(Message response)2712 public void rebootModem(Message response) { 2713 mCi.nvResetConfig(1 /* 1: reload NV reset, trigger a modem reboot */, response); 2714 } 2715 2716 /** 2717 * Perform the modem configuration reset. Used for device configuration by some CDMA operators. 2718 * TODO: reuse nvResetConfig for now, should move to separate HAL API. 2719 * 2720 * @param response Callback message. 2721 */ resetModemConfig(Message response)2722 public void resetModemConfig(Message response) { 2723 mCi.nvResetConfig(3 /* factory NV reset */, response); 2724 } 2725 2726 /** 2727 * Perform modem configuration erase. Used for network reset 2728 * 2729 * @param response Callback message. 2730 */ eraseModemConfig(Message response)2731 public void eraseModemConfig(Message response) { 2732 mCi.nvResetConfig(2 /* erase NV */, response); 2733 } 2734 2735 /** 2736 * Erase data saved in the SharedPreference. Used for network reset 2737 * 2738 */ eraseDataInSharedPreferences()2739 public boolean eraseDataInSharedPreferences() { 2740 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); 2741 SharedPreferences.Editor editor = sp.edit(); 2742 Rlog.d(LOG_TAG, "Erase all data saved in SharedPreferences"); 2743 editor.clear(); 2744 return editor.commit(); 2745 } 2746 setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, Message response)2747 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, 2748 Message response) { 2749 mCi.setSystemSelectionChannels(specifiers, response); 2750 } 2751 2752 /** 2753 * Get which bands the modem's background scan is acting on. 2754 * 2755 * @param response Callback message. 2756 */ getSystemSelectionChannels(Message response)2757 public void getSystemSelectionChannels(Message response) { 2758 mCi.getSystemSelectionChannels(response); 2759 } 2760 notifyDataActivity()2761 public void notifyDataActivity() { 2762 mNotifier.notifyDataActivity(this); 2763 } 2764 notifyMessageWaitingIndicator()2765 private void notifyMessageWaitingIndicator() { 2766 // Do not notify voice mail waiting if device doesn't support voice 2767 if (!mIsVoiceCapable) 2768 return; 2769 2770 // This function is added to send the notification to DefaultPhoneNotifier. 2771 mNotifier.notifyMessageWaitingChanged(this); 2772 } 2773 2774 /** Send notification with an updated PreciseDataConnectionState to a single data connection */ notifyDataConnection(PreciseDataConnectionState state)2775 public void notifyDataConnection(PreciseDataConnectionState state) { 2776 mNotifier.notifyDataConnection(this, state); 2777 } 2778 2779 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) notifyOtaspChanged(int otaspMode)2780 public void notifyOtaspChanged(int otaspMode) { 2781 mOtaspRegistrants.notifyRegistrants(new AsyncResult(null, otaspMode, null)); 2782 } 2783 notifyVoiceActivationStateChanged(int state)2784 public void notifyVoiceActivationStateChanged(int state) { 2785 mNotifier.notifyVoiceActivationStateChanged(this, state); 2786 } 2787 notifyDataActivationStateChanged(int state)2788 public void notifyDataActivationStateChanged(int state) { 2789 mNotifier.notifyDataActivationStateChanged(this, state); 2790 } 2791 notifyUserMobileDataStateChanged(boolean state)2792 public void notifyUserMobileDataStateChanged(boolean state) { 2793 mNotifier.notifyUserMobileDataStateChanged(this, state); 2794 } 2795 2796 /** Send notification that display info has changed. */ notifyDisplayInfoChanged(TelephonyDisplayInfo telephonyDisplayInfo)2797 public void notifyDisplayInfoChanged(TelephonyDisplayInfo telephonyDisplayInfo) { 2798 mNotifier.notifyDisplayInfoChanged(this, telephonyDisplayInfo); 2799 } 2800 notifySignalStrength()2801 public void notifySignalStrength() { 2802 mNotifier.notifySignalStrength(this); 2803 } 2804 getDataConnectionState(String apnType)2805 public PhoneConstants.DataState getDataConnectionState(String apnType) { 2806 return PhoneConstants.DataState.DISCONNECTED; 2807 } 2808 2809 /** Default implementation to get the PreciseDataConnectionState */ getPreciseDataConnectionState(String apnType)2810 public @Nullable PreciseDataConnectionState getPreciseDataConnectionState(String apnType) { 2811 return null; 2812 } 2813 notifyCellInfo(List<CellInfo> cellInfo)2814 public void notifyCellInfo(List<CellInfo> cellInfo) { 2815 AsyncResult ar = new AsyncResult(null, cellInfo, null); 2816 mCellInfoRegistrants.notifyRegistrants(ar); 2817 2818 mNotifier.notifyCellInfo(this, cellInfo); 2819 } 2820 2821 /** 2822 * Registration point for PhysicalChannelConfig change. 2823 * @param h handler to notify 2824 * @param what what code of message when delivered 2825 * @param obj placed in Message.obj.userObj 2826 */ registerForPhysicalChannelConfig(Handler h, int what, Object obj)2827 public void registerForPhysicalChannelConfig(Handler h, int what, Object obj) { 2828 checkCorrectThread(h); 2829 Registrant registrant = new Registrant(h, what, obj); 2830 mPhysicalChannelConfigRegistrants.add(registrant); 2831 // notify first 2832 List<PhysicalChannelConfig> physicalChannelConfigs = getPhysicalChannelConfigList(); 2833 if (physicalChannelConfigs != null) { 2834 registrant.notifyRegistrant(new AsyncResult(null, physicalChannelConfigs, null)); 2835 } 2836 } 2837 unregisterForPhysicalChannelConfig(Handler h)2838 public void unregisterForPhysicalChannelConfig(Handler h) { 2839 mPhysicalChannelConfigRegistrants.remove(h); 2840 } 2841 2842 /** Notify {@link PhysicalChannelConfig} changes. */ notifyPhysicalChannelConfig(List<PhysicalChannelConfig> configs)2843 public void notifyPhysicalChannelConfig(List<PhysicalChannelConfig> configs) { 2844 mPhysicalChannelConfigRegistrants.notifyRegistrants(new AsyncResult(null, configs, null)); 2845 mNotifier.notifyPhysicalChannelConfig(this, configs); 2846 } 2847 getPhysicalChannelConfigList()2848 public List<PhysicalChannelConfig> getPhysicalChannelConfigList() { 2849 return null; 2850 } 2851 2852 /** 2853 * Notify listeners that SRVCC state has changed. 2854 */ notifySrvccStateChanged(int state)2855 public void notifySrvccStateChanged(int state) { 2856 mNotifier.notifySrvccStateChanged(this, state); 2857 } 2858 2859 /** Notify the {@link EmergencyNumber} changes. */ notifyEmergencyNumberList()2860 public void notifyEmergencyNumberList() { 2861 mNotifier.notifyEmergencyNumberList(this); 2862 } 2863 2864 /** Notify the outgoing Sms {@link EmergencyNumber} changes. */ notifyOutgoingEmergencySms(EmergencyNumber emergencyNumber)2865 public void notifyOutgoingEmergencySms(EmergencyNumber emergencyNumber) { 2866 mNotifier.notifyOutgoingEmergencySms(this, emergencyNumber); 2867 } 2868 2869 /** Notify the data enabled changes. */ notifyDataEnabled(boolean enabled, @TelephonyManager.DataEnabledReason int reason)2870 public void notifyDataEnabled(boolean enabled, 2871 @TelephonyManager.DataEnabledReason int reason) { 2872 mNotifier.notifyDataEnabled(this, enabled, reason); 2873 } 2874 2875 /** Notify link capacity estimate has changed. */ notifyLinkCapacityEstimateChanged( List<LinkCapacityEstimate> linkCapacityEstimateList)2876 public void notifyLinkCapacityEstimateChanged( 2877 List<LinkCapacityEstimate> linkCapacityEstimateList) { 2878 mNotifier.notifyLinkCapacityEstimateChanged(this, linkCapacityEstimateList); 2879 } 2880 2881 /** 2882 * @return true if a mobile originating emergency call is active 2883 */ isInEmergencyCall()2884 public boolean isInEmergencyCall() { 2885 return false; 2886 } 2887 2888 // This property is used to handle phone process crashes, and is the same for CDMA and IMS 2889 // phones getInEcmMode()2890 protected static boolean getInEcmMode() { 2891 return TelephonyProperties.in_ecm_mode().orElse(false); 2892 } 2893 2894 /** 2895 * @return {@code true} if we are in emergency call back mode. This is a period where the phone 2896 * should be using as little power as possible and be ready to receive an incoming call from the 2897 * emergency operator. 2898 */ isInEcm()2899 public boolean isInEcm() { 2900 return mIsPhoneInEcmState; 2901 } 2902 isInImsEcm()2903 public boolean isInImsEcm() { 2904 return false; 2905 } 2906 setIsInEcm(boolean isInEcm)2907 public void setIsInEcm(boolean isInEcm) { 2908 if (!getUnitTestMode()) { 2909 TelephonyProperties.in_ecm_mode(isInEcm); 2910 } 2911 mIsPhoneInEcmState = isInEcm; 2912 } 2913 2914 /** 2915 * @return true if this Phone is in an emergency call that caused emergency callback mode to be 2916 * canceled, false if not. 2917 */ isEcmCanceledForEmergency()2918 public boolean isEcmCanceledForEmergency() { 2919 return mEcmCanceledForEmergency; 2920 } 2921 2922 /** 2923 * Set whether or not this Phone has an active emergency call that was placed during emergency 2924 * callback mode and caused it to be temporarily canceled. 2925 * @param isCanceled true if an emergency call was placed that caused ECM to be canceled, false 2926 * if it is not in this state. 2927 */ setEcmCanceledForEmergency(boolean isCanceled)2928 public void setEcmCanceledForEmergency(boolean isCanceled) { 2929 mEcmCanceledForEmergency = isCanceled; 2930 } 2931 2932 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getVideoState(Call call)2933 private static int getVideoState(Call call) { 2934 int videoState = VideoProfile.STATE_AUDIO_ONLY; 2935 Connection conn = call.getEarliestConnection(); 2936 if (conn != null) { 2937 videoState = conn.getVideoState(); 2938 } 2939 return videoState; 2940 } 2941 2942 /** 2943 * Determines if the specified call currently is or was at some point a video call, or if it is 2944 * a conference call. 2945 * @param call The call. 2946 * @return {@code true} if the call is or was a video call or is a conference call, 2947 * {@code false} otherwise. 2948 */ isVideoCallOrConference(Call call)2949 private boolean isVideoCallOrConference(Call call) { 2950 if (call.isMultiparty()) { 2951 return true; 2952 } 2953 2954 boolean isDowngradedVideoCall = false; 2955 if (call instanceof ImsPhoneCall) { 2956 ImsPhoneCall imsPhoneCall = (ImsPhoneCall) call; 2957 ImsCall imsCall = imsPhoneCall.getImsCall(); 2958 return imsCall != null && (imsCall.isVideoCall() || 2959 imsCall.wasVideoCall()); 2960 } 2961 return isDowngradedVideoCall; 2962 } 2963 2964 /** 2965 * @return {@code true} if an IMS video call or IMS conference is present, false otherwise. 2966 */ isImsVideoCallOrConferencePresent()2967 public boolean isImsVideoCallOrConferencePresent() { 2968 boolean isPresent = false; 2969 if (mImsPhone != null) { 2970 isPresent = isVideoCallOrConference(mImsPhone.getForegroundCall()) || 2971 isVideoCallOrConference(mImsPhone.getBackgroundCall()) || 2972 isVideoCallOrConference(mImsPhone.getRingingCall()); 2973 } 2974 Rlog.d(LOG_TAG, "isImsVideoCallOrConferencePresent: " + isPresent); 2975 return isPresent; 2976 } 2977 2978 /** 2979 * Return a numerical identifier for the phone radio interface. 2980 * @return PHONE_TYPE_XXX as defined above. 2981 */ 2982 @UnsupportedAppUsage getPhoneType()2983 public abstract int getPhoneType(); 2984 2985 /** 2986 * Returns unread voicemail count. This count is shown when the voicemail 2987 * notification is expanded.<p> 2988 */ getVoiceMessageCount()2989 public int getVoiceMessageCount(){ 2990 return mVmCount; 2991 } 2992 2993 /** sets the voice mail count of the phone and notifies listeners. */ setVoiceMessageCount(int countWaiting)2994 public void setVoiceMessageCount(int countWaiting) { 2995 mVmCount = countWaiting; 2996 int subId = getSubId(); 2997 if (SubscriptionManager.isValidSubscriptionId(subId)) { 2998 2999 Rlog.d(LOG_TAG, "setVoiceMessageCount: Storing Voice Mail Count = " + countWaiting + 3000 " for mVmCountKey = " + VM_COUNT + subId + " in preferences."); 3001 3002 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); 3003 SharedPreferences.Editor editor = sp.edit(); 3004 editor.putInt(VM_COUNT + subId, countWaiting); 3005 editor.apply(); 3006 } else { 3007 Rlog.e(LOG_TAG, "setVoiceMessageCount in sharedPreference: invalid subId " + subId); 3008 } 3009 // store voice mail count in SIM 3010 IccRecords records = UiccController.getInstance().getIccRecords( 3011 mPhoneId, UiccController.APP_FAM_3GPP); 3012 if (records != null) { 3013 Rlog.d(LOG_TAG, "setVoiceMessageCount: updating SIM Records"); 3014 records.setVoiceMessageWaiting(1, countWaiting); 3015 } else { 3016 Rlog.d(LOG_TAG, "setVoiceMessageCount: SIM Records not found"); 3017 } 3018 // notify listeners of voice mail 3019 notifyMessageWaitingIndicator(); 3020 } 3021 3022 /** gets the voice mail count from preferences */ getStoredVoiceMessageCount()3023 protected int getStoredVoiceMessageCount() { 3024 int countVoiceMessages = 0; 3025 int subId = getSubId(); 3026 if (SubscriptionManager.isValidSubscriptionId(subId)) { 3027 int invalidCount = -2; //-1 is not really invalid. It is used for unknown number of vm 3028 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); 3029 int countFromSP = sp.getInt(VM_COUNT + subId, invalidCount); 3030 if (countFromSP != invalidCount) { 3031 countVoiceMessages = countFromSP; 3032 Rlog.d(LOG_TAG, "getStoredVoiceMessageCount: from preference for subId " + subId + 3033 "= " + countVoiceMessages); 3034 } else { 3035 // Check for old preference if count not found for current subId. This part of the 3036 // code is needed only when upgrading from M to N. 3037 String subscriberId = sp.getString(VM_ID, null); 3038 if (subscriberId != null) { 3039 String currentSubscriberId = getSubscriberId(); 3040 3041 if (currentSubscriberId != null && currentSubscriberId.equals(subscriberId)) { 3042 // get voice mail count from preferences 3043 countVoiceMessages = sp.getInt(VM_COUNT, 0); 3044 setVoiceMessageCount(countVoiceMessages); 3045 Rlog.d(LOG_TAG, "getStoredVoiceMessageCount: from preference = " + 3046 countVoiceMessages); 3047 } else { 3048 Rlog.d(LOG_TAG, "getStoredVoiceMessageCount: returning 0 as count for " + 3049 "matching subscriberId not found"); 3050 3051 } 3052 // get rid of old preferences. 3053 SharedPreferences.Editor editor = sp.edit(); 3054 editor.remove(VM_ID); 3055 editor.remove(VM_COUNT); 3056 editor.apply(); 3057 } 3058 } 3059 } else { 3060 Rlog.e(LOG_TAG, "getStoredVoiceMessageCount: invalid subId " + subId); 3061 } 3062 return countVoiceMessages; 3063 } 3064 3065 /** 3066 * send secret dialer codes to launch arbitrary activities. 3067 * an Intent is started with the android_secret_code://<code> URI. 3068 * 3069 * @param code stripped version of secret code without *#*# prefix and #*#* suffix 3070 */ sendDialerSpecialCode(String code)3071 public void sendDialerSpecialCode(String code) { 3072 if (!TextUtils.isEmpty(code)) { 3073 final BroadcastOptions options = BroadcastOptions.makeBasic(); 3074 options.setBackgroundActivityStartsAllowed(true); 3075 Intent intent = new Intent(TelephonyIntents.SECRET_CODE_ACTION, 3076 Uri.parse("android_secret_code://" + code)); 3077 intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); 3078 mContext.sendBroadcast(intent, null, options.toBundle()); 3079 3080 // {@link TelephonyManager.ACTION_SECRET_CODE} will replace {@link 3081 // TelephonyIntents#SECRET_CODE_ACTION} in the next Android version. Before 3082 // that both of these two actions will be broadcast. 3083 Intent secrectCodeIntent = new Intent(TelephonyManager.ACTION_SECRET_CODE, 3084 Uri.parse("android_secret_code://" + code)); 3085 secrectCodeIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); 3086 mContext.sendBroadcast(secrectCodeIntent, null, options.toBundle()); 3087 } 3088 } 3089 3090 /** 3091 * Returns the CDMA ERI icon index to display 3092 */ getCdmaEriIconIndex()3093 public int getCdmaEriIconIndex() { 3094 return -1; 3095 } 3096 3097 /** 3098 * Returns the CDMA ERI icon mode, 3099 * 0 - ON 3100 * 1 - FLASHING 3101 */ getCdmaEriIconMode()3102 public int getCdmaEriIconMode() { 3103 return -1; 3104 } 3105 3106 /** 3107 * Returns the CDMA ERI text, 3108 */ getCdmaEriText()3109 public String getCdmaEriText() { 3110 return "GSM nw, no ERI"; 3111 } 3112 3113 /** 3114 * Retrieves the MIN for CDMA phones. 3115 */ getCdmaMin()3116 public String getCdmaMin() { 3117 return null; 3118 } 3119 3120 /** 3121 * Check if subscription data has been assigned to mMin 3122 * 3123 * return true if MIN info is ready; false otherwise. 3124 */ isMinInfoReady()3125 public boolean isMinInfoReady() { 3126 return false; 3127 } 3128 3129 /** 3130 * Retrieves PRL Version for CDMA phones 3131 */ getCdmaPrlVersion()3132 public String getCdmaPrlVersion(){ 3133 return null; 3134 } 3135 3136 /** 3137 * @return {@code true} if data is suspended. 3138 */ isDataSuspended()3139 public boolean isDataSuspended() { 3140 return false; 3141 } 3142 3143 /** 3144 * send burst DTMF tone, it can send the string as single character or multiple character 3145 * ignore if there is no active call or not valid digits string. 3146 * Valid digit means only includes characters ISO-LATIN characters 0-9, *, # 3147 * The difference between sendDtmf and sendBurstDtmf is sendDtmf only sends one character, 3148 * this api can send single character and multiple character, also, this api has response 3149 * back to caller. 3150 * 3151 * @param dtmfString is string representing the dialing digit(s) in the active call 3152 * @param on the DTMF ON length in milliseconds, or 0 for default 3153 * @param off the DTMF OFF length in milliseconds, or 0 for default 3154 * @param onComplete is the callback message when the action is processed by BP 3155 * 3156 */ sendBurstDtmf(String dtmfString, int on, int off, Message onComplete)3157 public void sendBurstDtmf(String dtmfString, int on, int off, Message onComplete) { 3158 } 3159 3160 /** 3161 * Sets an event to be fired when the telephony system processes 3162 * a post-dial character on an outgoing call.<p> 3163 * 3164 * Messages of type <code>what</code> will be sent to <code>h</code>. 3165 * The <code>obj</code> field of these Message's will be instances of 3166 * <code>AsyncResult</code>. <code>Message.obj.result</code> will be 3167 * a Connection object.<p> 3168 * 3169 * Message.arg1 will be the post dial character being processed, 3170 * or 0 ('\0') if end of string.<p> 3171 * 3172 * If Connection.getPostDialState() == WAIT, 3173 * the application must call 3174 * {@link com.android.internal.telephony.Connection#proceedAfterWaitChar() 3175 * Connection.proceedAfterWaitChar()} or 3176 * {@link com.android.internal.telephony.Connection#cancelPostDial() 3177 * Connection.cancelPostDial()} 3178 * for the telephony system to continue playing the post-dial 3179 * DTMF sequence.<p> 3180 * 3181 * If Connection.getPostDialState() == WILD, 3182 * the application must call 3183 * {@link com.android.internal.telephony.Connection#proceedAfterWildChar 3184 * Connection.proceedAfterWildChar()} 3185 * or 3186 * {@link com.android.internal.telephony.Connection#cancelPostDial() 3187 * Connection.cancelPostDial()} 3188 * for the telephony system to continue playing the 3189 * post-dial DTMF sequence.<p> 3190 * 3191 * Only one post dial character handler may be set. <p> 3192 * Calling this method with "h" equal to null unsets this handler.<p> 3193 */ 3194 @UnsupportedAppUsage setOnPostDialCharacter(Handler h, int what, Object obj)3195 public void setOnPostDialCharacter(Handler h, int what, Object obj) { 3196 mPostDialHandler = new Registrant(h, what, obj); 3197 } 3198 getPostDialHandler()3199 public Registrant getPostDialHandler() { 3200 return mPostDialHandler; 3201 } 3202 3203 /** 3204 * request to exit emergency call back mode 3205 * the caller should use setOnECMModeExitResponse 3206 * to receive the emergency callback mode exit response 3207 */ 3208 @UnsupportedAppUsage exitEmergencyCallbackMode()3209 public void exitEmergencyCallbackMode() { 3210 } 3211 3212 /** 3213 * Register for notifications when CDMA OTA Provision status change 3214 * 3215 * @param h Handler that receives the notification message. 3216 * @param what User-defined message code. 3217 * @param obj User object. 3218 */ registerForCdmaOtaStatusChange(Handler h, int what, Object obj)3219 public void registerForCdmaOtaStatusChange(Handler h, int what, Object obj) { 3220 } 3221 3222 /** 3223 * Unregister for notifications when CDMA OTA Provision status change 3224 * @param h Handler to be removed from the registrant list. 3225 */ unregisterForCdmaOtaStatusChange(Handler h)3226 public void unregisterForCdmaOtaStatusChange(Handler h) { 3227 } 3228 3229 /** 3230 * Registration point for subscription info ready 3231 * @param h handler to notify 3232 * @param what what code of message when delivered 3233 * @param obj placed in Message.obj 3234 */ registerForSubscriptionInfoReady(Handler h, int what, Object obj)3235 public void registerForSubscriptionInfoReady(Handler h, int what, Object obj) { 3236 } 3237 3238 /** 3239 * Unregister for notifications for subscription info 3240 * @param h Handler to be removed from the registrant list. 3241 */ unregisterForSubscriptionInfoReady(Handler h)3242 public void unregisterForSubscriptionInfoReady(Handler h) { 3243 } 3244 3245 /** 3246 * Returns true if OTA Service Provisioning needs to be performed. 3247 */ 3248 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) needsOtaServiceProvisioning()3249 public boolean needsOtaServiceProvisioning() { 3250 return false; 3251 } 3252 3253 /** 3254 * this decides if the dial number is OTA(Over the air provision) number or not 3255 * @param dialStr is string representing the dialing digit(s) 3256 * @return true means the dialStr is OTA number, and false means the dialStr is not OTA number 3257 */ isOtaSpNumber(String dialStr)3258 public boolean isOtaSpNumber(String dialStr) { 3259 return false; 3260 } 3261 3262 /** 3263 * Register for notifications when OTA Service Provisioning mode has changed. 3264 * 3265 * <p>The mode is integer. {@link TelephonyManager#OTASP_UNKNOWN} 3266 * means the value is currently unknown and the system should wait until 3267 * {@link TelephonyManager#OTASP_NEEDED} or {@link TelephonyManager#OTASP_NOT_NEEDED} is 3268 * received before making the decision to perform OTASP or not. 3269 * 3270 * @param h Handler that receives the notification message. 3271 * @param what User-defined message code. 3272 * @param obj User object. 3273 */ registerForOtaspChange(Handler h, int what, Object obj)3274 public void registerForOtaspChange(Handler h, int what, Object obj) { 3275 checkCorrectThread(h); 3276 mOtaspRegistrants.addUnique(h, what, obj); 3277 // notify first 3278 new Registrant(h, what, obj).notifyRegistrant(new AsyncResult(null, getOtasp(), null)); 3279 } 3280 3281 /** 3282 * Unegister for notifications when OTA Service Provisioning mode has changed. 3283 * @param h Handler to be removed from the registrant list. 3284 */ unregisterForOtaspChange(Handler h)3285 public void unregisterForOtaspChange(Handler h) { 3286 mOtaspRegistrants.remove(h); 3287 } 3288 3289 /** 3290 * Returns the current OTA Service Provisioning mode. 3291 * 3292 * @see registerForOtaspChange 3293 */ getOtasp()3294 public int getOtasp() { 3295 return TelephonyManager.OTASP_UNKNOWN; 3296 } 3297 3298 /** 3299 * Register for notifications when CDMA call waiting comes 3300 * 3301 * @param h Handler that receives the notification message. 3302 * @param what User-defined message code. 3303 * @param obj User object. 3304 */ registerForCallWaiting(Handler h, int what, Object obj)3305 public void registerForCallWaiting(Handler h, int what, Object obj){ 3306 } 3307 3308 /** 3309 * Unegister for notifications when CDMA Call waiting comes 3310 * @param h Handler to be removed from the registrant list. 3311 */ unregisterForCallWaiting(Handler h)3312 public void unregisterForCallWaiting(Handler h){ 3313 } 3314 3315 /** 3316 * Registration point for Ecm timer reset 3317 * @param h handler to notify 3318 * @param what user-defined message code 3319 * @param obj placed in Message.obj 3320 */ 3321 @UnsupportedAppUsage registerForEcmTimerReset(Handler h, int what, Object obj)3322 public void registerForEcmTimerReset(Handler h, int what, Object obj) { 3323 } 3324 3325 /** 3326 * Unregister for notification for Ecm timer reset 3327 * @param h Handler to be removed from the registrant list. 3328 */ 3329 @UnsupportedAppUsage unregisterForEcmTimerReset(Handler h)3330 public void unregisterForEcmTimerReset(Handler h) { 3331 } 3332 3333 /** 3334 * Register for signal information notifications from the network. 3335 * Message.obj will contain an AsyncResult. 3336 * AsyncResult.result will be a SuppServiceNotification instance. 3337 * 3338 * @param h Handler that receives the notification message. 3339 * @param what User-defined message code. 3340 * @param obj User object. 3341 */ registerForSignalInfo(Handler h, int what, Object obj)3342 public void registerForSignalInfo(Handler h, int what, Object obj) { 3343 mCi.registerForSignalInfo(h, what, obj); 3344 } 3345 3346 /** 3347 * Unregisters for signal information notifications. 3348 * Extraneous calls are tolerated silently 3349 * 3350 * @param h Handler to be removed from the registrant list. 3351 */ unregisterForSignalInfo(Handler h)3352 public void unregisterForSignalInfo(Handler h) { 3353 mCi.unregisterForSignalInfo(h); 3354 } 3355 3356 /** 3357 * Register for display information notifications from the network. 3358 * Message.obj will contain an AsyncResult. 3359 * AsyncResult.result will be a SuppServiceNotification instance. 3360 * 3361 * @param h Handler that receives the notification message. 3362 * @param what User-defined message code. 3363 * @param obj User object. 3364 */ registerForDisplayInfo(Handler h, int what, Object obj)3365 public void registerForDisplayInfo(Handler h, int what, Object obj) { 3366 mCi.registerForDisplayInfo(h, what, obj); 3367 } 3368 3369 /** 3370 * Unregisters for display information notifications. 3371 * Extraneous calls are tolerated silently 3372 * 3373 * @param h Handler to be removed from the registrant list. 3374 */ unregisterForDisplayInfo(Handler h)3375 public void unregisterForDisplayInfo(Handler h) { 3376 mCi.unregisterForDisplayInfo(h); 3377 } 3378 3379 /** 3380 * Register for CDMA number information record notification from the network. 3381 * Message.obj will contain an AsyncResult. 3382 * AsyncResult.result will be a CdmaInformationRecords.CdmaNumberInfoRec 3383 * instance. 3384 * 3385 * @param h Handler that receives the notification message. 3386 * @param what User-defined message code. 3387 * @param obj User object. 3388 */ registerForNumberInfo(Handler h, int what, Object obj)3389 public void registerForNumberInfo(Handler h, int what, Object obj) { 3390 mCi.registerForNumberInfo(h, what, obj); 3391 } 3392 3393 /** 3394 * Unregisters for number information record notifications. 3395 * Extraneous calls are tolerated silently 3396 * 3397 * @param h Handler to be removed from the registrant list. 3398 */ unregisterForNumberInfo(Handler h)3399 public void unregisterForNumberInfo(Handler h) { 3400 mCi.unregisterForNumberInfo(h); 3401 } 3402 3403 /** 3404 * Register for CDMA redirected number information record notification 3405 * from the network. 3406 * Message.obj will contain an AsyncResult. 3407 * AsyncResult.result will be a CdmaInformationRecords.CdmaRedirectingNumberInfoRec 3408 * instance. 3409 * 3410 * @param h Handler that receives the notification message. 3411 * @param what User-defined message code. 3412 * @param obj User object. 3413 */ registerForRedirectedNumberInfo(Handler h, int what, Object obj)3414 public void registerForRedirectedNumberInfo(Handler h, int what, Object obj) { 3415 mCi.registerForRedirectedNumberInfo(h, what, obj); 3416 } 3417 3418 /** 3419 * Unregisters for redirected number information record notification. 3420 * Extraneous calls are tolerated silently 3421 * 3422 * @param h Handler to be removed from the registrant list. 3423 */ unregisterForRedirectedNumberInfo(Handler h)3424 public void unregisterForRedirectedNumberInfo(Handler h) { 3425 mCi.unregisterForRedirectedNumberInfo(h); 3426 } 3427 3428 /** 3429 * Register for CDMA line control information record notification 3430 * from the network. 3431 * Message.obj will contain an AsyncResult. 3432 * AsyncResult.result will be a CdmaInformationRecords.CdmaLineControlInfoRec 3433 * instance. 3434 * 3435 * @param h Handler that receives the notification message. 3436 * @param what User-defined message code. 3437 * @param obj User object. 3438 */ registerForLineControlInfo(Handler h, int what, Object obj)3439 public void registerForLineControlInfo(Handler h, int what, Object obj) { 3440 mCi.registerForLineControlInfo(h, what, obj); 3441 } 3442 3443 /** 3444 * Unregisters for line control information notifications. 3445 * Extraneous calls are tolerated silently 3446 * 3447 * @param h Handler to be removed from the registrant list. 3448 */ unregisterForLineControlInfo(Handler h)3449 public void unregisterForLineControlInfo(Handler h) { 3450 mCi.unregisterForLineControlInfo(h); 3451 } 3452 3453 /** 3454 * Register for CDMA T53 CLIR information record notifications 3455 * from the network. 3456 * Message.obj will contain an AsyncResult. 3457 * AsyncResult.result will be a CdmaInformationRecords.CdmaT53ClirInfoRec 3458 * instance. 3459 * 3460 * @param h Handler that receives the notification message. 3461 * @param what User-defined message code. 3462 * @param obj User object. 3463 */ registerFoT53ClirlInfo(Handler h, int what, Object obj)3464 public void registerFoT53ClirlInfo(Handler h, int what, Object obj) { 3465 mCi.registerFoT53ClirlInfo(h, what, obj); 3466 } 3467 3468 /** 3469 * Unregisters for T53 CLIR information record notification 3470 * Extraneous calls are tolerated silently 3471 * 3472 * @param h Handler to be removed from the registrant list. 3473 */ unregisterForT53ClirInfo(Handler h)3474 public void unregisterForT53ClirInfo(Handler h) { 3475 mCi.unregisterForT53ClirInfo(h); 3476 } 3477 3478 /** 3479 * Register for CDMA T53 audio control information record notifications 3480 * from the network. 3481 * Message.obj will contain an AsyncResult. 3482 * AsyncResult.result will be a CdmaInformationRecords.CdmaT53AudioControlInfoRec 3483 * instance. 3484 * 3485 * @param h Handler that receives the notification message. 3486 * @param what User-defined message code. 3487 * @param obj User object. 3488 */ registerForT53AudioControlInfo(Handler h, int what, Object obj)3489 public void registerForT53AudioControlInfo(Handler h, int what, Object obj) { 3490 mCi.registerForT53AudioControlInfo(h, what, obj); 3491 } 3492 3493 /** 3494 * Unregisters for T53 audio control information record notifications. 3495 * Extraneous calls are tolerated silently 3496 * 3497 * @param h Handler to be removed from the registrant list. 3498 */ unregisterForT53AudioControlInfo(Handler h)3499 public void unregisterForT53AudioControlInfo(Handler h) { 3500 mCi.unregisterForT53AudioControlInfo(h); 3501 } 3502 3503 /** 3504 * registers for exit emergency call back mode request response 3505 * 3506 * @param h Handler that receives the notification message. 3507 * @param what User-defined message code. 3508 * @param obj User object. 3509 */ 3510 @UnsupportedAppUsage setOnEcbModeExitResponse(Handler h, int what, Object obj)3511 public void setOnEcbModeExitResponse(Handler h, int what, Object obj){ 3512 } 3513 3514 /** 3515 * Unregisters for exit emergency call back mode request response 3516 * 3517 * @param h Handler to be removed from the registrant list. 3518 */ 3519 @UnsupportedAppUsage unsetOnEcbModeExitResponse(Handler h)3520 public void unsetOnEcbModeExitResponse(Handler h){ 3521 } 3522 3523 /** 3524 * Register for radio off or not available 3525 * 3526 * @param h Handler that receives the notification message. 3527 * @param what User-defined message code. 3528 * @param obj User object. 3529 */ registerForRadioOffOrNotAvailable(Handler h, int what, Object obj)3530 public void registerForRadioOffOrNotAvailable(Handler h, int what, Object obj) { 3531 mRadioOffOrNotAvailableRegistrants.addUnique(h, what, obj); 3532 } 3533 3534 /** 3535 * Unregisters for radio off or not available 3536 * 3537 * @param h Handler to be removed from the registrant list. 3538 */ unregisterForRadioOffOrNotAvailable(Handler h)3539 public void unregisterForRadioOffOrNotAvailable(Handler h) { 3540 mRadioOffOrNotAvailableRegistrants.remove(h); 3541 } 3542 3543 /** 3544 * Returns an array of string identifiers for the APN types serviced by the 3545 * currently active subscription. 3546 * 3547 * @return The string array of APN types. Return null if no active APN types. 3548 */ 3549 @UnsupportedAppUsage 3550 @NonNull getActiveApnTypes()3551 public String[] getActiveApnTypes() { 3552 if (mTransportManager == null || mDcTrackers == null) { 3553 Rlog.e(LOG_TAG, "Invalid state for Transport/DcTrackers"); 3554 return new String[0]; 3555 } 3556 3557 Set<String> activeApnTypes = new HashSet<String>(); 3558 for (int transportType : mTransportManager.getAvailableTransports()) { 3559 DcTracker dct = getDcTracker(transportType); 3560 if (dct == null) continue; // TODO: should this ever happen? 3561 activeApnTypes.addAll(Arrays.asList(dct.getActiveApnTypes())); 3562 } 3563 3564 return activeApnTypes.toArray(new String[activeApnTypes.size()]); 3565 } 3566 3567 3568 /** 3569 * Location to an updatable file listing carrier provisioning urls. 3570 * An example: 3571 * 3572 * <?xml version="1.0" encoding="utf-8"?> 3573 * <provisioningUrls> 3574 * <provisioningUrl mcc="310" mnc="4">http://myserver.com/foo?mdn=%3$s&iccid=%1$s&imei=%2$s</provisioningUrl> 3575 * </provisioningUrls> 3576 */ 3577 private static final String PROVISIONING_URL_PATH = 3578 "/data/misc/radio/provisioning_urls.xml"; 3579 private final File mProvisioningUrlFile = new File(PROVISIONING_URL_PATH); 3580 3581 /** XML tag for root element. */ 3582 private static final String TAG_PROVISIONING_URLS = "provisioningUrls"; 3583 /** XML tag for individual url */ 3584 private static final String TAG_PROVISIONING_URL = "provisioningUrl"; 3585 /** XML attribute for mcc */ 3586 private static final String ATTR_MCC = "mcc"; 3587 /** XML attribute for mnc */ 3588 private static final String ATTR_MNC = "mnc"; 3589 getProvisioningUrlBaseFromFile()3590 private String getProvisioningUrlBaseFromFile() { 3591 XmlPullParser parser; 3592 final Configuration config = mContext.getResources().getConfiguration(); 3593 3594 try (FileReader fileReader = new FileReader(mProvisioningUrlFile)) { 3595 parser = Xml.newPullParser(); 3596 parser.setInput(fileReader); 3597 XmlUtils.beginDocument(parser, TAG_PROVISIONING_URLS); 3598 3599 while (true) { 3600 XmlUtils.nextElement(parser); 3601 3602 final String element = parser.getName(); 3603 if (element == null) break; 3604 3605 if (element.equals(TAG_PROVISIONING_URL)) { 3606 String mcc = parser.getAttributeValue(null, ATTR_MCC); 3607 try { 3608 if (mcc != null && Integer.parseInt(mcc) == config.mcc) { 3609 String mnc = parser.getAttributeValue(null, ATTR_MNC); 3610 if (mnc != null && Integer.parseInt(mnc) == config.mnc) { 3611 parser.next(); 3612 if (parser.getEventType() == XmlPullParser.TEXT) { 3613 return parser.getText(); 3614 } 3615 } 3616 } 3617 } catch (NumberFormatException e) { 3618 Rlog.e(LOG_TAG, "Exception in getProvisioningUrlBaseFromFile: " + e); 3619 } 3620 } 3621 } 3622 return null; 3623 } catch (FileNotFoundException e) { 3624 Rlog.e(LOG_TAG, "Carrier Provisioning Urls file not found"); 3625 } catch (XmlPullParserException e) { 3626 Rlog.e(LOG_TAG, "Xml parser exception reading Carrier Provisioning Urls file: " + e); 3627 } catch (IOException e) { 3628 Rlog.e(LOG_TAG, "I/O exception reading Carrier Provisioning Urls file: " + e); 3629 } 3630 return null; 3631 } 3632 3633 /** 3634 * Get the mobile provisioning url. 3635 */ getMobileProvisioningUrl()3636 public String getMobileProvisioningUrl() { 3637 String url = getProvisioningUrlBaseFromFile(); 3638 if (TextUtils.isEmpty(url)) { 3639 url = mContext.getResources().getString(R.string.mobile_provisioning_url); 3640 Rlog.d(LOG_TAG, "getMobileProvisioningUrl: url from resource =" + url); 3641 } else { 3642 Rlog.d(LOG_TAG, "getMobileProvisioningUrl: url from File =" + url); 3643 } 3644 // Populate the iccid, imei and phone number in the provisioning url. 3645 if (!TextUtils.isEmpty(url)) { 3646 String phoneNumber = getLine1Number(); 3647 if (TextUtils.isEmpty(phoneNumber)) { 3648 phoneNumber = "0000000000"; 3649 } 3650 url = String.format(url, 3651 getIccSerialNumber() /* ICCID */, 3652 getDeviceId() /* IMEI */, 3653 phoneNumber /* Phone number */); 3654 } 3655 3656 return url; 3657 } 3658 3659 /** 3660 * Check if there are matching tethering (i.e DUN) for the carrier. 3661 * @return true if there is a matching DUN APN. 3662 */ hasMatchedTetherApnSetting()3663 public boolean hasMatchedTetherApnSetting() { 3664 if (getDcTracker(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) != null) { 3665 return getDcTracker(AccessNetworkConstants.TRANSPORT_TYPE_WWAN) 3666 .hasMatchedTetherApnSetting(); 3667 } 3668 return false; 3669 } 3670 3671 /** 3672 * Returns string for the active APN host. 3673 * @return type as a string or null if none. 3674 */ getActiveApnHost(String apnType)3675 public String getActiveApnHost(String apnType) { 3676 if (mTransportManager != null) { 3677 int transportType = mTransportManager.getCurrentTransport( 3678 ApnSetting.getApnTypesBitmaskFromString(apnType)); 3679 if (getDcTracker(transportType) != null) { 3680 return getDcTracker(transportType).getActiveApnString(apnType); 3681 } 3682 } 3683 3684 return null; 3685 } 3686 3687 /** 3688 * Return the LinkProperties for the named apn or null if not available 3689 */ getLinkProperties(String apnType)3690 public LinkProperties getLinkProperties(String apnType) { 3691 if (mTransportManager != null) { 3692 int transport = mTransportManager.getCurrentTransport( 3693 ApnSetting.getApnTypesBitmaskFromString(apnType)); 3694 if (getDcTracker(transport) != null) { 3695 return getDcTracker(transport).getLinkProperties(apnType); 3696 } 3697 } 3698 return null; 3699 } 3700 3701 /** 3702 * Return the NetworkCapabilities 3703 */ getNetworkCapabilities(String apnType)3704 public NetworkCapabilities getNetworkCapabilities(String apnType) { 3705 if (mTransportManager != null) { 3706 int transportType = mTransportManager.getCurrentTransport( 3707 ApnSetting.getApnTypesBitmaskFromString(apnType)); 3708 if (getDcTracker(transportType) != null) { 3709 return getDcTracker(transportType).getNetworkCapabilities(apnType); 3710 } 3711 } 3712 return null; 3713 } 3714 3715 /** 3716 * Report on whether data connectivity is allowed for given APN type. 3717 * 3718 * @param apnType APN type 3719 * 3720 * @return True if data is allowed to be established. 3721 */ isDataAllowed(@pnType int apnType)3722 public boolean isDataAllowed(@ApnType int apnType) { 3723 return isDataAllowed(apnType, null); 3724 } 3725 3726 /** 3727 * Report on whether data connectivity is allowed. 3728 * 3729 * @param apnType APN type 3730 * @param reasons The reasons that data can/can't be established. This is an output param. 3731 * @return True if data is allowed to be established 3732 */ isDataAllowed(@pnType int apnType, DataConnectionReasons reasons)3733 public boolean isDataAllowed(@ApnType int apnType, DataConnectionReasons reasons) { 3734 if (mTransportManager != null) { 3735 int transport = mTransportManager.getCurrentTransport(apnType); 3736 if (getDcTracker(transport) != null) { 3737 return getDcTracker(transport).isDataAllowed(reasons); 3738 } 3739 } 3740 return false; 3741 } 3742 3743 3744 /** 3745 * Action set from carrier signalling broadcast receivers to enable/disable metered apns. 3746 */ carrierActionSetMeteredApnsEnabled(boolean enabled)3747 public void carrierActionSetMeteredApnsEnabled(boolean enabled) { 3748 mCarrierActionAgent.carrierActionSetMeteredApnsEnabled(enabled); 3749 } 3750 3751 /** 3752 * Action set from carrier signalling broadcast receivers to enable/disable radio 3753 */ carrierActionSetRadioEnabled(boolean enabled)3754 public void carrierActionSetRadioEnabled(boolean enabled) { 3755 mCarrierActionAgent.carrierActionSetRadioEnabled(enabled); 3756 } 3757 3758 /** 3759 * Action set from carrier app to start/stop reporting default network condition. 3760 */ carrierActionReportDefaultNetworkStatus(boolean report)3761 public void carrierActionReportDefaultNetworkStatus(boolean report) { 3762 mCarrierActionAgent.carrierActionReportDefaultNetworkStatus(report); 3763 } 3764 3765 /** 3766 * Action set from carrier signalling broadcast receivers to reset all carrier actions 3767 */ carrierActionResetAll()3768 public void carrierActionResetAll() { 3769 mCarrierActionAgent.carrierActionReset(); 3770 } 3771 3772 /** 3773 * Notify registrants of a new ringing Connection. 3774 * Subclasses of Phone probably want to replace this with a 3775 * version scoped to their packages 3776 */ notifyNewRingingConnectionP(Connection cn)3777 public void notifyNewRingingConnectionP(Connection cn) { 3778 if (!mIsVoiceCapable) 3779 return; 3780 AsyncResult ar = new AsyncResult(null, cn, null); 3781 mNewRingingConnectionRegistrants.notifyRegistrants(ar); 3782 } 3783 3784 /** 3785 * Notify registrants of a new unknown connection. 3786 */ notifyUnknownConnectionP(Connection cn)3787 public void notifyUnknownConnectionP(Connection cn) { 3788 mUnknownConnectionRegistrants.notifyResult(cn); 3789 } 3790 3791 /** 3792 * Notify registrants if phone is video capable. 3793 */ notifyForVideoCapabilityChanged(boolean isVideoCallCapable)3794 public void notifyForVideoCapabilityChanged(boolean isVideoCallCapable) { 3795 // Cache the current video capability so that we don't lose the information. 3796 mIsVideoCapable = isVideoCallCapable; 3797 3798 AsyncResult ar = new AsyncResult(null, isVideoCallCapable, null); 3799 mVideoCapabilityChangedRegistrants.notifyRegistrants(ar); 3800 } 3801 3802 /** 3803 * Notify registrants of a RING event. 3804 */ notifyIncomingRing()3805 private void notifyIncomingRing() { 3806 if (!mIsVoiceCapable) 3807 return; 3808 AsyncResult ar = new AsyncResult(null, this, null); 3809 mIncomingRingRegistrants.notifyRegistrants(ar); 3810 } 3811 3812 /** 3813 * Send the incoming call Ring notification if conditions are right. 3814 */ sendIncomingCallRingNotification(int token)3815 private void sendIncomingCallRingNotification(int token) { 3816 if (mIsVoiceCapable && !mDoesRilSendMultipleCallRing && 3817 (token == mCallRingContinueToken)) { 3818 Rlog.d(LOG_TAG, "Sending notifyIncomingRing"); 3819 notifyIncomingRing(); 3820 sendMessageDelayed( 3821 obtainMessage(EVENT_CALL_RING_CONTINUE, token, 0), mCallRingDelay); 3822 } else { 3823 Rlog.d(LOG_TAG, "Ignoring ring notification request," 3824 + " mDoesRilSendMultipleCallRing=" + mDoesRilSendMultipleCallRing 3825 + " token=" + token 3826 + " mCallRingContinueToken=" + mCallRingContinueToken 3827 + " mIsVoiceCapable=" + mIsVoiceCapable); 3828 } 3829 } 3830 3831 /** 3832 * Enable or disable always reporting signal strength changes from radio. 3833 * 3834 * @param isEnable {@code true} for enabling; {@code false} for disabling. 3835 */ setAlwaysReportSignalStrength(boolean isEnable)3836 public void setAlwaysReportSignalStrength(boolean isEnable) { 3837 if (mDeviceStateMonitor != null) { 3838 mDeviceStateMonitor.setAlwaysReportSignalStrength(isEnable); 3839 } 3840 } 3841 3842 /** 3843 * TODO: Adding a function for each property is not good. 3844 * A fucntion of type getPhoneProp(propType) where propType is an 3845 * enum of GSM+CDMA+LTE props would be a better approach. 3846 * 3847 * Get "Restriction of menu options for manual PLMN selection" bit 3848 * status from EF_CSP data, this belongs to "Value Added Services Group". 3849 * @return true if this bit is set or EF_CSP data is unavailable, 3850 * false otherwise 3851 */ 3852 @UnsupportedAppUsage isCspPlmnEnabled()3853 public boolean isCspPlmnEnabled() { 3854 return false; 3855 } 3856 3857 /** 3858 * Return an interface to retrieve the ISIM records for IMS, if available. 3859 * @return the interface to retrieve the ISIM records, or null if not supported 3860 */ 3861 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getIsimRecords()3862 public IsimRecords getIsimRecords() { 3863 Rlog.e(LOG_TAG, "getIsimRecords() is only supported on LTE devices"); 3864 return null; 3865 } 3866 3867 /** 3868 * Retrieves the MSISDN from the UICC. For GSM/UMTS phones, this is equivalent to 3869 * {@link #getLine1Number()}. For CDMA phones, {@link #getLine1Number()} returns 3870 * the MDN, so this method is provided to return the MSISDN on CDMA/LTE phones. 3871 */ 3872 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getMsisdn()3873 public String getMsisdn() { 3874 return null; 3875 } 3876 3877 /** 3878 * Retrieves the EF_PNN from the UICC For GSM/UMTS phones. 3879 */ getPlmn()3880 public String getPlmn() { 3881 return null; 3882 } 3883 3884 /** 3885 * Get the current for the default apn DataState. No change notification 3886 * exists at this interface -- use 3887 * {@link android.telephony.PhoneStateListener} instead. 3888 */ 3889 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getDataConnectionState()3890 public PhoneConstants.DataState getDataConnectionState() { 3891 return getDataConnectionState(ApnSetting.TYPE_DEFAULT_STRING); 3892 } 3893 notifyCallForwardingIndicator()3894 public void notifyCallForwardingIndicator() { 3895 } 3896 3897 /** 3898 * Sets the SIM voice message waiting indicator records. 3899 * @param line GSM Subscriber Profile Number, one-based. Only '1' is supported 3900 * @param countWaiting The number of messages waiting, if known. Use 3901 * -1 to indicate that an unknown number of 3902 * messages are waiting 3903 */ setVoiceMessageWaiting(int line, int countWaiting)3904 public void setVoiceMessageWaiting(int line, int countWaiting) { 3905 // This function should be overridden by class GsmCdmaPhone. 3906 Rlog.e(LOG_TAG, "Error! This function should never be executed, inactive Phone."); 3907 } 3908 3909 /** 3910 * Gets the USIM service table from the UICC, if present and available. 3911 * @return an interface to the UsimServiceTable record, or null if not available 3912 */ getUsimServiceTable()3913 public UsimServiceTable getUsimServiceTable() { 3914 IccRecords r = mIccRecords.get(); 3915 return (r != null) ? r.getUsimServiceTable() : null; 3916 } 3917 3918 /** 3919 * Gets the Uicc card corresponding to this phone. 3920 * @return the UiccCard object corresponding to the phone ID. 3921 */ 3922 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getUiccCard()3923 public UiccCard getUiccCard() { 3924 return mUiccController.getUiccCard(mPhoneId); 3925 } 3926 3927 /** 3928 * Get P-CSCF address from PCO after data connection is established or modified. 3929 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 3930 */ getPcscfAddress(String apnType)3931 public String[] getPcscfAddress(String apnType) { 3932 if (mTransportManager != null) { 3933 int transportType = mTransportManager.getCurrentTransport( 3934 ApnSetting.getApnTypesBitmaskFromString(apnType)); 3935 if (getDcTracker(transportType) != null) { 3936 return getDcTracker(transportType).getPcscfAddress(apnType); 3937 } 3938 } 3939 3940 return null; 3941 } 3942 3943 /** 3944 * Set IMS registration state 3945 */ setImsRegistrationState(boolean registered)3946 public void setImsRegistrationState(boolean registered) { 3947 } 3948 3949 /** 3950 * Return an instance of a IMS phone 3951 */ 3952 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getImsPhone()3953 public Phone getImsPhone() { 3954 return mImsPhone; 3955 } 3956 3957 @VisibleForTesting setImsPhone(ImsPhone imsPhone)3958 public void setImsPhone(ImsPhone imsPhone) { 3959 mImsPhone = imsPhone; 3960 } 3961 3962 /** 3963 * Returns Carrier specific information that will be used to encrypt the IMSI and IMPI. 3964 * @param keyType whether the key is being used for WLAN or ePDG. 3965 * @param fallback whether or not to fall back to the encryption key info stored in carrier 3966 * config 3967 * @return ImsiEncryptionInfo which includes the Key Type, the Public Key 3968 * {@link java.security.PublicKey} and the Key Identifier. 3969 * The keyIdentifier This is used by the server to help it locate the private key to 3970 * decrypt the permanent identity. 3971 */ getCarrierInfoForImsiEncryption(int keyType, boolean fallback)3972 public ImsiEncryptionInfo getCarrierInfoForImsiEncryption(int keyType, boolean fallback) { 3973 return null; 3974 } 3975 3976 /** 3977 * Sets the carrier information needed to encrypt the IMSI and IMPI. 3978 * @param imsiEncryptionInfo Carrier specific information that will be used to encrypt the 3979 * IMSI and IMPI. This includes the Key type, the Public key 3980 * {@link java.security.PublicKey} and the Key identifier. 3981 */ setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo)3982 public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo) { 3983 return; 3984 } 3985 3986 /** 3987 * Deletes all the keys for a given Carrier from the device keystore. 3988 */ deleteCarrierInfoForImsiEncryption()3989 public void deleteCarrierInfoForImsiEncryption() { 3990 return; 3991 } 3992 getCarrierId()3993 public int getCarrierId() { 3994 return TelephonyManager.UNKNOWN_CARRIER_ID; 3995 } 3996 getCarrierName()3997 public String getCarrierName() { 3998 return null; 3999 } 4000 getMNOCarrierId()4001 public int getMNOCarrierId() { 4002 return TelephonyManager.UNKNOWN_CARRIER_ID; 4003 } 4004 getSpecificCarrierId()4005 public int getSpecificCarrierId() { 4006 return TelephonyManager.UNKNOWN_CARRIER_ID; 4007 } 4008 getSpecificCarrierName()4009 public String getSpecificCarrierName() { 4010 return null; 4011 } 4012 getCarrierIdListVersion()4013 public int getCarrierIdListVersion() { 4014 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; 4015 } 4016 getEmergencyNumberDbVersion()4017 public int getEmergencyNumberDbVersion() { 4018 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; 4019 } 4020 resolveSubscriptionCarrierId(String simState)4021 public void resolveSubscriptionCarrierId(String simState) { 4022 } 4023 4024 /** 4025 * Resets the Carrier Keys in the database. This involves 2 steps: 4026 * 1. Delete the keys from the database. 4027 * 2. Send an intent to download new Certificates. 4028 */ resetCarrierKeysForImsiEncryption()4029 public void resetCarrierKeysForImsiEncryption() { 4030 return; 4031 } 4032 4033 /** 4034 * Return if UT capability of ImsPhone is enabled or not 4035 */ 4036 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) isUtEnabled()4037 public boolean isUtEnabled() { 4038 if (mImsPhone != null) { 4039 return mImsPhone.isUtEnabled(); 4040 } 4041 return false; 4042 } 4043 4044 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) dispose()4045 public void dispose() { 4046 } 4047 4048 /** 4049 * Dials a number. 4050 * 4051 * @param dialString The number to dial. 4052 * @param dialArgs Parameters to dial with. 4053 * @return The Connection. 4054 * @throws CallStateException 4055 */ dialInternal(String dialString, DialArgs dialArgs)4056 protected Connection dialInternal(String dialString, DialArgs dialArgs) 4057 throws CallStateException { 4058 // dialInternal shall be overriden by GsmCdmaPhone 4059 return null; 4060 } 4061 4062 /* 4063 * This function is for CSFB SS. GsmCdmaPhone overrides this function. 4064 */ setCallWaiting(boolean enable, int serviceClass, Message onComplete)4065 public void setCallWaiting(boolean enable, int serviceClass, Message onComplete) { 4066 } 4067 queryCLIP(Message onComplete)4068 public void queryCLIP(Message onComplete) { 4069 } 4070 4071 /* 4072 * Returns the subscription id. 4073 */ 4074 @UnsupportedAppUsage getSubId()4075 public int getSubId() { 4076 if (SubscriptionController.getInstance() == null) { 4077 // TODO b/78359408 getInstance sometimes returns null in Treehugger tests, which causes 4078 // flakiness. Even though we haven't seen this crash in the wild we should keep this 4079 // check in until we've figured out the root cause. 4080 Rlog.e(LOG_TAG, "SubscriptionController.getInstance = null! Returning default subId"); 4081 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; 4082 } 4083 return SubscriptionController.getInstance().getSubIdUsingPhoneId(mPhoneId); 4084 } 4085 4086 /** 4087 * Returns the phone id. 4088 */ 4089 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getPhoneId()4090 public int getPhoneId() { 4091 return mPhoneId; 4092 } 4093 4094 /** 4095 * Return the service state of mImsPhone if it is STATE_IN_SERVICE 4096 * otherwise return the current voice service state 4097 */ getVoicePhoneServiceState()4098 public int getVoicePhoneServiceState() { 4099 Phone imsPhone = mImsPhone; 4100 if (imsPhone != null 4101 && imsPhone.getServiceState().getState() == ServiceState.STATE_IN_SERVICE) { 4102 return ServiceState.STATE_IN_SERVICE; 4103 } 4104 return getServiceState().getState(); 4105 } 4106 4107 /** 4108 * Override the service provider name and the operator name for the current ICCID. 4109 */ setOperatorBrandOverride(String brand)4110 public boolean setOperatorBrandOverride(String brand) { 4111 return false; 4112 } 4113 4114 /** 4115 * Override the roaming indicator for the current ICCID. 4116 */ setRoamingOverride(List<String> gsmRoamingList, List<String> gsmNonRoamingList, List<String> cdmaRoamingList, List<String> cdmaNonRoamingList)4117 public boolean setRoamingOverride(List<String> gsmRoamingList, 4118 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 4119 List<String> cdmaNonRoamingList) { 4120 String iccId = getIccSerialNumber(); 4121 if (TextUtils.isEmpty(iccId)) { 4122 return false; 4123 } 4124 4125 setRoamingOverrideHelper(gsmRoamingList, GSM_ROAMING_LIST_OVERRIDE_PREFIX, iccId); 4126 setRoamingOverrideHelper(gsmNonRoamingList, GSM_NON_ROAMING_LIST_OVERRIDE_PREFIX, iccId); 4127 setRoamingOverrideHelper(cdmaRoamingList, CDMA_ROAMING_LIST_OVERRIDE_PREFIX, iccId); 4128 setRoamingOverrideHelper(cdmaNonRoamingList, CDMA_NON_ROAMING_LIST_OVERRIDE_PREFIX, iccId); 4129 4130 // Refresh. 4131 ServiceStateTracker tracker = getServiceStateTracker(); 4132 if (tracker != null) { 4133 tracker.pollState(); 4134 } 4135 return true; 4136 } 4137 setRoamingOverrideHelper(List<String> list, String prefix, String iccId)4138 private void setRoamingOverrideHelper(List<String> list, String prefix, String iccId) { 4139 SharedPreferences.Editor spEditor = 4140 PreferenceManager.getDefaultSharedPreferences(mContext).edit(); 4141 String key = prefix + iccId; 4142 if (list == null || list.isEmpty()) { 4143 spEditor.remove(key).commit(); 4144 } else { 4145 spEditor.putStringSet(key, new HashSet<String>(list)).commit(); 4146 } 4147 } 4148 isMccMncMarkedAsRoaming(String mccMnc)4149 public boolean isMccMncMarkedAsRoaming(String mccMnc) { 4150 return getRoamingOverrideHelper(GSM_ROAMING_LIST_OVERRIDE_PREFIX, mccMnc); 4151 } 4152 isMccMncMarkedAsNonRoaming(String mccMnc)4153 public boolean isMccMncMarkedAsNonRoaming(String mccMnc) { 4154 return getRoamingOverrideHelper(GSM_NON_ROAMING_LIST_OVERRIDE_PREFIX, mccMnc); 4155 } 4156 isSidMarkedAsRoaming(int SID)4157 public boolean isSidMarkedAsRoaming(int SID) { 4158 return getRoamingOverrideHelper(CDMA_ROAMING_LIST_OVERRIDE_PREFIX, 4159 Integer.toString(SID)); 4160 } 4161 isSidMarkedAsNonRoaming(int SID)4162 public boolean isSidMarkedAsNonRoaming(int SID) { 4163 return getRoamingOverrideHelper(CDMA_NON_ROAMING_LIST_OVERRIDE_PREFIX, 4164 Integer.toString(SID)); 4165 } 4166 4167 /** 4168 * Query the IMS Registration Status. 4169 * 4170 * @return true if IMS is Registered 4171 */ isImsRegistered()4172 public boolean isImsRegistered() { 4173 Phone imsPhone = mImsPhone; 4174 boolean isImsRegistered = false; 4175 if (imsPhone != null) { 4176 isImsRegistered = imsPhone.isImsRegistered(); 4177 } else { 4178 ServiceStateTracker sst = getServiceStateTracker(); 4179 if (sst != null) { 4180 isImsRegistered = sst.isImsRegistered(); 4181 } 4182 } 4183 Rlog.d(LOG_TAG, "isImsRegistered =" + isImsRegistered); 4184 return isImsRegistered; 4185 } 4186 4187 /** 4188 * Get Wifi Calling Feature Availability 4189 */ 4190 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) isWifiCallingEnabled()4191 public boolean isWifiCallingEnabled() { 4192 Phone imsPhone = mImsPhone; 4193 boolean isWifiCallingEnabled = false; 4194 if (imsPhone != null) { 4195 isWifiCallingEnabled = imsPhone.isWifiCallingEnabled(); 4196 } 4197 Rlog.d(LOG_TAG, "isWifiCallingEnabled =" + isWifiCallingEnabled); 4198 return isWifiCallingEnabled; 4199 } 4200 4201 /** 4202 * @return true if the IMS capability for the registration technology specified is available, 4203 * false otherwise. 4204 */ isImsCapabilityAvailable(int capability, int regTech)4205 public boolean isImsCapabilityAvailable(int capability, int regTech) throws ImsException { 4206 Phone imsPhone = mImsPhone; 4207 boolean isAvailable = false; 4208 if (imsPhone != null) { 4209 isAvailable = imsPhone.isImsCapabilityAvailable(capability, regTech); 4210 } 4211 Rlog.d(LOG_TAG, "isImsCapabilityAvailable, capability=" + capability + ", regTech=" 4212 + regTech + ", isAvailable=" + isAvailable); 4213 return isAvailable; 4214 } 4215 4216 /** 4217 * Get Volte Feature Availability 4218 * @deprecated Use {@link #isVoiceOverCellularImsEnabled} instead. 4219 */ 4220 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 4221 @Deprecated isVolteEnabled()4222 public boolean isVolteEnabled() { 4223 return isVoiceOverCellularImsEnabled(); 4224 } 4225 4226 /** 4227 * @return {@code true} if voice over IMS on cellular is enabled, {@code false} otherwise. 4228 */ isVoiceOverCellularImsEnabled()4229 public boolean isVoiceOverCellularImsEnabled() { 4230 Phone imsPhone = mImsPhone; 4231 boolean isVolteEnabled = false; 4232 if (imsPhone != null) { 4233 isVolteEnabled = imsPhone.isVoiceOverCellularImsEnabled(); 4234 } 4235 Rlog.d(LOG_TAG, "isVoiceOverCellularImsEnabled=" + isVolteEnabled); 4236 return isVolteEnabled; 4237 } 4238 4239 /** 4240 * @return the IMS MmTel Registration technology for this Phone, defined in 4241 * {@link ImsRegistrationImplBase}. 4242 */ getImsRegistrationTech()4243 public int getImsRegistrationTech() { 4244 Phone imsPhone = mImsPhone; 4245 int regTech = ImsRegistrationImplBase.REGISTRATION_TECH_NONE; 4246 if (imsPhone != null) { 4247 regTech = imsPhone.getImsRegistrationTech(); 4248 } 4249 Rlog.d(LOG_TAG, "getImsRegistrationTechnology =" + regTech); 4250 return regTech; 4251 } 4252 4253 /** 4254 * Get the IMS MmTel Registration technology for this Phone, defined in 4255 * {@link ImsRegistrationImplBase}. 4256 */ getImsRegistrationTech(Consumer<Integer> callback)4257 public void getImsRegistrationTech(Consumer<Integer> callback) { 4258 Phone imsPhone = mImsPhone; 4259 if (imsPhone != null) { 4260 imsPhone.getImsRegistrationTech(callback); 4261 } else { 4262 callback.accept(ImsRegistrationImplBase.REGISTRATION_TECH_NONE); 4263 } 4264 } 4265 4266 /** 4267 * Asynchronously get the IMS MmTel Registration state for this Phone. 4268 */ getImsRegistrationState(Consumer<Integer> callback)4269 public void getImsRegistrationState(Consumer<Integer> callback) { 4270 Phone imsPhone = mImsPhone; 4271 if (imsPhone != null) { 4272 imsPhone.getImsRegistrationState(callback); 4273 } else { 4274 callback.accept(RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED); 4275 } 4276 } 4277 4278 getRoamingOverrideHelper(String prefix, String key)4279 private boolean getRoamingOverrideHelper(String prefix, String key) { 4280 String iccId = getIccSerialNumber(); 4281 if (TextUtils.isEmpty(iccId) || TextUtils.isEmpty(key)) { 4282 return false; 4283 } 4284 4285 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); 4286 Set<String> value = sp.getStringSet(prefix + iccId, null); 4287 if (value == null) { 4288 return false; 4289 } 4290 return value.contains(key); 4291 } 4292 4293 /** 4294 * @return returns the latest radio state from the modem 4295 */ getRadioPowerState()4296 public int getRadioPowerState() { 4297 return mCi.getRadioState(); 4298 } 4299 4300 /** 4301 * Is Radio Present on the device and is it accessible 4302 */ isRadioAvailable()4303 public boolean isRadioAvailable() { 4304 return mCi.getRadioState() != TelephonyManager.RADIO_POWER_UNAVAILABLE; 4305 } 4306 4307 /** 4308 * Is Radio turned on 4309 */ isRadioOn()4310 public boolean isRadioOn() { 4311 return mCi.getRadioState() == TelephonyManager.RADIO_POWER_ON; 4312 } 4313 4314 /** 4315 * shutdown Radio gracefully 4316 */ shutdownRadio()4317 public void shutdownRadio() { 4318 getServiceStateTracker().requestShutdown(); 4319 } 4320 4321 /** 4322 * Return true if the device is shutting down. 4323 */ isShuttingDown()4324 public boolean isShuttingDown() { 4325 return getServiceStateTracker().isDeviceShuttingDown(); 4326 } 4327 4328 /** 4329 * Set phone radio capability 4330 * 4331 * @param rc the phone radio capability defined in 4332 * RadioCapability. It's a input object used to transfer parameter to logic modem 4333 * @param response Callback message. 4334 */ setRadioCapability(RadioCapability rc, Message response)4335 public void setRadioCapability(RadioCapability rc, Message response) { 4336 mCi.setRadioCapability(rc, response); 4337 } 4338 4339 /** 4340 * Get phone radio access family 4341 * 4342 * @return a bit mask to identify the radio access family. 4343 */ getRadioAccessFamily()4344 public int getRadioAccessFamily() { 4345 final RadioCapability rc = getRadioCapability(); 4346 return (rc == null ? RadioAccessFamily.RAF_UNKNOWN : rc.getRadioAccessFamily()); 4347 } 4348 4349 /** 4350 * Get the associated data modems Id. 4351 * 4352 * @return a String containing the id of the data modem 4353 */ getModemUuId()4354 public String getModemUuId() { 4355 final RadioCapability rc = getRadioCapability(); 4356 return (rc == null ? "" : rc.getLogicalModemUuid()); 4357 } 4358 4359 /** 4360 * Get phone radio capability 4361 * 4362 * @return the capability of the radio defined in RadioCapability 4363 */ getRadioCapability()4364 public RadioCapability getRadioCapability() { 4365 return mRadioCapability.get(); 4366 } 4367 4368 /** 4369 * The RadioCapability has changed. This comes up from the RIL and is called when radios first 4370 * become available or after a capability switch. The flow is we use setRadioCapability to 4371 * request a change with the RIL and get an UNSOL response with the new data which gets set 4372 * here. 4373 * 4374 * @param rc the phone radio capability currently in effect for this phone. 4375 * @param capabilitySwitched whether this method called after a radio capability switch 4376 * completion or called when radios first become available. 4377 */ radioCapabilityUpdated(RadioCapability rc, boolean capabilitySwitched)4378 public void radioCapabilityUpdated(RadioCapability rc, boolean capabilitySwitched) { 4379 // Called when radios first become available or after a capability switch 4380 // Update the cached value 4381 mRadioCapability.set(rc); 4382 4383 if (SubscriptionManager.isValidSubscriptionId(getSubId())) { 4384 boolean restoreSelection = !mContext.getResources().getBoolean( 4385 com.android.internal.R.bool.skip_restoring_network_selection); 4386 sendSubscriptionSettings(restoreSelection); 4387 } 4388 4389 // When radio capability switch is done, query IMEI value and update it in Phone objects 4390 // to make it in sync with the IMEI value currently used by Logical-Modem. 4391 if (capabilitySwitched) { 4392 mCi.getDeviceIdentity(obtainMessage(EVENT_GET_DEVICE_IDENTITY_DONE)); 4393 } 4394 } 4395 sendSubscriptionSettings(boolean restoreNetworkSelection)4396 public void sendSubscriptionSettings(boolean restoreNetworkSelection) { 4397 // Send settings down 4398 if (mIsAllowedNetworkTypesLoadedFromDb) { 4399 updateAllowedNetworkTypes(null); 4400 } 4401 4402 if (restoreNetworkSelection) { 4403 restoreSavedNetworkSelection(null); 4404 } 4405 } 4406 4407 /** 4408 * Registers the handler when phone radio capability is changed. 4409 * 4410 * @param h Handler for notification message. 4411 * @param what User-defined message code. 4412 * @param obj User object. 4413 */ registerForRadioCapabilityChanged(Handler h, int what, Object obj)4414 public void registerForRadioCapabilityChanged(Handler h, int what, Object obj) { 4415 mCi.registerForRadioCapabilityChanged(h, what, obj); 4416 } 4417 4418 /** 4419 * Unregister for notifications when phone radio type and access technology is changed. 4420 * 4421 * @param h Handler to be removed from the registrant list. 4422 */ unregisterForRadioCapabilityChanged(Handler h)4423 public void unregisterForRadioCapabilityChanged(Handler h) { 4424 mCi.unregisterForRadioCapabilityChanged(this); 4425 } 4426 4427 /** 4428 * Determines if the connection to IMS services are available yet. 4429 * @return {@code true} if the connection to IMS services are available. 4430 */ isImsAvailable()4431 public boolean isImsAvailable() { 4432 if (mImsPhone == null) { 4433 return false; 4434 } 4435 4436 return mImsPhone.isImsAvailable(); 4437 } 4438 4439 /** 4440 * Determines if video calling is enabled for the phone. 4441 * 4442 * @return {@code true} if video calling is enabled, {@code false} otherwise. 4443 */ 4444 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) isVideoEnabled()4445 public boolean isVideoEnabled() { 4446 Phone imsPhone = mImsPhone; 4447 if (imsPhone != null) { 4448 return imsPhone.isVideoEnabled(); 4449 } 4450 return false; 4451 } 4452 4453 /** 4454 * Returns the status of Link Capacity Estimation (LCE) service. 4455 */ getLceStatus()4456 public int getLceStatus() { 4457 return mLceStatus; 4458 } 4459 4460 /** 4461 * Returns the modem activity information 4462 */ getModemActivityInfo(Message response, WorkSource workSource)4463 public void getModemActivityInfo(Message response, WorkSource workSource) { 4464 mCi.getModemActivityInfo(response, workSource); 4465 } 4466 4467 /** 4468 * Starts LCE service after radio becomes available. 4469 * LCE service state may get destroyed on the modem when radio becomes unavailable. 4470 */ startLceAfterRadioIsAvailable()4471 public void startLceAfterRadioIsAvailable() { 4472 mCi.startLceService(DEFAULT_REPORT_INTERVAL_MS, LCE_PULL_MODE, 4473 obtainMessage(EVENT_CONFIG_LCE)); 4474 } 4475 4476 /** 4477 * Control the data throttling at modem. 4478 * 4479 * @param result Message that will be sent back to the requester 4480 * @param workSource calling Worksource 4481 * @param dataThrottlingAction the DataThrottlingAction that is being requested. Defined in 4482 * android.telephony.TelephonyManger. 4483 * @param completionWindowMillis milliseconds in which data throttling action has to be 4484 * achieved. 4485 */ setDataThrottling(Message result, WorkSource workSource, int dataThrottlingAction, long completionWindowMillis)4486 public void setDataThrottling(Message result, WorkSource workSource, 4487 int dataThrottlingAction, long completionWindowMillis) { 4488 mCi.setDataThrottling(result, workSource, dataThrottlingAction, completionWindowMillis); 4489 } 4490 4491 /** 4492 * Set allowed carriers 4493 */ setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules, Message response, WorkSource workSource)4494 public void setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules, 4495 Message response, WorkSource workSource) { 4496 mCi.setAllowedCarriers(carrierRestrictionRules, response, workSource); 4497 } 4498 4499 /** Sets the SignalStrength reporting criteria. */ setSignalStrengthReportingCriteria( int signalStrengthMeasure, int[] thresholds, int ran, boolean isEnabled)4500 public void setSignalStrengthReportingCriteria( 4501 int signalStrengthMeasure, int[] thresholds, int ran, boolean isEnabled) { 4502 // no-op default implementation 4503 } 4504 4505 /** Sets the SignalStrength reporting criteria. */ setLinkCapacityReportingCriteria(int[] dlThresholds, int[] ulThresholds, int ran)4506 public void setLinkCapacityReportingCriteria(int[] dlThresholds, int[] ulThresholds, int ran) { 4507 // no-op default implementation 4508 } 4509 4510 /** 4511 * Get allowed carriers 4512 */ getAllowedCarriers(Message response, WorkSource workSource)4513 public void getAllowedCarriers(Message response, WorkSource workSource) { 4514 mCi.getAllowedCarriers(response, workSource); 4515 } 4516 4517 /** 4518 * Returns the locale based on the carrier properties (such as {@code ro.carrier}) and 4519 * SIM preferences. 4520 */ getLocaleFromSimAndCarrierPrefs()4521 public Locale getLocaleFromSimAndCarrierPrefs() { 4522 final IccRecords records = mIccRecords.get(); 4523 if (records != null && records.getSimLanguage() != null) { 4524 return new Locale(records.getSimLanguage()); 4525 } 4526 4527 return getLocaleFromCarrierProperties(); 4528 } 4529 updateCurrentCarrierInProvider()4530 public boolean updateCurrentCarrierInProvider() { 4531 return false; 4532 } 4533 4534 /** 4535 * @return True if all data connections are disconnected. 4536 */ areAllDataDisconnected()4537 public boolean areAllDataDisconnected() { 4538 if (mTransportManager != null) { 4539 for (int transport : mTransportManager.getAvailableTransports()) { 4540 if (getDcTracker(transport) != null 4541 && !getDcTracker(transport).areAllDataDisconnected()) { 4542 return false; 4543 } 4544 } 4545 } 4546 return true; 4547 } 4548 registerForAllDataDisconnected(Handler h, int what)4549 public void registerForAllDataDisconnected(Handler h, int what) { 4550 mAllDataDisconnectedRegistrants.addUnique(h, what, null); 4551 if (mTransportManager != null) { 4552 for (int transport : mTransportManager.getAvailableTransports()) { 4553 if (getDcTracker(transport) != null 4554 && !getDcTracker(transport).areAllDataDisconnected()) { 4555 getDcTracker(transport).registerForAllDataDisconnected( 4556 this, EVENT_ALL_DATA_DISCONNECTED); 4557 } 4558 } 4559 } 4560 } 4561 unregisterForAllDataDisconnected(Handler h)4562 public void unregisterForAllDataDisconnected(Handler h) { 4563 mAllDataDisconnectedRegistrants.remove(h); 4564 } 4565 getDataEnabledSettings()4566 public DataEnabledSettings getDataEnabledSettings() { 4567 return mDataEnabledSettings; 4568 } 4569 4570 @UnsupportedAppUsage getIccSmsInterfaceManager()4571 public IccSmsInterfaceManager getIccSmsInterfaceManager(){ 4572 return null; 4573 } 4574 isMatchGid(String gid)4575 protected boolean isMatchGid(String gid) { 4576 String gid1 = getGroupIdLevel1(); 4577 int gidLength = gid.length(); 4578 if (!TextUtils.isEmpty(gid1) && (gid1.length() >= gidLength) 4579 && gid1.substring(0, gidLength).equalsIgnoreCase(gid)) { 4580 return true; 4581 } 4582 return false; 4583 } 4584 checkWfcWifiOnlyModeBeforeDial(Phone imsPhone, int phoneId, Context context)4585 public static void checkWfcWifiOnlyModeBeforeDial(Phone imsPhone, int phoneId, Context context) 4586 throws CallStateException { 4587 if (imsPhone == null || !imsPhone.isWifiCallingEnabled()) { 4588 ImsManager imsManager = ImsManager.getInstance(context, phoneId); 4589 boolean wfcWiFiOnly = (imsManager.isWfcEnabledByPlatform() 4590 && imsManager.isWfcEnabledByUser() && (imsManager.getWfcMode() 4591 == ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY)); 4592 if (wfcWiFiOnly) { 4593 throw new CallStateException( 4594 CallStateException.ERROR_OUT_OF_SERVICE, 4595 "WFC Wi-Fi Only Mode: IMS not registered"); 4596 } 4597 } 4598 } 4599 startRingbackTone()4600 public void startRingbackTone() { 4601 } 4602 stopRingbackTone()4603 public void stopRingbackTone() { 4604 } 4605 callEndCleanupHandOverCallIfAny()4606 public void callEndCleanupHandOverCallIfAny() { 4607 } 4608 4609 /** 4610 * Cancel USSD session. 4611 * 4612 * @param msg The message to dispatch when the USSD session terminated. 4613 */ cancelUSSD(Message msg)4614 public void cancelUSSD(Message msg) { 4615 } 4616 4617 /** 4618 * Set boolean broadcastEmergencyCallStateChanges 4619 */ setBroadcastEmergencyCallStateChanges(boolean broadcast)4620 public abstract void setBroadcastEmergencyCallStateChanges(boolean broadcast); 4621 sendEmergencyCallStateChange(boolean callActive)4622 public abstract void sendEmergencyCallStateChange(boolean callActive); 4623 4624 /** 4625 * This function returns the parent phone of the current phone. It is applicable 4626 * only for IMS phone (function is overridden by ImsPhone). For others the phone 4627 * object itself is returned. 4628 * @return 4629 */ getDefaultPhone()4630 public Phone getDefaultPhone() { 4631 return this; 4632 } 4633 4634 /** 4635 * SIP URIs aliased to the current subscriber given by the IMS implementation. 4636 * Applicable only on IMS; used in absence of line1number. 4637 * @return array of SIP URIs aliased to the current subscriber 4638 */ getCurrentSubscriberUris()4639 public Uri[] getCurrentSubscriberUris() { 4640 return null; 4641 } 4642 getAppSmsManager()4643 public AppSmsManager getAppSmsManager() { 4644 return mAppSmsManager; 4645 } 4646 4647 /** 4648 * Set SIM card power state. 4649 * @param state State of SIM (power down, power up, pass through) 4650 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} 4651 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} 4652 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} 4653 **/ setSimPowerState(int state, Message result, WorkSource workSource)4654 public void setSimPowerState(int state, Message result, WorkSource workSource) { 4655 mCi.setSimCardPower(state, result, workSource); 4656 } 4657 4658 /** 4659 * Enable or disable Voice over NR (VoNR) 4660 * @param enabled enable or disable VoNR. 4661 **/ setVoNrEnabled(boolean enabled, Message result, WorkSource workSource)4662 public void setVoNrEnabled(boolean enabled, Message result, WorkSource workSource) { 4663 mCi.setVoNrEnabled(enabled, result, workSource); 4664 } 4665 4666 /** 4667 * Is voice over NR enabled 4668 */ isVoNrEnabled(Message message, WorkSource workSource)4669 public void isVoNrEnabled(Message message, WorkSource workSource) { 4670 mCi.isVoNrEnabled(message, workSource); 4671 } 4672 setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, String gid2, String pnn, String spn, String carrierPrivilegeRules, String apn)4673 public void setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, 4674 String gid2, String pnn, String spn, String carrierPrivilegeRules, String apn) { 4675 } 4676 4677 /** 4678 * Check if the device can only make the emergency call. The device is emergency call only if 4679 * none of the phone is in service, and one of them has the capability to make the emergency 4680 * call. 4681 * 4682 * @return {@code True} if the device is emergency call only, otherwise return {@code False}. 4683 */ isEmergencyCallOnly()4684 public static boolean isEmergencyCallOnly() { 4685 boolean isEmergencyCallOnly = false; 4686 for (Phone phone : PhoneFactory.getPhones()) { 4687 if (phone != null) { 4688 ServiceStateTracker sst = phone.getServiceStateTracker(); 4689 ServiceState ss = sst.getServiceState(); 4690 // Combined reg state is in service, hence the device is not emergency call only. 4691 if (sst.getCombinedRegState(ss) == ServiceState.STATE_IN_SERVICE) { 4692 return false; 4693 } 4694 isEmergencyCallOnly |= ss.isEmergencyOnly(); 4695 } 4696 } 4697 return isEmergencyCallOnly; 4698 } 4699 4700 /** 4701 * Get data connection tracker based on the transport type 4702 * 4703 * @param transportType Transport type defined in AccessNetworkConstants.TransportType 4704 * @return The data connection tracker. Null if not found. 4705 */ getDcTracker(int transportType)4706 public @Nullable DcTracker getDcTracker(int transportType) { 4707 return mDcTrackers.get(transportType); 4708 } 4709 4710 // Return true if either CSIM or RUIM app is present. By default it returns false. isCdmaSubscriptionAppPresent()4711 public boolean isCdmaSubscriptionAppPresent() { 4712 return false; 4713 } 4714 4715 /** 4716 * Enable or disable uicc applications. 4717 * @param enable whether to enable or disable uicc applications. 4718 * @param onCompleteMessage callback for async operation. Ignored if blockingCall is true. 4719 */ enableUiccApplications(boolean enable, Message onCompleteMessage)4720 public void enableUiccApplications(boolean enable, Message onCompleteMessage) {} 4721 4722 /** 4723 * Whether disabling a physical subscription is supported or not. 4724 */ canDisablePhysicalSubscription()4725 public boolean canDisablePhysicalSubscription() { 4726 return false; 4727 } 4728 4729 /** 4730 * Get the HAL version. 4731 * 4732 * @return the current HalVersion 4733 */ getHalVersion()4734 public HalVersion getHalVersion() { 4735 if (mCi != null && mCi instanceof RIL) { 4736 return ((RIL) mCi).getHalVersion(); 4737 } 4738 return RIL.RADIO_HAL_VERSION_UNKNOWN; 4739 } 4740 4741 /** 4742 * Get the SIM's MCC/MNC 4743 * 4744 * @return MCC/MNC in string format, empty string if not available. 4745 */ 4746 @NonNull getOperatorNumeric()4747 public String getOperatorNumeric() { 4748 return ""; 4749 } 4750 4751 /** Returns the {@link VoiceCallSessionStats} for this phone ID. */ getVoiceCallSessionStats()4752 public VoiceCallSessionStats getVoiceCallSessionStats() { 4753 return mVoiceCallSessionStats; 4754 } 4755 4756 /** Sets the {@link VoiceCallSessionStats} mock for this phone ID during unit testing. */ 4757 @VisibleForTesting setVoiceCallSessionStats(VoiceCallSessionStats voiceCallSessionStats)4758 public void setVoiceCallSessionStats(VoiceCallSessionStats voiceCallSessionStats) { 4759 mVoiceCallSessionStats = voiceCallSessionStats; 4760 } 4761 4762 /** Returns the {@link SmsStats} for this phone ID. */ getSmsStats()4763 public SmsStats getSmsStats() { 4764 return mSmsStats; 4765 } 4766 4767 /** Sets the {@link SmsStats} mock for this phone ID during unit testing. */ 4768 @VisibleForTesting setSmsStats(SmsStats smsStats)4769 public void setSmsStats(SmsStats smsStats) { 4770 mSmsStats = smsStats; 4771 } 4772 4773 /** @hide */ getCarrierPrivilegesTracker()4774 public CarrierPrivilegesTracker getCarrierPrivilegesTracker() { 4775 return mCarrierPrivilegesTracker; 4776 } 4777 useSsOverIms(Message onComplete)4778 public boolean useSsOverIms(Message onComplete) { 4779 return false; 4780 } 4781 4782 /** 4783 * Check if device is idle. Device is idle when it is not in high power consumption mode. 4784 * 4785 * @see DeviceStateMonitor#shouldEnableHighPowerConsumptionIndications() 4786 * 4787 * @return true if device is idle 4788 */ isDeviceIdle()4789 public boolean isDeviceIdle() { 4790 DeviceStateMonitor dsm = getDeviceStateMonitor(); 4791 if (dsm == null) { 4792 Rlog.e(LOG_TAG, "isDeviceIdle: DeviceStateMonitor is null"); 4793 return false; 4794 } 4795 return !dsm.shouldEnableHighPowerConsumptionIndications(); 4796 } 4797 4798 /** 4799 * Get notified when device idleness state has changed 4800 * 4801 * @param isIdle true if the new state is idle 4802 */ notifyDeviceIdleStateChanged(boolean isIdle)4803 public void notifyDeviceIdleStateChanged(boolean isIdle) { 4804 ServiceStateTracker sst = getServiceStateTracker(); 4805 if (sst == null) { 4806 Rlog.e(LOG_TAG, "notifyDeviceIdleStateChanged: SST is null"); 4807 return; 4808 } 4809 sst.onDeviceIdleStateChanged(isIdle); 4810 } 4811 4812 /** 4813 * Returns a list of the equivalent home PLMNs (EF_EHPLMN) from the USIM app. 4814 * 4815 * @return A list of equivalent home PLMNs. Returns an empty list if EF_EHPLMN is empty or 4816 * does not exist on the SIM card. 4817 */ getEquivalentHomePlmns()4818 public @NonNull List<String> getEquivalentHomePlmns() { 4819 return Collections.emptyList(); 4820 } 4821 4822 /** 4823 * 4824 * @return 4825 */ getDataServicePackages()4826 public @NonNull List<String> getDataServicePackages() { 4827 return Collections.emptyList(); 4828 } 4829 4830 /** 4831 * Return link bandwidth estimator 4832 */ getLinkBandwidthEstimator()4833 public LinkBandwidthEstimator getLinkBandwidthEstimator() { 4834 return mLinkBandwidthEstimator; 4835 } 4836 4837 /** 4838 * Request to get the current slicing configuration including URSP rules and 4839 * NSSAIs (configured, allowed and rejected). 4840 */ getSlicingConfig(Message response)4841 public void getSlicingConfig(Message response) { 4842 mCi.getSlicingConfig(response); 4843 } 4844 4845 /** 4846 * Returns the InboundSmsHandler object for this phone 4847 */ getInboundSmsHandler(boolean is3gpp2)4848 public InboundSmsHandler getInboundSmsHandler(boolean is3gpp2) { 4849 return null; 4850 } 4851 dump(FileDescriptor fd, PrintWriter pw, String[] args)4852 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 4853 pw.println("Phone: subId=" + getSubId()); 4854 pw.println(" mPhoneId=" + mPhoneId); 4855 pw.println(" mCi=" + mCi); 4856 pw.println(" mDnsCheckDisabled=" + mDnsCheckDisabled); 4857 pw.println(" mDoesRilSendMultipleCallRing=" + mDoesRilSendMultipleCallRing); 4858 pw.println(" mCallRingContinueToken=" + mCallRingContinueToken); 4859 pw.println(" mCallRingDelay=" + mCallRingDelay); 4860 pw.println(" mIsVoiceCapable=" + mIsVoiceCapable); 4861 pw.println(" mIccRecords=" + mIccRecords.get()); 4862 pw.println(" mUiccApplication=" + mUiccApplication.get()); 4863 pw.println(" mSmsStorageMonitor=" + mSmsStorageMonitor); 4864 pw.println(" mSmsUsageMonitor=" + mSmsUsageMonitor); 4865 pw.flush(); 4866 pw.println(" mLooper=" + mLooper); 4867 pw.println(" mContext=" + mContext); 4868 pw.println(" mNotifier=" + mNotifier); 4869 pw.println(" mSimulatedRadioControl=" + mSimulatedRadioControl); 4870 pw.println(" mUnitTestMode=" + mUnitTestMode); 4871 pw.println(" isDnsCheckDisabled()=" + isDnsCheckDisabled()); 4872 pw.println(" getUnitTestMode()=" + getUnitTestMode()); 4873 pw.println(" getState()=" + getState()); 4874 pw.println(" getIccSerialNumber()=" + getIccSerialNumber()); 4875 pw.println(" getIccRecordsLoaded()=" + getIccRecordsLoaded()); 4876 pw.println(" getMessageWaitingIndicator()=" + getMessageWaitingIndicator()); 4877 pw.println(" getCallForwardingIndicator()=" + getCallForwardingIndicator()); 4878 pw.println(" isInEmergencyCall()=" + isInEmergencyCall()); 4879 pw.flush(); 4880 pw.println(" isInEcm()=" + isInEcm()); 4881 pw.println(" getPhoneName()=" + getPhoneName()); 4882 pw.println(" getPhoneType()=" + getPhoneType()); 4883 pw.println(" getVoiceMessageCount()=" + getVoiceMessageCount()); 4884 pw.println(" getActiveApnTypes()=" + getActiveApnTypes()); 4885 pw.println(" needsOtaServiceProvisioning=" + needsOtaServiceProvisioning()); 4886 pw.println(" isInEmergencySmsMode=" + isInEmergencySmsMode()); 4887 pw.println(" isEcmCanceledForEmergency=" + isEcmCanceledForEmergency()); 4888 pw.println(" service state=" + getServiceState()); 4889 pw.flush(); 4890 pw.println("++++++++++++++++++++++++++++++++"); 4891 4892 if (mImsPhone != null) { 4893 try { 4894 mImsPhone.dump(fd, pw, args); 4895 } catch (Exception e) { 4896 e.printStackTrace(); 4897 } 4898 4899 pw.flush(); 4900 pw.println("++++++++++++++++++++++++++++++++"); 4901 } 4902 4903 if (mTransportManager != null) { 4904 for (int transport : mTransportManager.getAvailableTransports()) { 4905 if (getDcTracker(transport) != null) { 4906 getDcTracker(transport).dump(fd, pw, args); 4907 pw.flush(); 4908 pw.println("++++++++++++++++++++++++++++++++"); 4909 } 4910 } 4911 } 4912 4913 if (getServiceStateTracker() != null) { 4914 try { 4915 getServiceStateTracker().dump(fd, pw, args); 4916 } catch (Exception e) { 4917 e.printStackTrace(); 4918 } 4919 4920 pw.flush(); 4921 pw.println("++++++++++++++++++++++++++++++++"); 4922 } 4923 4924 if (getEmergencyNumberTracker() != null) { 4925 try { 4926 getEmergencyNumberTracker().dump(fd, pw, args); 4927 } catch (Exception e) { 4928 e.printStackTrace(); 4929 } 4930 4931 pw.flush(); 4932 pw.println("++++++++++++++++++++++++++++++++"); 4933 } 4934 4935 if (getDisplayInfoController() != null) { 4936 try { 4937 getDisplayInfoController().dump(fd, pw, args); 4938 } catch (Exception e) { 4939 e.printStackTrace(); 4940 } 4941 4942 pw.flush(); 4943 pw.println("++++++++++++++++++++++++++++++++"); 4944 } 4945 4946 if (mCarrierResolver != null) { 4947 try { 4948 mCarrierResolver.dump(fd, pw, args); 4949 } catch (Exception e) { 4950 e.printStackTrace(); 4951 } 4952 4953 pw.flush(); 4954 pw.println("++++++++++++++++++++++++++++++++"); 4955 } 4956 4957 if (mCarrierActionAgent != null) { 4958 try { 4959 mCarrierActionAgent.dump(fd, pw, args); 4960 } catch (Exception e) { 4961 e.printStackTrace(); 4962 } 4963 4964 pw.flush(); 4965 pw.println("++++++++++++++++++++++++++++++++"); 4966 } 4967 4968 if (mCarrierSignalAgent != null) { 4969 try { 4970 mCarrierSignalAgent.dump(fd, pw, args); 4971 } catch (Exception e) { 4972 e.printStackTrace(); 4973 } 4974 4975 pw.flush(); 4976 pw.println("++++++++++++++++++++++++++++++++"); 4977 } 4978 4979 if (getCallTracker() != null) { 4980 try { 4981 getCallTracker().dump(fd, pw, args); 4982 } catch (Exception e) { 4983 e.printStackTrace(); 4984 } 4985 4986 pw.flush(); 4987 pw.println("++++++++++++++++++++++++++++++++"); 4988 } 4989 4990 if (mSimActivationTracker != null) { 4991 try { 4992 mSimActivationTracker.dump(fd, pw, args); 4993 } catch (Exception e) { 4994 e.printStackTrace(); 4995 } 4996 4997 pw.flush(); 4998 pw.println("++++++++++++++++++++++++++++++++"); 4999 } 5000 5001 if (mDeviceStateMonitor != null) { 5002 pw.println("DeviceStateMonitor:"); 5003 mDeviceStateMonitor.dump(fd, pw, args); 5004 pw.println("++++++++++++++++++++++++++++++++"); 5005 } 5006 5007 if (mTransportManager != null) { 5008 mTransportManager.dump(fd, pw, args); 5009 } 5010 5011 if (mCi != null && mCi instanceof RIL) { 5012 try { 5013 ((RIL)mCi).dump(fd, pw, args); 5014 } catch (Exception e) { 5015 e.printStackTrace(); 5016 } 5017 5018 pw.flush(); 5019 pw.println("++++++++++++++++++++++++++++++++"); 5020 } 5021 5022 if (getCarrierPrivilegesTracker() != null) { 5023 pw.println("CarrierPrivilegesTracker:"); 5024 getCarrierPrivilegesTracker().dump(fd, pw, args); 5025 pw.println("++++++++++++++++++++++++++++++++"); 5026 } 5027 5028 if (getLinkBandwidthEstimator() != null) { 5029 pw.println("LinkBandwidthEstimator:"); 5030 getLinkBandwidthEstimator().dump(fd, pw, args); 5031 pw.println("++++++++++++++++++++++++++++++++"); 5032 } 5033 5034 pw.println("Phone Local Log: "); 5035 if (mLocalLog != null) { 5036 try { 5037 mLocalLog.dump(fd, pw, args); 5038 } catch (Exception e) { 5039 e.printStackTrace(); 5040 } 5041 pw.flush(); 5042 pw.println("++++++++++++++++++++++++++++++++"); 5043 } 5044 } 5045 logd(String s)5046 private void logd(String s) { 5047 Rlog.d(LOG_TAG, "[" + mPhoneId + "] " + s); 5048 } 5049 logi(String s)5050 private void logi(String s) { 5051 Rlog.i(LOG_TAG, "[" + mPhoneId + "] " + s); 5052 } 5053 loge(String s)5054 private void loge(String s) { 5055 Rlog.e(LOG_TAG, "[" + mPhoneId + "] " + s); 5056 } 5057 pii(String s)5058 private static String pii(String s) { 5059 return Rlog.pii(LOG_TAG, s); 5060 } 5061 5062 /** 5063 * Used in unit tests to set whether the AllowedNetworkTypes is loaded from Db. Should not 5064 * be used otherwise. 5065 * 5066 * @return {@code true} if the AllowedNetworkTypes is loaded from Db, 5067 * {@code false} otherwise. 5068 */ 5069 @VisibleForTesting isAllowedNetworkTypesLoadedFromDb()5070 public boolean isAllowedNetworkTypesLoadedFromDb() { 5071 return mIsAllowedNetworkTypesLoadedFromDb; 5072 } 5073 } 5074