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