PhoneProxy.java revision c06ce125408696fd49c7fa9e1189ecb61804007a
1/* 2 * Copyright (C) 2008 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 17package com.android.internal.telephony; 18 19 20import android.app.ActivityManagerNative; 21import android.content.Context; 22import android.content.Intent; 23import android.content.SharedPreferences; 24import android.os.Handler; 25import android.os.Message; 26import android.preference.PreferenceManager; 27import android.telephony.CellLocation; 28import android.telephony.ServiceState; 29import android.util.Log; 30 31import com.android.internal.telephony.cdma.CDMAPhone; 32import com.android.internal.telephony.gsm.GSMPhone; 33import com.android.internal.telephony.gsm.NetworkInfo; 34import com.android.internal.telephony.gsm.PdpConnection; 35import com.android.internal.telephony.test.SimulatedRadioControl; 36 37import java.util.List; 38 39public class PhoneProxy extends Handler implements Phone { 40 public final static Object lockForRadioTechnologyChange = new Object(); 41// private static boolean radioTechnologyChangeGsmToCdma = false; 42// private static boolean radioTechnologyChangeCdmaToGsm = false; 43 44 private Phone mActivePhone; 45 private String mOutgoingPhone; 46 private CommandsInterface mCommandsInterface; 47 private IccSmsInterfaceManagerProxy mIccSmsInterfaceManagerProxy; 48 private IccPhoneBookInterfaceManagerProxy mIccPhoneBookInterfaceManagerProxy; 49 private PhoneSubInfoProxy mPhoneSubInfoProxy; 50 51 private static final int EVENT_RADIO_TECHNOLOGY_CHANGED = 1; 52 private static final String LOG_TAG = "PHONE"; 53 54 //***** Class Methods 55 public PhoneProxy(Phone phone) { 56 mActivePhone = phone; 57 mIccSmsInterfaceManagerProxy = new IccSmsInterfaceManagerProxy( 58 phone.getIccSmsInterfaceManager()); 59 mIccPhoneBookInterfaceManagerProxy = new IccPhoneBookInterfaceManagerProxy( 60 phone.getIccPhoneBookInterfaceManager()); 61 mPhoneSubInfoProxy = new PhoneSubInfoProxy(phone.getPhoneSubInfo()); 62 mCommandsInterface = ((PhoneBase)mActivePhone).mCM; 63 mCommandsInterface.registerForRadioTechnologyChanged( 64 this, EVENT_RADIO_TECHNOLOGY_CHANGED, null); 65 } 66 67 @Override 68 public void handleMessage(Message msg) { 69 switch(msg.what) { 70 case EVENT_RADIO_TECHNOLOGY_CHANGED: 71 //switch Phone from CDMA to GSM or vice versa 72 mOutgoingPhone = ((PhoneBase)mActivePhone).getPhoneName(); 73 logd("Switching phone from " + mOutgoingPhone + "Phone to " + 74 (mOutgoingPhone.equals("GSM") ? "CDMAPhone" : "GSMPhone") ); 75 boolean oldPowerState = false; //old power state to off 76 if (mCommandsInterface.getRadioState().isOn()) { 77 oldPowerState = true; 78 logd("Setting Radio Power to Off"); 79 mCommandsInterface.setRadioPower(false, null); 80 } 81 if(mOutgoingPhone.equals("GSM")) { 82 logd("Make a new CDMAPhone and destroy the old GSMPhone."); 83 84 ((GSMPhone)mActivePhone).dispose(); 85 Phone oldPhone = mActivePhone; 86 87 //Give the garbage collector a hint to start the garbage collection asap 88 // NOTE this has been disabled since radio technology change could happen during 89 // e.g. a multimedia playing and could slow the system. Tests needs to be done 90 // to see the effects of the GC call here when system is busy. 91 //System.gc(); 92 93 mActivePhone = PhoneFactory.getCdmaPhone(); 94 logd("Resetting Radio"); 95 mCommandsInterface.setRadioPower(oldPowerState, null); 96 ((GSMPhone)oldPhone).removeReferences(); 97 oldPhone = null; 98 } else { 99 logd("Make a new GSMPhone and destroy the old CDMAPhone."); 100 101 ((CDMAPhone)mActivePhone).dispose(); 102 //mActivePhone = null; 103 Phone oldPhone = mActivePhone; 104 105 // Give the GC a hint to start the garbage collection asap 106 // NOTE this has been disabled since radio technology change could happen during 107 // e.g. a multimedia playing and could slow the system. Tests needs to be done 108 // to see the effects of the GC call here when system is busy. 109 //System.gc(); 110 111 mActivePhone = PhoneFactory.getGsmPhone(); 112 logd("Resetting Radio:"); 113 mCommandsInterface.setRadioPower(oldPowerState, null); 114 ((CDMAPhone)oldPhone).removeReferences(); 115 oldPhone = null; 116 } 117 118 //Set the new interfaces in the proxy's 119 mIccSmsInterfaceManagerProxy.setmIccSmsInterfaceManager( 120 mActivePhone.getIccSmsInterfaceManager()); 121 mIccPhoneBookInterfaceManagerProxy.setmIccPhoneBookInterfaceManager( 122 mActivePhone.getIccPhoneBookInterfaceManager()); 123 mPhoneSubInfoProxy.setmPhoneSubInfo(this.mActivePhone.getPhoneSubInfo()); 124 mCommandsInterface = ((PhoneBase)mActivePhone).mCM; 125 126 //Send an Intent to the PhoneApp that we had a radio technology change 127 Intent intent = new Intent(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); 128 intent.putExtra(Phone.PHONE_NAME_KEY, mActivePhone.getPhoneName()); 129 ActivityManagerNative.broadcastStickyIntent(intent, null); 130 131 break; 132 default: 133 Log.e(LOG_TAG, "Error! This handler was not registered for this message type. Message: " 134 + msg.what); 135 break; 136 } 137 super.handleMessage(msg); 138 } 139 140 private void logv(String msg) { 141 Log.v(LOG_TAG, "[PhoneProxy] " + msg); 142 } 143 144 private void logd(String msg) { 145 Log.d(LOG_TAG, "[PhoneProxy] " + msg); 146 } 147 148 private void logw(String msg) { 149 Log.w(LOG_TAG, "[PhoneProxy] " + msg); 150 } 151 152 private void loge(String msg) { 153 Log.e(LOG_TAG, "[PhoneProxy] " + msg); 154 } 155 156 157 public ServiceState getServiceState() { 158 return mActivePhone.getServiceState(); 159 } 160 161 public CellLocation getCellLocation() { 162 return mActivePhone.getCellLocation(); 163 } 164 165 public DataState getDataConnectionState() { 166 return mActivePhone.getDataConnectionState(); 167 } 168 169 public DataActivityState getDataActivityState() { 170 return mActivePhone.getDataActivityState(); 171 } 172 173 public Context getContext() { 174 return mActivePhone.getContext(); 175 } 176 177 public void disableDnsCheck(boolean b) { 178 mActivePhone.disableDnsCheck(b); 179 } 180 181 public boolean isDnsCheckDisabled() { 182 return mActivePhone.isDnsCheckDisabled(); 183 } 184 185 public State getState() { 186 return mActivePhone.getState(); 187 } 188 189 public String getPhoneName() { 190 return mActivePhone.getPhoneName(); 191 } 192 193 public String[] getActiveApnTypes() { 194 return mActivePhone.getActiveApnTypes(); 195 } 196 197 public String getActiveApn() { 198 return mActivePhone.getActiveApn(); 199 } 200 201 public int getSignalStrengthASU() { 202 return mActivePhone.getSignalStrengthASU(); 203 } 204 205 public void registerForUnknownConnection(Handler h, int what, Object obj) { 206 mActivePhone.registerForUnknownConnection(h, what, obj); 207 } 208 209 public void unregisterForUnknownConnection(Handler h) { 210 mActivePhone.unregisterForUnknownConnection(h); 211 } 212 213 public void registerForPhoneStateChanged(Handler h, int what, Object obj) { 214 mActivePhone.registerForPhoneStateChanged(h, what, obj); 215 } 216 217 public void unregisterForPhoneStateChanged(Handler h) { 218 mActivePhone.unregisterForPhoneStateChanged(h); 219 } 220 221 public void registerForNewRingingConnection(Handler h, int what, Object obj) { 222 mActivePhone.registerForNewRingingConnection(h, what, obj); 223 } 224 225 public void unregisterForNewRingingConnection(Handler h) { 226 mActivePhone.unregisterForNewRingingConnection(h); 227 } 228 229 public void registerForIncomingRing(Handler h, int what, Object obj) { 230 mActivePhone.registerForIncomingRing(h, what, obj); 231 } 232 233 public void unregisterForIncomingRing(Handler h) { 234 mActivePhone.unregisterForIncomingRing(h); 235 } 236 237 public void registerForDisconnect(Handler h, int what, Object obj) { 238 mActivePhone.registerForDisconnect(h, what, obj); 239 } 240 241 public void unregisterForDisconnect(Handler h) { 242 mActivePhone.unregisterForDisconnect(h); 243 } 244 245 public void registerForMmiInitiate(Handler h, int what, Object obj) { 246 mActivePhone.registerForMmiInitiate(h, what, obj); 247 } 248 249 public void unregisterForMmiInitiate(Handler h) { 250 mActivePhone.unregisterForMmiInitiate(h); 251 } 252 253 public void registerForMmiComplete(Handler h, int what, Object obj) { 254 mActivePhone.registerForMmiComplete(h, what, obj); 255 } 256 257 public void unregisterForMmiComplete(Handler h) { 258 mActivePhone.unregisterForMmiComplete(h); 259 } 260 261 public List<? extends MmiCode> getPendingMmiCodes() { 262 return mActivePhone.getPendingMmiCodes(); 263 } 264 265 public void sendUssdResponse(String ussdMessge) { 266 mActivePhone.sendUssdResponse(ussdMessge); 267 } 268 269 public void registerForServiceStateChanged(Handler h, int what, Object obj) { 270 mActivePhone.registerForServiceStateChanged(h, what, obj); 271 } 272 273 public void unregisterForServiceStateChanged(Handler h) { 274 mActivePhone.unregisterForServiceStateChanged(h); 275 } 276 277 public void registerForSuppServiceNotification(Handler h, int what, Object obj) { 278 mActivePhone.registerForSuppServiceNotification(h, what, obj); 279 } 280 281 public void unregisterForSuppServiceNotification(Handler h) { 282 mActivePhone.unregisterForSuppServiceNotification(h); 283 } 284 285 public void registerForSuppServiceFailed(Handler h, int what, Object obj) { 286 mActivePhone.registerForSuppServiceFailed(h, what, obj); 287 } 288 289 public void unregisterForSuppServiceFailed(Handler h) { 290 mActivePhone.unregisterForSuppServiceFailed(h); 291 } 292 293 public void registerForInCallVoicePrivacyOn(Handler h, int what, Object obj){ 294 mActivePhone.registerForInCallVoicePrivacyOn(h,what,obj); 295 } 296 297 public void unregisterForInCallVoicePrivacyOn(Handler h){ 298 mActivePhone.unregisterForInCallVoicePrivacyOn(h); 299 } 300 301 public void registerForInCallVoicePrivacyOff(Handler h, int what, Object obj){ 302 mActivePhone.registerForInCallVoicePrivacyOff(h,what,obj); 303 } 304 305 public void unregisterForInCallVoicePrivacyOff(Handler h){ 306 mActivePhone.unregisterForInCallVoicePrivacyOff(h); 307 } 308 309 public boolean getIccRecordsLoaded() { 310 return mActivePhone.getIccRecordsLoaded(); 311 } 312 313 public IccCard getIccCard() { 314 return mActivePhone.getIccCard(); 315 } 316 317 public void acceptCall() throws CallStateException { 318 mActivePhone.acceptCall(); 319 } 320 321 public void rejectCall() throws CallStateException { 322 mActivePhone.rejectCall(); 323 } 324 325 public void switchHoldingAndActive() throws CallStateException { 326 mActivePhone.switchHoldingAndActive(); 327 } 328 329 public boolean canConference() { 330 return mActivePhone.canConference(); 331 } 332 333 public void conference() throws CallStateException { 334 mActivePhone.conference(); 335 } 336 337 public void enableEnhancedVoicePrivacy(boolean enable, Message onComplete) { 338 mActivePhone.enableEnhancedVoicePrivacy(enable, onComplete); 339 } 340 341 public void getEnhancedVoicePrivacy(Message onComplete) { 342 mActivePhone.getEnhancedVoicePrivacy(onComplete); 343 } 344 345 public boolean canTransfer() { 346 return mActivePhone.canTransfer(); 347 } 348 349 public void explicitCallTransfer() throws CallStateException { 350 mActivePhone.explicitCallTransfer(); 351 } 352 353 public void clearDisconnected() { 354 mActivePhone.clearDisconnected(); 355 } 356 357 public Call getForegroundCall() { 358 return mActivePhone.getForegroundCall(); 359 } 360 361 public Call getBackgroundCall() { 362 return mActivePhone.getBackgroundCall(); 363 } 364 365 public Call getRingingCall() { 366 return mActivePhone.getRingingCall(); 367 } 368 369 public Connection dial(String dialString) throws CallStateException { 370 return mActivePhone.dial(dialString); 371 } 372 373 public boolean handlePinMmi(String dialString) { 374 return mActivePhone.handlePinMmi(dialString); 375 } 376 377 public boolean handleInCallMmiCommands(String command) throws CallStateException { 378 return mActivePhone.handleInCallMmiCommands(command); 379 } 380 381 public void sendDtmf(char c) { 382 mActivePhone.sendDtmf(c); 383 } 384 385 public void startDtmf(char c) { 386 mActivePhone.startDtmf(c); 387 } 388 389 public void stopDtmf() { 390 mActivePhone.stopDtmf(); 391 } 392 393 public void setRadioPower(boolean power) { 394 mActivePhone.setRadioPower(power); 395 } 396 397 public boolean getMessageWaitingIndicator() { 398 return mActivePhone.getMessageWaitingIndicator(); 399 } 400 401 public boolean getCallForwardingIndicator() { 402 return mActivePhone.getCallForwardingIndicator(); 403 } 404 405 public String getLine1Number() { 406 return mActivePhone.getLine1Number(); 407 } 408 409 public String getLine1AlphaTag() { 410 return mActivePhone.getLine1AlphaTag(); 411 } 412 413 public void setLine1Number(String alphaTag, String number, Message onComplete) { 414 mActivePhone.setLine1Number(alphaTag, number, onComplete); 415 } 416 417 public String getVoiceMailNumber() { 418 return mActivePhone.getVoiceMailNumber(); 419 } 420 421 public String getVoiceMailAlphaTag() { 422 return mActivePhone.getVoiceMailAlphaTag(); 423 } 424 425 public void setVoiceMailNumber(String alphaTag,String voiceMailNumber, 426 Message onComplete) { 427 mActivePhone.setVoiceMailNumber(alphaTag, voiceMailNumber, onComplete); 428 } 429 430 public void getCallForwardingOption(int commandInterfaceCFReason, 431 Message onComplete) { 432 mActivePhone.getCallForwardingOption(commandInterfaceCFReason, 433 onComplete); 434 } 435 436 public void setCallForwardingOption(int commandInterfaceCFReason, 437 int commandInterfaceCFAction, String dialingNumber, 438 int timerSeconds, Message onComplete) { 439 mActivePhone.setCallForwardingOption(commandInterfaceCFReason, 440 commandInterfaceCFAction, dialingNumber, timerSeconds, onComplete); 441 } 442 443 public void getOutgoingCallerIdDisplay(Message onComplete) { 444 mActivePhone.getOutgoingCallerIdDisplay(onComplete); 445 } 446 447 public void setOutgoingCallerIdDisplay(int commandInterfaceCLIRMode, 448 Message onComplete) { 449 mActivePhone.setOutgoingCallerIdDisplay(commandInterfaceCLIRMode, 450 onComplete); 451 } 452 453 public void getCallWaiting(Message onComplete) { 454 mActivePhone.getCallWaiting(onComplete); 455 } 456 457 public void setCallWaiting(boolean enable, Message onComplete) { 458 mActivePhone.setCallWaiting(enable, onComplete); 459 } 460 461 public void getAvailableNetworks(Message response) { 462 mActivePhone.getAvailableNetworks(response); 463 } 464 465 public void setNetworkSelectionModeAutomatic(Message response) { 466 mActivePhone.setNetworkSelectionModeAutomatic(response); 467 } 468 469 public void selectNetworkManually(NetworkInfo network, Message response) { 470 mActivePhone.selectNetworkManually(network, response); 471 } 472 473 public void setPreferredNetworkType(int networkType, Message response) { 474 mActivePhone.setPreferredNetworkType(networkType, response); 475 } 476 477 public void getPreferredNetworkType(Message response) { 478 mActivePhone.getPreferredNetworkType(response); 479 } 480 481 public void getNeighboringCids(Message response) { 482 mActivePhone.getNeighboringCids(response); 483 } 484 485 public void setOnPostDialCharacter(Handler h, int what, Object obj) { 486 mActivePhone.setOnPostDialCharacter(h, what, obj); 487 } 488 489 public void setMute(boolean muted) { 490 mActivePhone.setMute(muted); 491 } 492 493 public boolean getMute() { 494 return mActivePhone.getMute(); 495 } 496 497 public void invokeOemRilRequestRaw(byte[] data, Message response) { 498 mActivePhone.invokeOemRilRequestRaw(data, response); 499 } 500 501 public void invokeOemRilRequestStrings(String[] strings, Message response) { 502 mActivePhone.invokeOemRilRequestStrings(strings, response); 503 } 504 505 /** 506 * @deprecated 507 */ 508 public void getPdpContextList(Message response) { 509 mActivePhone.getPdpContextList(response); 510 } 511 512 public void getDataCallList(Message response) { 513 mActivePhone.getDataCallList(response); 514 } 515 516 /** 517 * @deprecated 518 */ 519 public List<PdpConnection> getCurrentPdpList() { 520 return mActivePhone.getCurrentPdpList(); 521 } 522 523 public List<DataConnection> getCurrentDataConnectionList() { 524 return mActivePhone.getCurrentDataConnectionList(); 525 } 526 527 public void updateServiceLocation(Message response) { 528 mActivePhone.updateServiceLocation(response); 529 } 530 531 public void enableLocationUpdates() { 532 mActivePhone.enableLocationUpdates(); 533 } 534 535 public void disableLocationUpdates() { 536 mActivePhone.disableLocationUpdates(); 537 } 538 539 public void setUnitTestMode(boolean f) { 540 mActivePhone.setUnitTestMode(f); 541 } 542 543 public boolean getUnitTestMode() { 544 return mActivePhone.getUnitTestMode(); 545 } 546 547 public void setBandMode(int bandMode, Message response) { 548 mActivePhone.setBandMode(bandMode, response); 549 } 550 551 public void queryAvailableBandMode(Message response) { 552 mActivePhone.queryAvailableBandMode(response); 553 } 554 555 public boolean getDataRoamingEnabled() { 556 return mActivePhone.getDataRoamingEnabled(); 557 } 558 559 public void setDataRoamingEnabled(boolean enable) { 560 mActivePhone.setDataRoamingEnabled(enable); 561 } 562 563 public void queryCdmaRoamingPreference(Message response) { 564 mActivePhone.queryCdmaRoamingPreference(response); 565 } 566 567 public void setCdmaRoamingPreference(int cdmaRoamingType, Message response) { 568 mActivePhone.setCdmaRoamingPreference(cdmaRoamingType, response); 569 } 570 571 public void setCdmaSubscription(int cdmaSubscriptionType, Message response) { 572 mActivePhone.setCdmaSubscription(cdmaSubscriptionType, response); 573 } 574 575 public SimulatedRadioControl getSimulatedRadioControl() { 576 return mActivePhone.getSimulatedRadioControl(); 577 } 578 579 public boolean enableDataConnectivity() { 580 return mActivePhone.enableDataConnectivity(); 581 } 582 583 public boolean disableDataConnectivity() { 584 return mActivePhone.disableDataConnectivity(); 585 } 586 587 public int enableApnType(String type) { 588 return mActivePhone.enableApnType(type); 589 } 590 591 public int disableApnType(String type) { 592 return mActivePhone.disableApnType(type); 593 } 594 595 public boolean isDataConnectivityPossible() { 596 return mActivePhone.isDataConnectivityPossible(); 597 } 598 599 public String getInterfaceName(String apnType) { 600 return mActivePhone.getInterfaceName(apnType); 601 } 602 603 public String getIpAddress(String apnType) { 604 return mActivePhone.getIpAddress(apnType); 605 } 606 607 public String getGateway(String apnType) { 608 return mActivePhone.getGateway(apnType); 609 } 610 611 public String[] getDnsServers(String apnType) { 612 return mActivePhone.getDnsServers(apnType); 613 } 614 615 public String getDeviceId() { 616 return mActivePhone.getDeviceId(); 617 } 618 619 public String getDeviceSvn() { 620 return mActivePhone.getDeviceSvn(); 621 } 622 623 public String getSubscriberId() { 624 return mActivePhone.getSubscriberId(); 625 } 626 627 public String getIccSerialNumber() { 628 return mActivePhone.getIccSerialNumber(); 629 } 630 631 public String getEsn() { 632 return mActivePhone.getEsn(); 633 } 634 635 public String getMeid() { 636 return mActivePhone.getMeid(); 637 } 638 639 public PhoneSubInfo getPhoneSubInfo(){ 640 return mActivePhone.getPhoneSubInfo(); 641 } 642 643 public IccSmsInterfaceManager getIccSmsInterfaceManager(){ 644 return mActivePhone.getIccSmsInterfaceManager(); 645 } 646 647 public IccPhoneBookInterfaceManager getIccPhoneBookInterfaceManager(){ 648 return mActivePhone.getIccPhoneBookInterfaceManager(); 649 } 650 651 public void setTTYModeEnabled(boolean enable, Message onComplete) { 652 mActivePhone.setTTYModeEnabled(enable, onComplete); 653 } 654 655 public void queryTTYModeEnabled(Message onComplete) { 656 mActivePhone.queryTTYModeEnabled(onComplete); 657 } 658 659 public void activateCellBroadcastSms(int activate, Message response) { 660 mActivePhone.activateCellBroadcastSms(activate, response); 661 } 662 663 public void getCellBroadcastSmsConfig(Message response) { 664 mActivePhone.getCellBroadcastSmsConfig(response); 665 } 666 667 public void setCellBroadcastSmsConfig(int[] configValuesArray, Message response) { 668 mActivePhone.setCellBroadcastSmsConfig(configValuesArray, response); 669 } 670 671 public void notifyDataActivity() { 672 mActivePhone.notifyDataActivity(); 673 } 674 675 public void getSmscAddress(Message result) { 676 mActivePhone.getSmscAddress(result); 677 } 678 679 public void setSmscAddress(String address, Message result) { 680 mActivePhone.setSmscAddress(address, result); 681 } 682} 683 684