1 2 /* 3 * Copyright (C) 2006 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.internal.telephony; 19 20 import android.content.Context; 21 import android.os.AsyncResult; 22 import android.os.Handler; 23 import android.os.Message; 24 import android.os.Registrant; 25 import android.os.RegistrantList; 26 import android.telephony.TelephonyManager; 27 28 /** 29 * {@hide} 30 */ 31 public abstract class BaseCommands implements CommandsInterface { 32 //***** Instance Variables 33 protected Context mContext; 34 protected RadioState mState = RadioState.RADIO_UNAVAILABLE; 35 protected Object mStateMonitor = new Object(); 36 37 protected RegistrantList mRadioStateChangedRegistrants = new RegistrantList(); 38 protected RegistrantList mOnRegistrants = new RegistrantList(); 39 protected RegistrantList mAvailRegistrants = new RegistrantList(); 40 protected RegistrantList mOffOrNotAvailRegistrants = new RegistrantList(); 41 protected RegistrantList mNotAvailRegistrants = new RegistrantList(); 42 protected RegistrantList mCallStateRegistrants = new RegistrantList(); 43 protected RegistrantList mNetworkStateRegistrants = new RegistrantList(); 44 protected RegistrantList mDataCallListChangedRegistrants = new RegistrantList(); 45 protected RegistrantList mVoiceRadioTechChangedRegistrants = new RegistrantList(); 46 protected RegistrantList mImsNetworkStateChangedRegistrants = new RegistrantList(); 47 protected RegistrantList mIccStatusChangedRegistrants = new RegistrantList(); 48 protected RegistrantList mIccSlotStatusChangedRegistrants = new RegistrantList(); 49 protected RegistrantList mVoicePrivacyOnRegistrants = new RegistrantList(); 50 protected RegistrantList mVoicePrivacyOffRegistrants = new RegistrantList(); 51 protected Registrant mUnsolOemHookRawRegistrant; 52 protected RegistrantList mOtaProvisionRegistrants = new RegistrantList(); 53 protected RegistrantList mCallWaitingInfoRegistrants = new RegistrantList(); 54 protected RegistrantList mDisplayInfoRegistrants = new RegistrantList(); 55 protected RegistrantList mSignalInfoRegistrants = new RegistrantList(); 56 protected RegistrantList mNumberInfoRegistrants = new RegistrantList(); 57 protected RegistrantList mRedirNumInfoRegistrants = new RegistrantList(); 58 protected RegistrantList mLineControlInfoRegistrants = new RegistrantList(); 59 protected RegistrantList mT53ClirInfoRegistrants = new RegistrantList(); 60 protected RegistrantList mT53AudCntrlInfoRegistrants = new RegistrantList(); 61 protected RegistrantList mRingbackToneRegistrants = new RegistrantList(); 62 protected RegistrantList mResendIncallMuteRegistrants = new RegistrantList(); 63 protected RegistrantList mCdmaSubscriptionChangedRegistrants = new RegistrantList(); 64 protected RegistrantList mCdmaPrlChangedRegistrants = new RegistrantList(); 65 protected RegistrantList mExitEmergencyCallbackModeRegistrants = new RegistrantList(); 66 protected RegistrantList mRilConnectedRegistrants = new RegistrantList(); 67 protected RegistrantList mIccRefreshRegistrants = new RegistrantList(); 68 protected RegistrantList mRilCellInfoListRegistrants = new RegistrantList(); 69 protected RegistrantList mSubscriptionStatusRegistrants = new RegistrantList(); 70 protected RegistrantList mSrvccStateRegistrants = new RegistrantList(); 71 protected RegistrantList mHardwareConfigChangeRegistrants = new RegistrantList(); 72 protected RegistrantList mPhoneRadioCapabilityChangedRegistrants = 73 new RegistrantList(); 74 protected RegistrantList mPcoDataRegistrants = new RegistrantList(); 75 protected RegistrantList mCarrierInfoForImsiEncryptionRegistrants = new RegistrantList(); 76 protected RegistrantList mRilNetworkScanResultRegistrants = new RegistrantList(); 77 protected RegistrantList mModemResetRegistrants = new RegistrantList(); 78 protected RegistrantList mNattKeepaliveStatusRegistrants = new RegistrantList(); 79 protected RegistrantList mPhysicalChannelConfigurationRegistrants = new RegistrantList(); 80 protected RegistrantList mLceInfoRegistrants = new RegistrantList(); 81 82 protected Registrant mGsmSmsRegistrant; 83 protected Registrant mCdmaSmsRegistrant; 84 protected Registrant mNITZTimeRegistrant; 85 protected Registrant mSignalStrengthRegistrant; 86 protected Registrant mUSSDRegistrant; 87 protected Registrant mSmsOnSimRegistrant; 88 protected Registrant mSmsStatusRegistrant; 89 protected Registrant mSsnRegistrant; 90 protected Registrant mCatSessionEndRegistrant; 91 protected Registrant mCatProCmdRegistrant; 92 protected Registrant mCatEventRegistrant; 93 protected Registrant mCatCallSetUpRegistrant; 94 protected Registrant mIccSmsFullRegistrant; 95 protected Registrant mEmergencyCallbackModeRegistrant; 96 protected Registrant mRingRegistrant; 97 protected Registrant mRestrictedStateRegistrant; 98 protected Registrant mGsmBroadcastSmsRegistrant; 99 protected Registrant mCatCcAlphaRegistrant; 100 protected Registrant mSsRegistrant; 101 102 // Preferred network type received from PhoneFactory. 103 // This is used when establishing a connection to the 104 // vendor ril so it starts up in the correct mode. 105 protected int mPreferredNetworkType; 106 // CDMA subscription received from PhoneFactory 107 protected int mCdmaSubscription; 108 // Type of Phone, GSM or CDMA. Set by GsmCdmaPhone. 109 protected int mPhoneType; 110 // RIL Version 111 protected int mRilVersion = -1; 112 BaseCommands(Context context)113 public BaseCommands(Context context) { 114 mContext = context; // May be null (if so we won't log statistics) 115 } 116 117 //***** CommandsInterface implementation 118 119 @Override getRadioState()120 public RadioState getRadioState() { 121 return mState; 122 } 123 124 @Override registerForRadioStateChanged(Handler h, int what, Object obj)125 public void registerForRadioStateChanged(Handler h, int what, Object obj) { 126 Registrant r = new Registrant (h, what, obj); 127 128 synchronized (mStateMonitor) { 129 mRadioStateChangedRegistrants.add(r); 130 r.notifyRegistrant(); 131 } 132 } 133 134 @Override unregisterForRadioStateChanged(Handler h)135 public void unregisterForRadioStateChanged(Handler h) { 136 synchronized (mStateMonitor) { 137 mRadioStateChangedRegistrants.remove(h); 138 } 139 } 140 registerForImsNetworkStateChanged(Handler h, int what, Object obj)141 public void registerForImsNetworkStateChanged(Handler h, int what, Object obj) { 142 Registrant r = new Registrant (h, what, obj); 143 mImsNetworkStateChangedRegistrants.add(r); 144 } 145 unregisterForImsNetworkStateChanged(Handler h)146 public void unregisterForImsNetworkStateChanged(Handler h) { 147 mImsNetworkStateChangedRegistrants.remove(h); 148 } 149 150 @Override registerForOn(Handler h, int what, Object obj)151 public void registerForOn(Handler h, int what, Object obj) { 152 Registrant r = new Registrant (h, what, obj); 153 154 synchronized (mStateMonitor) { 155 mOnRegistrants.add(r); 156 157 if (mState.isOn()) { 158 r.notifyRegistrant(new AsyncResult(null, null, null)); 159 } 160 } 161 } 162 @Override unregisterForOn(Handler h)163 public void unregisterForOn(Handler h) { 164 synchronized (mStateMonitor) { 165 mOnRegistrants.remove(h); 166 } 167 } 168 169 170 @Override registerForAvailable(Handler h, int what, Object obj)171 public void registerForAvailable(Handler h, int what, Object obj) { 172 Registrant r = new Registrant (h, what, obj); 173 174 synchronized (mStateMonitor) { 175 mAvailRegistrants.add(r); 176 177 if (mState.isAvailable()) { 178 r.notifyRegistrant(new AsyncResult(null, null, null)); 179 } 180 } 181 } 182 183 @Override unregisterForAvailable(Handler h)184 public void unregisterForAvailable(Handler h) { 185 synchronized(mStateMonitor) { 186 mAvailRegistrants.remove(h); 187 } 188 } 189 190 @Override registerForNotAvailable(Handler h, int what, Object obj)191 public void registerForNotAvailable(Handler h, int what, Object obj) { 192 Registrant r = new Registrant (h, what, obj); 193 194 synchronized (mStateMonitor) { 195 mNotAvailRegistrants.add(r); 196 197 if (!mState.isAvailable()) { 198 r.notifyRegistrant(new AsyncResult(null, null, null)); 199 } 200 } 201 } 202 203 @Override unregisterForNotAvailable(Handler h)204 public void unregisterForNotAvailable(Handler h) { 205 synchronized (mStateMonitor) { 206 mNotAvailRegistrants.remove(h); 207 } 208 } 209 210 @Override registerForOffOrNotAvailable(Handler h, int what, Object obj)211 public void registerForOffOrNotAvailable(Handler h, int what, Object obj) { 212 Registrant r = new Registrant (h, what, obj); 213 214 synchronized (mStateMonitor) { 215 mOffOrNotAvailRegistrants.add(r); 216 217 if (mState == RadioState.RADIO_OFF || !mState.isAvailable()) { 218 r.notifyRegistrant(new AsyncResult(null, null, null)); 219 } 220 } 221 } 222 @Override unregisterForOffOrNotAvailable(Handler h)223 public void unregisterForOffOrNotAvailable(Handler h) { 224 synchronized(mStateMonitor) { 225 mOffOrNotAvailRegistrants.remove(h); 226 } 227 } 228 229 @Override registerForCallStateChanged(Handler h, int what, Object obj)230 public void registerForCallStateChanged(Handler h, int what, Object obj) { 231 Registrant r = new Registrant (h, what, obj); 232 233 mCallStateRegistrants.add(r); 234 } 235 236 @Override unregisterForCallStateChanged(Handler h)237 public void unregisterForCallStateChanged(Handler h) { 238 mCallStateRegistrants.remove(h); 239 } 240 241 @Override registerForNetworkStateChanged(Handler h, int what, Object obj)242 public void registerForNetworkStateChanged(Handler h, int what, Object obj) { 243 Registrant r = new Registrant (h, what, obj); 244 245 mNetworkStateRegistrants.add(r); 246 } 247 248 @Override unregisterForNetworkStateChanged(Handler h)249 public void unregisterForNetworkStateChanged(Handler h) { 250 mNetworkStateRegistrants.remove(h); 251 } 252 253 @Override registerForDataCallListChanged(Handler h, int what, Object obj)254 public void registerForDataCallListChanged(Handler h, int what, Object obj) { 255 Registrant r = new Registrant (h, what, obj); 256 257 mDataCallListChangedRegistrants.add(r); 258 } 259 260 @Override unregisterForDataCallListChanged(Handler h)261 public void unregisterForDataCallListChanged(Handler h) { 262 mDataCallListChangedRegistrants.remove(h); 263 } 264 265 @Override registerForVoiceRadioTechChanged(Handler h, int what, Object obj)266 public void registerForVoiceRadioTechChanged(Handler h, int what, Object obj) { 267 Registrant r = new Registrant (h, what, obj); 268 mVoiceRadioTechChangedRegistrants.add(r); 269 } 270 271 @Override unregisterForVoiceRadioTechChanged(Handler h)272 public void unregisterForVoiceRadioTechChanged(Handler h) { 273 mVoiceRadioTechChangedRegistrants.remove(h); 274 } 275 276 @Override registerForIccStatusChanged(Handler h, int what, Object obj)277 public void registerForIccStatusChanged(Handler h, int what, Object obj) { 278 Registrant r = new Registrant (h, what, obj); 279 mIccStatusChangedRegistrants.add(r); 280 } 281 282 @Override unregisterForIccStatusChanged(Handler h)283 public void unregisterForIccStatusChanged(Handler h) { 284 mIccStatusChangedRegistrants.remove(h); 285 } 286 287 @Override registerForIccSlotStatusChanged(Handler h, int what, Object obj)288 public void registerForIccSlotStatusChanged(Handler h, int what, Object obj) { 289 Registrant r = new Registrant(h, what, obj); 290 mIccSlotStatusChangedRegistrants.add(r); 291 } 292 293 @Override unregisterForIccSlotStatusChanged(Handler h)294 public void unregisterForIccSlotStatusChanged(Handler h) { 295 mIccSlotStatusChangedRegistrants.remove(h); 296 } 297 298 @Override setOnNewGsmSms(Handler h, int what, Object obj)299 public void setOnNewGsmSms(Handler h, int what, Object obj) { 300 mGsmSmsRegistrant = new Registrant (h, what, obj); 301 } 302 303 @Override unSetOnNewGsmSms(Handler h)304 public void unSetOnNewGsmSms(Handler h) { 305 if (mGsmSmsRegistrant != null && mGsmSmsRegistrant.getHandler() == h) { 306 mGsmSmsRegistrant.clear(); 307 mGsmSmsRegistrant = null; 308 } 309 } 310 311 @Override setOnNewCdmaSms(Handler h, int what, Object obj)312 public void setOnNewCdmaSms(Handler h, int what, Object obj) { 313 mCdmaSmsRegistrant = new Registrant (h, what, obj); 314 } 315 316 @Override unSetOnNewCdmaSms(Handler h)317 public void unSetOnNewCdmaSms(Handler h) { 318 if (mCdmaSmsRegistrant != null && mCdmaSmsRegistrant.getHandler() == h) { 319 mCdmaSmsRegistrant.clear(); 320 mCdmaSmsRegistrant = null; 321 } 322 } 323 324 @Override setOnNewGsmBroadcastSms(Handler h, int what, Object obj)325 public void setOnNewGsmBroadcastSms(Handler h, int what, Object obj) { 326 mGsmBroadcastSmsRegistrant = new Registrant (h, what, obj); 327 } 328 329 @Override unSetOnNewGsmBroadcastSms(Handler h)330 public void unSetOnNewGsmBroadcastSms(Handler h) { 331 if (mGsmBroadcastSmsRegistrant != null && mGsmBroadcastSmsRegistrant.getHandler() == h) { 332 mGsmBroadcastSmsRegistrant.clear(); 333 mGsmBroadcastSmsRegistrant = null; 334 } 335 } 336 337 @Override setOnSmsOnSim(Handler h, int what, Object obj)338 public void setOnSmsOnSim(Handler h, int what, Object obj) { 339 mSmsOnSimRegistrant = new Registrant (h, what, obj); 340 } 341 342 @Override unSetOnSmsOnSim(Handler h)343 public void unSetOnSmsOnSim(Handler h) { 344 if (mSmsOnSimRegistrant != null && mSmsOnSimRegistrant.getHandler() == h) { 345 mSmsOnSimRegistrant.clear(); 346 mSmsOnSimRegistrant = null; 347 } 348 } 349 350 @Override setOnSmsStatus(Handler h, int what, Object obj)351 public void setOnSmsStatus(Handler h, int what, Object obj) { 352 mSmsStatusRegistrant = new Registrant (h, what, obj); 353 } 354 355 @Override unSetOnSmsStatus(Handler h)356 public void unSetOnSmsStatus(Handler h) { 357 if (mSmsStatusRegistrant != null && mSmsStatusRegistrant.getHandler() == h) { 358 mSmsStatusRegistrant.clear(); 359 mSmsStatusRegistrant = null; 360 } 361 } 362 363 @Override setOnSignalStrengthUpdate(Handler h, int what, Object obj)364 public void setOnSignalStrengthUpdate(Handler h, int what, Object obj) { 365 mSignalStrengthRegistrant = new Registrant (h, what, obj); 366 } 367 368 @Override unSetOnSignalStrengthUpdate(Handler h)369 public void unSetOnSignalStrengthUpdate(Handler h) { 370 if (mSignalStrengthRegistrant != null && mSignalStrengthRegistrant.getHandler() == h) { 371 mSignalStrengthRegistrant.clear(); 372 mSignalStrengthRegistrant = null; 373 } 374 } 375 376 @Override setOnNITZTime(Handler h, int what, Object obj)377 public void setOnNITZTime(Handler h, int what, Object obj) { 378 mNITZTimeRegistrant = new Registrant (h, what, obj); 379 } 380 381 @Override unSetOnNITZTime(Handler h)382 public void unSetOnNITZTime(Handler h) { 383 if (mNITZTimeRegistrant != null && mNITZTimeRegistrant.getHandler() == h) { 384 mNITZTimeRegistrant.clear(); 385 mNITZTimeRegistrant = null; 386 } 387 } 388 389 @Override setOnUSSD(Handler h, int what, Object obj)390 public void setOnUSSD(Handler h, int what, Object obj) { 391 mUSSDRegistrant = new Registrant (h, what, obj); 392 } 393 394 @Override unSetOnUSSD(Handler h)395 public void unSetOnUSSD(Handler h) { 396 if (mUSSDRegistrant != null && mUSSDRegistrant.getHandler() == h) { 397 mUSSDRegistrant.clear(); 398 mUSSDRegistrant = null; 399 } 400 } 401 402 @Override setOnSuppServiceNotification(Handler h, int what, Object obj)403 public void setOnSuppServiceNotification(Handler h, int what, Object obj) { 404 mSsnRegistrant = new Registrant (h, what, obj); 405 } 406 407 @Override unSetOnSuppServiceNotification(Handler h)408 public void unSetOnSuppServiceNotification(Handler h) { 409 if (mSsnRegistrant != null && mSsnRegistrant.getHandler() == h) { 410 mSsnRegistrant.clear(); 411 mSsnRegistrant = null; 412 } 413 } 414 415 @Override setOnCatSessionEnd(Handler h, int what, Object obj)416 public void setOnCatSessionEnd(Handler h, int what, Object obj) { 417 mCatSessionEndRegistrant = new Registrant (h, what, obj); 418 } 419 420 @Override unSetOnCatSessionEnd(Handler h)421 public void unSetOnCatSessionEnd(Handler h) { 422 if (mCatSessionEndRegistrant != null && mCatSessionEndRegistrant.getHandler() == h) { 423 mCatSessionEndRegistrant.clear(); 424 mCatSessionEndRegistrant = null; 425 } 426 } 427 428 @Override setOnCatProactiveCmd(Handler h, int what, Object obj)429 public void setOnCatProactiveCmd(Handler h, int what, Object obj) { 430 mCatProCmdRegistrant = new Registrant (h, what, obj); 431 } 432 433 @Override unSetOnCatProactiveCmd(Handler h)434 public void unSetOnCatProactiveCmd(Handler h) { 435 if (mCatProCmdRegistrant != null && mCatProCmdRegistrant.getHandler() == h) { 436 mCatProCmdRegistrant.clear(); 437 mCatProCmdRegistrant = null; 438 } 439 } 440 441 @Override setOnCatEvent(Handler h, int what, Object obj)442 public void setOnCatEvent(Handler h, int what, Object obj) { 443 mCatEventRegistrant = new Registrant (h, what, obj); 444 } 445 446 @Override unSetOnCatEvent(Handler h)447 public void unSetOnCatEvent(Handler h) { 448 if (mCatEventRegistrant != null && mCatEventRegistrant.getHandler() == h) { 449 mCatEventRegistrant.clear(); 450 mCatEventRegistrant = null; 451 } 452 } 453 454 @Override setOnCatCallSetUp(Handler h, int what, Object obj)455 public void setOnCatCallSetUp(Handler h, int what, Object obj) { 456 mCatCallSetUpRegistrant = new Registrant (h, what, obj); 457 } 458 459 @Override unSetOnCatCallSetUp(Handler h)460 public void unSetOnCatCallSetUp(Handler h) { 461 if (mCatCallSetUpRegistrant != null && mCatCallSetUpRegistrant.getHandler() == h) { 462 mCatCallSetUpRegistrant.clear(); 463 mCatCallSetUpRegistrant = null; 464 } 465 } 466 467 @Override setOnIccSmsFull(Handler h, int what, Object obj)468 public void setOnIccSmsFull(Handler h, int what, Object obj) { 469 mIccSmsFullRegistrant = new Registrant (h, what, obj); 470 } 471 472 @Override unSetOnIccSmsFull(Handler h)473 public void unSetOnIccSmsFull(Handler h) { 474 if (mIccSmsFullRegistrant != null && mIccSmsFullRegistrant.getHandler() == h) { 475 mIccSmsFullRegistrant.clear(); 476 mIccSmsFullRegistrant = null; 477 } 478 } 479 480 @Override registerForIccRefresh(Handler h, int what, Object obj)481 public void registerForIccRefresh(Handler h, int what, Object obj) { 482 Registrant r = new Registrant (h, what, obj); 483 mIccRefreshRegistrants.add(r); 484 } 485 @Override setOnIccRefresh(Handler h, int what, Object obj)486 public void setOnIccRefresh(Handler h, int what, Object obj) { 487 registerForIccRefresh(h, what, obj); 488 } 489 490 @Override setEmergencyCallbackMode(Handler h, int what, Object obj)491 public void setEmergencyCallbackMode(Handler h, int what, Object obj) { 492 mEmergencyCallbackModeRegistrant = new Registrant (h, what, obj); 493 } 494 495 @Override unregisterForIccRefresh(Handler h)496 public void unregisterForIccRefresh(Handler h) { 497 mIccRefreshRegistrants.remove(h); 498 } 499 @Override unsetOnIccRefresh(Handler h)500 public void unsetOnIccRefresh(Handler h) { 501 unregisterForIccRefresh(h); 502 } 503 504 @Override setOnCallRing(Handler h, int what, Object obj)505 public void setOnCallRing(Handler h, int what, Object obj) { 506 mRingRegistrant = new Registrant (h, what, obj); 507 } 508 509 @Override unSetOnCallRing(Handler h)510 public void unSetOnCallRing(Handler h) { 511 if (mRingRegistrant != null && mRingRegistrant.getHandler() == h) { 512 mRingRegistrant.clear(); 513 mRingRegistrant = null; 514 } 515 } 516 517 @Override setOnSs(Handler h, int what, Object obj)518 public void setOnSs(Handler h, int what, Object obj) { 519 mSsRegistrant = new Registrant (h, what, obj); 520 } 521 522 @Override unSetOnSs(Handler h)523 public void unSetOnSs(Handler h) { 524 mSsRegistrant.clear(); 525 } 526 527 @Override setOnCatCcAlphaNotify(Handler h, int what, Object obj)528 public void setOnCatCcAlphaNotify(Handler h, int what, Object obj) { 529 mCatCcAlphaRegistrant = new Registrant (h, what, obj); 530 } 531 532 @Override unSetOnCatCcAlphaNotify(Handler h)533 public void unSetOnCatCcAlphaNotify(Handler h) { 534 mCatCcAlphaRegistrant.clear(); 535 } 536 537 @Override registerForInCallVoicePrivacyOn(Handler h, int what, Object obj)538 public void registerForInCallVoicePrivacyOn(Handler h, int what, Object obj) { 539 Registrant r = new Registrant (h, what, obj); 540 mVoicePrivacyOnRegistrants.add(r); 541 } 542 543 @Override unregisterForInCallVoicePrivacyOn(Handler h)544 public void unregisterForInCallVoicePrivacyOn(Handler h){ 545 mVoicePrivacyOnRegistrants.remove(h); 546 } 547 548 @Override registerForInCallVoicePrivacyOff(Handler h, int what, Object obj)549 public void registerForInCallVoicePrivacyOff(Handler h, int what, Object obj) { 550 Registrant r = new Registrant (h, what, obj); 551 mVoicePrivacyOffRegistrants.add(r); 552 } 553 554 @Override unregisterForInCallVoicePrivacyOff(Handler h)555 public void unregisterForInCallVoicePrivacyOff(Handler h){ 556 mVoicePrivacyOffRegistrants.remove(h); 557 } 558 559 @Override setOnRestrictedStateChanged(Handler h, int what, Object obj)560 public void setOnRestrictedStateChanged(Handler h, int what, Object obj) { 561 mRestrictedStateRegistrant = new Registrant (h, what, obj); 562 } 563 564 @Override unSetOnRestrictedStateChanged(Handler h)565 public void unSetOnRestrictedStateChanged(Handler h) { 566 if (mRestrictedStateRegistrant != null && mRestrictedStateRegistrant.getHandler() == h) { 567 mRestrictedStateRegistrant.clear(); 568 mRestrictedStateRegistrant = null; 569 } 570 } 571 572 @Override registerForDisplayInfo(Handler h, int what, Object obj)573 public void registerForDisplayInfo(Handler h, int what, Object obj) { 574 Registrant r = new Registrant (h, what, obj); 575 mDisplayInfoRegistrants.add(r); 576 } 577 578 @Override unregisterForDisplayInfo(Handler h)579 public void unregisterForDisplayInfo(Handler h) { 580 mDisplayInfoRegistrants.remove(h); 581 } 582 583 @Override registerForCallWaitingInfo(Handler h, int what, Object obj)584 public void registerForCallWaitingInfo(Handler h, int what, Object obj) { 585 Registrant r = new Registrant (h, what, obj); 586 mCallWaitingInfoRegistrants.add(r); 587 } 588 589 @Override unregisterForCallWaitingInfo(Handler h)590 public void unregisterForCallWaitingInfo(Handler h) { 591 mCallWaitingInfoRegistrants.remove(h); 592 } 593 594 @Override registerForSignalInfo(Handler h, int what, Object obj)595 public void registerForSignalInfo(Handler h, int what, Object obj) { 596 Registrant r = new Registrant (h, what, obj); 597 mSignalInfoRegistrants.add(r); 598 } 599 setOnUnsolOemHookRaw(Handler h, int what, Object obj)600 public void setOnUnsolOemHookRaw(Handler h, int what, Object obj) { 601 mUnsolOemHookRawRegistrant = new Registrant (h, what, obj); 602 } 603 unSetOnUnsolOemHookRaw(Handler h)604 public void unSetOnUnsolOemHookRaw(Handler h) { 605 if (mUnsolOemHookRawRegistrant != null && mUnsolOemHookRawRegistrant.getHandler() == h) { 606 mUnsolOemHookRawRegistrant.clear(); 607 mUnsolOemHookRawRegistrant = null; 608 } 609 } 610 611 @Override unregisterForSignalInfo(Handler h)612 public void unregisterForSignalInfo(Handler h) { 613 mSignalInfoRegistrants.remove(h); 614 } 615 616 @Override registerForCdmaOtaProvision(Handler h,int what, Object obj)617 public void registerForCdmaOtaProvision(Handler h,int what, Object obj){ 618 Registrant r = new Registrant (h, what, obj); 619 mOtaProvisionRegistrants.add(r); 620 } 621 622 @Override unregisterForCdmaOtaProvision(Handler h)623 public void unregisterForCdmaOtaProvision(Handler h){ 624 mOtaProvisionRegistrants.remove(h); 625 } 626 627 @Override registerForNumberInfo(Handler h,int what, Object obj)628 public void registerForNumberInfo(Handler h,int what, Object obj) { 629 Registrant r = new Registrant (h, what, obj); 630 mNumberInfoRegistrants.add(r); 631 } 632 633 @Override unregisterForNumberInfo(Handler h)634 public void unregisterForNumberInfo(Handler h){ 635 mNumberInfoRegistrants.remove(h); 636 } 637 638 @Override registerForRedirectedNumberInfo(Handler h,int what, Object obj)639 public void registerForRedirectedNumberInfo(Handler h,int what, Object obj) { 640 Registrant r = new Registrant (h, what, obj); 641 mRedirNumInfoRegistrants.add(r); 642 } 643 644 @Override unregisterForRedirectedNumberInfo(Handler h)645 public void unregisterForRedirectedNumberInfo(Handler h) { 646 mRedirNumInfoRegistrants.remove(h); 647 } 648 649 @Override registerForLineControlInfo(Handler h, int what, Object obj)650 public void registerForLineControlInfo(Handler h, int what, Object obj) { 651 Registrant r = new Registrant (h, what, obj); 652 mLineControlInfoRegistrants.add(r); 653 } 654 655 @Override unregisterForLineControlInfo(Handler h)656 public void unregisterForLineControlInfo(Handler h) { 657 mLineControlInfoRegistrants.remove(h); 658 } 659 660 @Override registerFoT53ClirlInfo(Handler h,int what, Object obj)661 public void registerFoT53ClirlInfo(Handler h,int what, Object obj) { 662 Registrant r = new Registrant (h, what, obj); 663 mT53ClirInfoRegistrants.add(r); 664 } 665 666 @Override unregisterForT53ClirInfo(Handler h)667 public void unregisterForT53ClirInfo(Handler h) { 668 mT53ClirInfoRegistrants.remove(h); 669 } 670 671 @Override registerForT53AudioControlInfo(Handler h,int what, Object obj)672 public void registerForT53AudioControlInfo(Handler h,int what, Object obj) { 673 Registrant r = new Registrant (h, what, obj); 674 mT53AudCntrlInfoRegistrants.add(r); 675 } 676 677 @Override unregisterForT53AudioControlInfo(Handler h)678 public void unregisterForT53AudioControlInfo(Handler h) { 679 mT53AudCntrlInfoRegistrants.remove(h); 680 } 681 682 @Override registerForRingbackTone(Handler h, int what, Object obj)683 public void registerForRingbackTone(Handler h, int what, Object obj) { 684 Registrant r = new Registrant (h, what, obj); 685 mRingbackToneRegistrants.add(r); 686 } 687 688 @Override unregisterForRingbackTone(Handler h)689 public void unregisterForRingbackTone(Handler h) { 690 mRingbackToneRegistrants.remove(h); 691 } 692 693 @Override registerForResendIncallMute(Handler h, int what, Object obj)694 public void registerForResendIncallMute(Handler h, int what, Object obj) { 695 Registrant r = new Registrant (h, what, obj); 696 mResendIncallMuteRegistrants.add(r); 697 } 698 699 @Override unregisterForResendIncallMute(Handler h)700 public void unregisterForResendIncallMute(Handler h) { 701 mResendIncallMuteRegistrants.remove(h); 702 } 703 704 @Override registerForCdmaSubscriptionChanged(Handler h, int what, Object obj)705 public void registerForCdmaSubscriptionChanged(Handler h, int what, Object obj) { 706 Registrant r = new Registrant (h, what, obj); 707 mCdmaSubscriptionChangedRegistrants.add(r); 708 } 709 710 @Override unregisterForCdmaSubscriptionChanged(Handler h)711 public void unregisterForCdmaSubscriptionChanged(Handler h) { 712 mCdmaSubscriptionChangedRegistrants.remove(h); 713 } 714 715 @Override registerForCdmaPrlChanged(Handler h, int what, Object obj)716 public void registerForCdmaPrlChanged(Handler h, int what, Object obj) { 717 Registrant r = new Registrant (h, what, obj); 718 mCdmaPrlChangedRegistrants.add(r); 719 } 720 721 @Override unregisterForCdmaPrlChanged(Handler h)722 public void unregisterForCdmaPrlChanged(Handler h) { 723 mCdmaPrlChangedRegistrants.remove(h); 724 } 725 726 @Override registerForExitEmergencyCallbackMode(Handler h, int what, Object obj)727 public void registerForExitEmergencyCallbackMode(Handler h, int what, Object obj) { 728 Registrant r = new Registrant (h, what, obj); 729 mExitEmergencyCallbackModeRegistrants.add(r); 730 } 731 732 @Override unregisterForExitEmergencyCallbackMode(Handler h)733 public void unregisterForExitEmergencyCallbackMode(Handler h) { 734 mExitEmergencyCallbackModeRegistrants.remove(h); 735 } 736 737 @Override registerForHardwareConfigChanged(Handler h, int what, Object obj)738 public void registerForHardwareConfigChanged(Handler h, int what, Object obj) { 739 Registrant r = new Registrant (h, what, obj); 740 mHardwareConfigChangeRegistrants.add(r); 741 } 742 743 @Override unregisterForHardwareConfigChanged(Handler h)744 public void unregisterForHardwareConfigChanged(Handler h) { 745 mHardwareConfigChangeRegistrants.remove(h); 746 } 747 748 @Override registerForNetworkScanResult(Handler h, int what, Object obj)749 public void registerForNetworkScanResult(Handler h, int what, Object obj) { 750 Registrant r = new Registrant(h, what, obj); 751 mRilNetworkScanResultRegistrants.add(r); 752 } 753 754 @Override unregisterForNetworkScanResult(Handler h)755 public void unregisterForNetworkScanResult(Handler h) { 756 mRilNetworkScanResultRegistrants.remove(h); 757 } 758 759 /** 760 * {@inheritDoc} 761 */ 762 @Override registerForRilConnected(Handler h, int what, Object obj)763 public void registerForRilConnected(Handler h, int what, Object obj) { 764 Registrant r = new Registrant (h, what, obj); 765 mRilConnectedRegistrants.add(r); 766 if (mRilVersion != -1) { 767 r.notifyRegistrant(new AsyncResult(null, new Integer(mRilVersion), null)); 768 } 769 } 770 771 @Override unregisterForRilConnected(Handler h)772 public void unregisterForRilConnected(Handler h) { 773 mRilConnectedRegistrants.remove(h); 774 } 775 registerForSubscriptionStatusChanged(Handler h, int what, Object obj)776 public void registerForSubscriptionStatusChanged(Handler h, int what, Object obj) { 777 Registrant r = new Registrant (h, what, obj); 778 mSubscriptionStatusRegistrants.add(r); 779 } 780 unregisterForSubscriptionStatusChanged(Handler h)781 public void unregisterForSubscriptionStatusChanged(Handler h) { 782 mSubscriptionStatusRegistrants.remove(h); 783 } 784 785 //***** Protected Methods 786 /** 787 * Store new RadioState and send notification based on the changes 788 * 789 * This function is called only by RIL.java when receiving unsolicited 790 * RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED 791 * 792 * RadioState has 3 values : RADIO_OFF, RADIO_UNAVAILABLE, RADIO_ON. 793 * 794 * @param newState new RadioState decoded from RIL_UNSOL_RADIO_STATE_CHANGED 795 */ setRadioState(RadioState newState)796 protected void setRadioState(RadioState newState) { 797 RadioState oldState; 798 799 synchronized (mStateMonitor) { 800 oldState = mState; 801 mState = newState; 802 803 if (oldState == mState) { 804 // no state transition 805 return; 806 } 807 808 mRadioStateChangedRegistrants.notifyRegistrants(); 809 810 if (mState.isAvailable() && !oldState.isAvailable()) { 811 mAvailRegistrants.notifyRegistrants(); 812 } 813 814 if (!mState.isAvailable() && oldState.isAvailable()) { 815 mNotAvailRegistrants.notifyRegistrants(); 816 } 817 818 if (mState.isOn() && !oldState.isOn()) { 819 mOnRegistrants.notifyRegistrants(); 820 } 821 822 if ((!mState.isOn() || !mState.isAvailable()) 823 && !((!oldState.isOn() || !oldState.isAvailable())) 824 ) { 825 mOffOrNotAvailRegistrants.notifyRegistrants(); 826 } 827 } 828 } 829 830 /** 831 * {@inheritDoc} 832 */ 833 @Override getLteOnCdmaMode()834 public int getLteOnCdmaMode() { 835 return TelephonyManager.getLteOnCdmaModeStatic(); 836 } 837 838 /** 839 * {@inheritDoc} 840 */ 841 @Override registerForCellInfoList(Handler h, int what, Object obj)842 public void registerForCellInfoList(Handler h, int what, Object obj) { 843 Registrant r = new Registrant (h, what, obj); 844 mRilCellInfoListRegistrants.add(r); 845 } 846 @Override unregisterForCellInfoList(Handler h)847 public void unregisterForCellInfoList(Handler h) { 848 mRilCellInfoListRegistrants.remove(h); 849 } 850 851 @Override registerForPhysicalChannelConfiguration(Handler h, int what, Object obj)852 public void registerForPhysicalChannelConfiguration(Handler h, int what, Object obj) { 853 Registrant r = new Registrant(h, what, obj); 854 mPhysicalChannelConfigurationRegistrants.add(r); 855 } 856 857 @Override unregisterForPhysicalChannelConfiguration(Handler h)858 public void unregisterForPhysicalChannelConfiguration(Handler h) { 859 mPhysicalChannelConfigurationRegistrants.remove(h); 860 } 861 862 @Override registerForSrvccStateChanged(Handler h, int what, Object obj)863 public void registerForSrvccStateChanged(Handler h, int what, Object obj) { 864 Registrant r = new Registrant (h, what, obj); 865 866 mSrvccStateRegistrants.add(r); 867 } 868 869 @Override unregisterForSrvccStateChanged(Handler h)870 public void unregisterForSrvccStateChanged(Handler h) { 871 mSrvccStateRegistrants.remove(h); 872 } 873 874 @Override testingEmergencyCall()875 public void testingEmergencyCall() {} 876 877 @Override getRilVersion()878 public int getRilVersion() { 879 return mRilVersion; 880 } 881 setUiccSubscription(int slotId, int appIndex, int subId, int subStatus, Message response)882 public void setUiccSubscription(int slotId, int appIndex, int subId, int subStatus, 883 Message response) { 884 } 885 setDataAllowed(boolean allowed, Message response)886 public void setDataAllowed(boolean allowed, Message response) { 887 } 888 889 @Override requestShutdown(Message result)890 public void requestShutdown(Message result) { 891 } 892 893 @Override getRadioCapability(Message result)894 public void getRadioCapability(Message result) { 895 } 896 897 @Override setRadioCapability(RadioCapability rc, Message response)898 public void setRadioCapability(RadioCapability rc, Message response) { 899 } 900 901 @Override registerForRadioCapabilityChanged(Handler h, int what, Object obj)902 public void registerForRadioCapabilityChanged(Handler h, int what, Object obj) { 903 Registrant r = new Registrant(h, what, obj); 904 mPhoneRadioCapabilityChangedRegistrants.add(r); 905 } 906 907 @Override unregisterForRadioCapabilityChanged(Handler h)908 public void unregisterForRadioCapabilityChanged(Handler h) { 909 mPhoneRadioCapabilityChangedRegistrants.remove(h); 910 } 911 912 @Override startLceService(int reportIntervalMs, boolean pullMode, Message result)913 public void startLceService(int reportIntervalMs, boolean pullMode, Message result) { 914 } 915 916 @Override stopLceService(Message result)917 public void stopLceService(Message result) { 918 } 919 920 @Override pullLceData(Message result)921 public void pullLceData(Message result) { 922 } 923 924 @Override registerForLceInfo(Handler h, int what, Object obj)925 public void registerForLceInfo(Handler h, int what, Object obj) { 926 Registrant r = new Registrant(h, what, obj); 927 928 synchronized (mStateMonitor) { 929 mLceInfoRegistrants.add(r); 930 } 931 } 932 933 @Override unregisterForLceInfo(Handler h)934 public void unregisterForLceInfo(Handler h) { 935 synchronized (mStateMonitor) { 936 mLceInfoRegistrants.remove(h); 937 } 938 } 939 940 @Override registerForModemReset(Handler h, int what, Object obj)941 public void registerForModemReset(Handler h, int what, Object obj) { 942 mModemResetRegistrants.add(new Registrant(h, what, obj)); 943 } 944 945 @Override unregisterForModemReset(Handler h)946 public void unregisterForModemReset(Handler h) { 947 mModemResetRegistrants.remove(h); 948 } 949 950 @Override registerForPcoData(Handler h, int what, Object obj)951 public void registerForPcoData(Handler h, int what, Object obj) { 952 mPcoDataRegistrants.add(new Registrant(h, what, obj)); 953 } 954 955 @Override unregisterForPcoData(Handler h)956 public void unregisterForPcoData(Handler h) { 957 mPcoDataRegistrants.remove(h); 958 } 959 960 @Override registerForCarrierInfoForImsiEncryption(Handler h, int what, Object obj)961 public void registerForCarrierInfoForImsiEncryption(Handler h, int what, Object obj) { 962 mCarrierInfoForImsiEncryptionRegistrants.add(new Registrant(h, what, obj)); 963 } 964 965 @Override unregisterForCarrierInfoForImsiEncryption(Handler h)966 public void unregisterForCarrierInfoForImsiEncryption(Handler h) { 967 mCarrierInfoForImsiEncryptionRegistrants.remove(h); 968 } 969 970 @Override registerForNattKeepaliveStatus(Handler h, int what, Object obj)971 public void registerForNattKeepaliveStatus(Handler h, int what, Object obj) { 972 Registrant r = new Registrant(h, what, obj); 973 974 synchronized (mStateMonitor) { 975 mNattKeepaliveStatusRegistrants.add(r); 976 } 977 } 978 979 @Override unregisterForNattKeepaliveStatus(Handler h)980 public void unregisterForNattKeepaliveStatus(Handler h) { 981 synchronized (mStateMonitor) { 982 mNattKeepaliveStatusRegistrants.remove(h); 983 } 984 } 985 } 986