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