1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
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
18package com.android.internal.telephony;
19
20
21import android.app.ActivityManagerNative;
22import android.content.Context;
23import android.content.Intent;
24import android.net.LinkProperties;
25import android.net.NetworkCapabilities;
26import android.os.AsyncResult;
27import android.os.Handler;
28import android.os.Message;
29import android.os.SystemProperties;
30import android.os.UserHandle;
31import android.telephony.CellInfo;
32import android.telephony.CellLocation;
33import android.telephony.ServiceState;
34import android.telephony.SignalStrength;
35import android.telephony.SubscriptionManager;
36import android.telephony.Rlog;
37
38import com.android.internal.telephony.cdma.CDMAPhone;
39import com.android.internal.telephony.gsm.GSMPhone;
40import com.android.internal.telephony.imsphone.ImsPhone;
41import com.android.internal.telephony.test.SimulatedRadioControl;
42import com.android.internal.telephony.cdma.CDMALTEPhone;
43import com.android.internal.telephony.uicc.IccCardProxy;
44import com.android.internal.telephony.uicc.IccFileHandler;
45import com.android.internal.telephony.uicc.IsimRecords;
46import com.android.internal.telephony.uicc.UiccCard;
47import com.android.internal.telephony.uicc.UsimServiceTable;
48
49import java.util.List;
50
51public class PhoneProxy extends Handler implements Phone {
52    public final static Object lockForRadioTechnologyChange = new Object();
53
54    private Phone mActivePhone;
55    private CommandsInterface mCommandsInterface;
56    private IccSmsInterfaceManager mIccSmsInterfaceManager;
57    private IccPhoneBookInterfaceManagerProxy mIccPhoneBookInterfaceManagerProxy;
58    private PhoneSubInfoProxy mPhoneSubInfoProxy;
59    private IccCardProxy mIccCardProxy;
60
61    private boolean mResetModemOnRadioTechnologyChange = false;
62
63    private int mRilVersion;
64
65    private static final int EVENT_VOICE_RADIO_TECH_CHANGED = 1;
66    private static final int EVENT_RADIO_ON = 2;
67    private static final int EVENT_REQUEST_VOICE_RADIO_TECH_DONE = 3;
68    private static final int EVENT_RIL_CONNECTED = 4;
69    private static final int EVENT_UPDATE_PHONE_OBJECT = 5;
70
71    private int mPhoneId = 0;
72
73    private static final String LOG_TAG = "PhoneProxy";
74
75    //***** Class Methods
76    public PhoneProxy(PhoneBase phone) {
77        mActivePhone = phone;
78        mResetModemOnRadioTechnologyChange = SystemProperties.getBoolean(
79                TelephonyProperties.PROPERTY_RESET_ON_RADIO_TECH_CHANGE, false);
80        mIccPhoneBookInterfaceManagerProxy = new IccPhoneBookInterfaceManagerProxy(
81                phone.getIccPhoneBookInterfaceManager());
82        mPhoneSubInfoProxy = new PhoneSubInfoProxy(phone.getPhoneSubInfo());
83        mCommandsInterface = ((PhoneBase)mActivePhone).mCi;
84
85        mCommandsInterface.registerForRilConnected(this, EVENT_RIL_CONNECTED, null);
86        mCommandsInterface.registerForOn(this, EVENT_RADIO_ON, null);
87        mCommandsInterface.registerForVoiceRadioTechChanged(
88                             this, EVENT_VOICE_RADIO_TECH_CHANGED, null);
89        mPhoneId = phone.getPhoneId();
90        mIccSmsInterfaceManager =
91                new IccSmsInterfaceManager((PhoneBase)this.mActivePhone);
92        mIccCardProxy = new IccCardProxy(mActivePhone.getContext(), mCommandsInterface, mActivePhone.getPhoneId());
93
94        if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM) {
95            // For the purpose of IccCardProxy we only care about the technology family
96            mIccCardProxy.setVoiceRadioTech(ServiceState.RIL_RADIO_TECHNOLOGY_UMTS);
97        } else if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
98            mIccCardProxy.setVoiceRadioTech(ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT);
99        }
100    }
101
102    @Override
103    public void handleMessage(Message msg) {
104        AsyncResult ar = (AsyncResult) msg.obj;
105        switch(msg.what) {
106        case EVENT_RADIO_ON:
107            /* Proactively query voice radio technologies */
108            mCommandsInterface.getVoiceRadioTechnology(
109                    obtainMessage(EVENT_REQUEST_VOICE_RADIO_TECH_DONE));
110            break;
111
112        case EVENT_RIL_CONNECTED:
113            if (ar.exception == null && ar.result != null) {
114                mRilVersion = (Integer) ar.result;
115            } else {
116                logd("Unexpected exception on EVENT_RIL_CONNECTED");
117                mRilVersion = -1;
118            }
119            break;
120
121        case EVENT_VOICE_RADIO_TECH_CHANGED:
122        case EVENT_REQUEST_VOICE_RADIO_TECH_DONE:
123            String what = (msg.what == EVENT_VOICE_RADIO_TECH_CHANGED) ?
124                    "EVENT_VOICE_RADIO_TECH_CHANGED" : "EVENT_REQUEST_VOICE_RADIO_TECH_DONE";
125            if (ar.exception == null) {
126                if ((ar.result != null) && (((int[]) ar.result).length != 0)) {
127                    int newVoiceTech = ((int[]) ar.result)[0];
128                    logd(what + ": newVoiceTech=" + newVoiceTech);
129                    phoneObjectUpdater(newVoiceTech);
130                } else {
131                    loge(what + ": has no tech!");
132                }
133            } else {
134                loge(what + ": exception=" + ar.exception);
135            }
136            break;
137
138        case EVENT_UPDATE_PHONE_OBJECT:
139            phoneObjectUpdater(msg.arg1);
140            break;
141
142        default:
143            loge("Error! This handler was not registered for this message type. Message: "
144                    + msg.what);
145            break;
146        }
147        super.handleMessage(msg);
148    }
149
150    private static void logd(String msg) {
151        Rlog.d(LOG_TAG, "[PhoneProxy] " + msg);
152    }
153
154    private void loge(String msg) {
155        Rlog.e(LOG_TAG, "[PhoneProxy] " + msg);
156    }
157
158    private void phoneObjectUpdater(int newVoiceRadioTech) {
159        logd("phoneObjectUpdater: newVoiceRadioTech=" + newVoiceRadioTech);
160
161        if (mActivePhone != null) {
162            // Check for a voice over lte replacement
163            if ((newVoiceRadioTech == ServiceState.RIL_RADIO_TECHNOLOGY_LTE) ||
164                    (newVoiceRadioTech == ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN)) {
165                int volteReplacementRat = mActivePhone.getContext().getResources().getInteger(
166                        com.android.internal.R.integer.config_volte_replacement_rat);
167                logd("phoneObjectUpdater: volteReplacementRat=" + volteReplacementRat);
168                if (volteReplacementRat != ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN) {
169                    newVoiceRadioTech = volteReplacementRat;
170                }
171            }
172
173            if(mRilVersion == 6 && getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE) {
174                /*
175                 * On v6 RIL, when LTE_ON_CDMA is TRUE, always create CDMALTEPhone
176                 * irrespective of the voice radio tech reported.
177                 */
178                if (mActivePhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
179                    logd("phoneObjectUpdater: LTE ON CDMA property is set. Use CDMA Phone" +
180                            " newVoiceRadioTech=" + newVoiceRadioTech +
181                            " mActivePhone=" + mActivePhone.getPhoneName());
182                    return;
183                } else {
184                    logd("phoneObjectUpdater: LTE ON CDMA property is set. Switch to CDMALTEPhone" +
185                            " newVoiceRadioTech=" + newVoiceRadioTech +
186                            " mActivePhone=" + mActivePhone.getPhoneName());
187                    newVoiceRadioTech = ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT;
188                }
189            } else {
190                if ((ServiceState.isCdma(newVoiceRadioTech) &&
191                        mActivePhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) ||
192                        (ServiceState.isGsm(newVoiceRadioTech) &&
193                                mActivePhone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM)) {
194                    // Nothing changed. Keep phone as it is.
195                    logd("phoneObjectUpdater: No change ignore," +
196                            " newVoiceRadioTech=" + newVoiceRadioTech +
197                            " mActivePhone=" + mActivePhone.getPhoneName());
198                    return;
199                }
200            }
201        }
202
203        if (newVoiceRadioTech == ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN) {
204            // We need some voice phone object to be active always, so never
205            // delete the phone without anything to replace it with!
206            logd("phoneObjectUpdater: Unknown rat ignore, "
207                    + " newVoiceRadioTech=Unknown. mActivePhone=" + mActivePhone.getPhoneName());
208            return;
209        }
210
211        boolean oldPowerState = false; // old power state to off
212        if (mResetModemOnRadioTechnologyChange) {
213            if (mCommandsInterface.getRadioState().isOn()) {
214                oldPowerState = true;
215                logd("phoneObjectUpdater: Setting Radio Power to Off");
216                mCommandsInterface.setRadioPower(false, null);
217            }
218        }
219
220        deleteAndCreatePhone(newVoiceRadioTech);
221
222        if (mResetModemOnRadioTechnologyChange && oldPowerState) { // restore power state
223            logd("phoneObjectUpdater: Resetting Radio");
224            mCommandsInterface.setRadioPower(oldPowerState, null);
225        }
226
227        // Set the new interfaces in the proxy's
228        mIccSmsInterfaceManager.updatePhoneObject((PhoneBase) mActivePhone);
229        mIccPhoneBookInterfaceManagerProxy.setmIccPhoneBookInterfaceManager(mActivePhone
230                .getIccPhoneBookInterfaceManager());
231        mPhoneSubInfoProxy.setmPhoneSubInfo(mActivePhone.getPhoneSubInfo());
232
233        mCommandsInterface = ((PhoneBase)mActivePhone).mCi;
234        mIccCardProxy.setVoiceRadioTech(newVoiceRadioTech);
235
236        // Send an Intent to the PhoneApp that we had a radio technology change
237        Intent intent = new Intent(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
238        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
239        intent.putExtra(PhoneConstants.PHONE_NAME_KEY, mActivePhone.getPhoneName());
240        SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhoneId);
241        ActivityManagerNative.broadcastStickyIntent(intent, null, UserHandle.USER_ALL);
242
243    }
244
245    private void deleteAndCreatePhone(int newVoiceRadioTech) {
246
247        String outgoingPhoneName = "Unknown";
248        Phone oldPhone = mActivePhone;
249        ImsPhone imsPhone = null;
250
251        if (oldPhone != null) {
252            outgoingPhoneName = ((PhoneBase) oldPhone).getPhoneName();
253        }
254
255        logd("Switching Voice Phone : " + outgoingPhoneName + " >>> "
256                + (ServiceState.isGsm(newVoiceRadioTech) ? "GSM" : "CDMA"));
257
258
259        if (ServiceState.isCdma(newVoiceRadioTech)) {
260            mActivePhone = PhoneFactory.getCdmaPhone(mPhoneId);
261        } else if (ServiceState.isGsm(newVoiceRadioTech)) {
262            mActivePhone = PhoneFactory.getGsmPhone(mPhoneId);
263        }
264
265        if (oldPhone != null) {
266            imsPhone = oldPhone.relinquishOwnershipOfImsPhone();
267        }
268
269        if(mActivePhone != null) {
270            CallManager.getInstance().registerPhone(mActivePhone);
271            if (imsPhone != null) {
272                mActivePhone.acquireOwnershipOfImsPhone(imsPhone);
273            }
274        }
275
276        if (oldPhone != null) {
277            CallManager.getInstance().unregisterPhone(oldPhone);
278            logd("Disposing old phone..");
279            oldPhone.dispose();
280            // Potential GC issues: however, callers may have references to old
281            // phone on which they perform hierarchical funcs: phone.getA().getB()
282            // HENCE: do not delete references.
283            //oldPhone.removeReferences();
284        }
285        oldPhone = null;
286    }
287
288    public IccSmsInterfaceManager getIccSmsInterfaceManager(){
289        return mIccSmsInterfaceManager;
290    }
291
292    public PhoneSubInfoProxy getPhoneSubInfoProxy(){
293        return mPhoneSubInfoProxy;
294    }
295
296    public IccPhoneBookInterfaceManagerProxy getIccPhoneBookInterfaceManagerProxy() {
297        return mIccPhoneBookInterfaceManagerProxy;
298    }
299
300    public IccFileHandler getIccFileHandler() {
301        return ((PhoneBase)mActivePhone).getIccFileHandler();
302    }
303
304    @Override
305    public void updatePhoneObject(int voiceRadioTech) {
306        logd("updatePhoneObject: radioTechnology=" + voiceRadioTech);
307        sendMessage(obtainMessage(EVENT_UPDATE_PHONE_OBJECT, voiceRadioTech, 0, null));
308    }
309
310    @Override
311    public ServiceState getServiceState() {
312        return mActivePhone.getServiceState();
313    }
314
315    @Override
316    public CellLocation getCellLocation() {
317        return mActivePhone.getCellLocation();
318    }
319
320    /**
321     * @return all available cell information or null if none.
322     */
323    @Override
324    public List<CellInfo> getAllCellInfo() {
325        return mActivePhone.getAllCellInfo();
326    }
327
328    /**
329     * {@inheritDoc}
330     */
331    @Override
332    public void setCellInfoListRate(int rateInMillis) {
333        mActivePhone.setCellInfoListRate(rateInMillis);
334    }
335
336    @Override
337    public PhoneConstants.DataState getDataConnectionState() {
338        return mActivePhone.getDataConnectionState(PhoneConstants.APN_TYPE_DEFAULT);
339    }
340
341    @Override
342    public PhoneConstants.DataState getDataConnectionState(String apnType) {
343        return mActivePhone.getDataConnectionState(apnType);
344    }
345
346    @Override
347    public DataActivityState getDataActivityState() {
348        return mActivePhone.getDataActivityState();
349    }
350
351    @Override
352    public Context getContext() {
353        return mActivePhone.getContext();
354    }
355
356    @Override
357    public void disableDnsCheck(boolean b) {
358        mActivePhone.disableDnsCheck(b);
359    }
360
361    @Override
362    public boolean isDnsCheckDisabled() {
363        return mActivePhone.isDnsCheckDisabled();
364    }
365
366    @Override
367    public PhoneConstants.State getState() {
368        return mActivePhone.getState();
369    }
370
371    @Override
372    public String getPhoneName() {
373        return mActivePhone.getPhoneName();
374    }
375
376    @Override
377    public int getPhoneType() {
378        return mActivePhone.getPhoneType();
379    }
380
381    @Override
382    public String[] getActiveApnTypes() {
383        return mActivePhone.getActiveApnTypes();
384    }
385
386    @Override
387    public String getActiveApnHost(String apnType) {
388        return mActivePhone.getActiveApnHost(apnType);
389    }
390
391    @Override
392    public LinkProperties getLinkProperties(String apnType) {
393        return mActivePhone.getLinkProperties(apnType);
394    }
395
396    @Override
397    public NetworkCapabilities getNetworkCapabilities(String apnType) {
398        return mActivePhone.getNetworkCapabilities(apnType);
399    }
400
401    @Override
402    public SignalStrength getSignalStrength() {
403        return mActivePhone.getSignalStrength();
404    }
405
406    @Override
407    public void registerForUnknownConnection(Handler h, int what, Object obj) {
408        mActivePhone.registerForUnknownConnection(h, what, obj);
409    }
410
411    @Override
412    public void unregisterForUnknownConnection(Handler h) {
413        mActivePhone.unregisterForUnknownConnection(h);
414    }
415
416    @Override
417    public void registerForHandoverStateChanged(Handler h, int what, Object obj) {
418        mActivePhone.registerForHandoverStateChanged(h, what, obj);
419    }
420
421    @Override
422    public void unregisterForHandoverStateChanged(Handler h) {
423        mActivePhone.unregisterForHandoverStateChanged(h);
424    }
425
426    @Override
427    public void registerForPreciseCallStateChanged(Handler h, int what, Object obj) {
428        mActivePhone.registerForPreciseCallStateChanged(h, what, obj);
429    }
430
431    @Override
432    public void unregisterForPreciseCallStateChanged(Handler h) {
433        mActivePhone.unregisterForPreciseCallStateChanged(h);
434    }
435
436    @Override
437    public void registerForNewRingingConnection(Handler h, int what, Object obj) {
438        mActivePhone.registerForNewRingingConnection(h, what, obj);
439    }
440
441    @Override
442    public void unregisterForNewRingingConnection(Handler h) {
443        mActivePhone.unregisterForNewRingingConnection(h);
444    }
445
446    @Override
447    public void registerForIncomingRing(Handler h, int what, Object obj) {
448        mActivePhone.registerForIncomingRing(h, what, obj);
449    }
450
451    @Override
452    public void unregisterForIncomingRing(Handler h) {
453        mActivePhone.unregisterForIncomingRing(h);
454    }
455
456    @Override
457    public void registerForDisconnect(Handler h, int what, Object obj) {
458        mActivePhone.registerForDisconnect(h, what, obj);
459    }
460
461    @Override
462    public void unregisterForDisconnect(Handler h) {
463        mActivePhone.unregisterForDisconnect(h);
464    }
465
466    @Override
467    public void registerForMmiInitiate(Handler h, int what, Object obj) {
468        mActivePhone.registerForMmiInitiate(h, what, obj);
469    }
470
471    @Override
472    public void unregisterForMmiInitiate(Handler h) {
473        mActivePhone.unregisterForMmiInitiate(h);
474    }
475
476    @Override
477    public void registerForMmiComplete(Handler h, int what, Object obj) {
478        mActivePhone.registerForMmiComplete(h, what, obj);
479    }
480
481    @Override
482    public void unregisterForMmiComplete(Handler h) {
483        mActivePhone.unregisterForMmiComplete(h);
484    }
485
486    @Override
487    public List<? extends MmiCode> getPendingMmiCodes() {
488        return mActivePhone.getPendingMmiCodes();
489    }
490
491    @Override
492    public void sendUssdResponse(String ussdMessge) {
493        mActivePhone.sendUssdResponse(ussdMessge);
494    }
495
496    @Override
497    public void registerForServiceStateChanged(Handler h, int what, Object obj) {
498        mActivePhone.registerForServiceStateChanged(h, what, obj);
499    }
500
501    @Override
502    public void unregisterForServiceStateChanged(Handler h) {
503        mActivePhone.unregisterForServiceStateChanged(h);
504    }
505
506    @Override
507    public void registerForSuppServiceNotification(Handler h, int what, Object obj) {
508        mActivePhone.registerForSuppServiceNotification(h, what, obj);
509    }
510
511    @Override
512    public void unregisterForSuppServiceNotification(Handler h) {
513        mActivePhone.unregisterForSuppServiceNotification(h);
514    }
515
516    @Override
517    public void registerForSuppServiceFailed(Handler h, int what, Object obj) {
518        mActivePhone.registerForSuppServiceFailed(h, what, obj);
519    }
520
521    @Override
522    public void unregisterForSuppServiceFailed(Handler h) {
523        mActivePhone.unregisterForSuppServiceFailed(h);
524    }
525
526    @Override
527    public void registerForInCallVoicePrivacyOn(Handler h, int what, Object obj){
528        mActivePhone.registerForInCallVoicePrivacyOn(h,what,obj);
529    }
530
531    @Override
532    public void unregisterForInCallVoicePrivacyOn(Handler h){
533        mActivePhone.unregisterForInCallVoicePrivacyOn(h);
534    }
535
536    @Override
537    public void registerForInCallVoicePrivacyOff(Handler h, int what, Object obj){
538        mActivePhone.registerForInCallVoicePrivacyOff(h,what,obj);
539    }
540
541    @Override
542    public void unregisterForInCallVoicePrivacyOff(Handler h){
543        mActivePhone.unregisterForInCallVoicePrivacyOff(h);
544    }
545
546    @Override
547    public void registerForCdmaOtaStatusChange(Handler h, int what, Object obj) {
548        mActivePhone.registerForCdmaOtaStatusChange(h,what,obj);
549    }
550
551    @Override
552    public void unregisterForCdmaOtaStatusChange(Handler h) {
553         mActivePhone.unregisterForCdmaOtaStatusChange(h);
554    }
555
556    @Override
557    public void registerForSubscriptionInfoReady(Handler h, int what, Object obj) {
558        mActivePhone.registerForSubscriptionInfoReady(h, what, obj);
559    }
560
561    @Override
562    public void unregisterForSubscriptionInfoReady(Handler h) {
563        mActivePhone.unregisterForSubscriptionInfoReady(h);
564    }
565
566    @Override
567    public void registerForEcmTimerReset(Handler h, int what, Object obj) {
568        mActivePhone.registerForEcmTimerReset(h,what,obj);
569    }
570
571    @Override
572    public void unregisterForEcmTimerReset(Handler h) {
573        mActivePhone.unregisterForEcmTimerReset(h);
574    }
575
576    @Override
577    public void registerForRingbackTone(Handler h, int what, Object obj) {
578        mActivePhone.registerForRingbackTone(h,what,obj);
579    }
580
581    @Override
582    public void unregisterForRingbackTone(Handler h) {
583        mActivePhone.unregisterForRingbackTone(h);
584    }
585
586    @Override
587    public void registerForOnHoldTone(Handler h, int what, Object obj) {
588        mActivePhone.registerForOnHoldTone(h,what,obj);
589    }
590
591    @Override
592    public void unregisterForOnHoldTone(Handler h) {
593        mActivePhone.unregisterForOnHoldTone(h);
594    }
595
596    @Override
597    public void registerForResendIncallMute(Handler h, int what, Object obj) {
598        mActivePhone.registerForResendIncallMute(h,what,obj);
599    }
600
601    @Override
602    public void unregisterForResendIncallMute(Handler h) {
603        mActivePhone.unregisterForResendIncallMute(h);
604    }
605
606    @Override
607    public void registerForSimRecordsLoaded(Handler h, int what, Object obj) {
608        mActivePhone.registerForSimRecordsLoaded(h,what,obj);
609    }
610
611    public void unregisterForSimRecordsLoaded(Handler h) {
612        mActivePhone.unregisterForSimRecordsLoaded(h);
613    }
614
615    @Override
616    public boolean getIccRecordsLoaded() {
617        return mIccCardProxy.getIccRecordsLoaded();
618    }
619
620    @Override
621    public IccCard getIccCard() {
622        return mIccCardProxy;
623    }
624
625    @Override
626    public void acceptCall(int videoState) throws CallStateException {
627        mActivePhone.acceptCall(videoState);
628    }
629
630    @Override
631    public void rejectCall() throws CallStateException {
632        mActivePhone.rejectCall();
633    }
634
635    @Override
636    public void switchHoldingAndActive() throws CallStateException {
637        mActivePhone.switchHoldingAndActive();
638    }
639
640    @Override
641    public boolean canConference() {
642        return mActivePhone.canConference();
643    }
644
645    @Override
646    public void conference() throws CallStateException {
647        mActivePhone.conference();
648    }
649
650    @Override
651    public void enableEnhancedVoicePrivacy(boolean enable, Message onComplete) {
652        mActivePhone.enableEnhancedVoicePrivacy(enable, onComplete);
653    }
654
655    @Override
656    public void getEnhancedVoicePrivacy(Message onComplete) {
657        mActivePhone.getEnhancedVoicePrivacy(onComplete);
658    }
659
660    @Override
661    public boolean canTransfer() {
662        return mActivePhone.canTransfer();
663    }
664
665    @Override
666    public void explicitCallTransfer() throws CallStateException {
667        mActivePhone.explicitCallTransfer();
668    }
669
670    @Override
671    public void clearDisconnected() {
672        mActivePhone.clearDisconnected();
673    }
674
675    @Override
676    public Call getForegroundCall() {
677        return mActivePhone.getForegroundCall();
678    }
679
680    @Override
681    public Call getBackgroundCall() {
682        return mActivePhone.getBackgroundCall();
683    }
684
685    @Override
686    public Call getRingingCall() {
687        return mActivePhone.getRingingCall();
688    }
689
690    @Override
691    public Connection dial(String dialString, int videoState) throws CallStateException {
692        return mActivePhone.dial(dialString, videoState);
693    }
694
695    @Override
696    public Connection dial(String dialString, UUSInfo uusInfo, int videoState) throws CallStateException {
697        return mActivePhone.dial(dialString, uusInfo, videoState);
698    }
699
700    @Override
701    public boolean handlePinMmi(String dialString) {
702        return mActivePhone.handlePinMmi(dialString);
703    }
704
705    @Override
706    public boolean handleInCallMmiCommands(String command) throws CallStateException {
707        return mActivePhone.handleInCallMmiCommands(command);
708    }
709
710    @Override
711    public void sendDtmf(char c) {
712        mActivePhone.sendDtmf(c);
713    }
714
715    @Override
716    public void startDtmf(char c) {
717        mActivePhone.startDtmf(c);
718    }
719
720    @Override
721    public void stopDtmf() {
722        mActivePhone.stopDtmf();
723    }
724
725    @Override
726    public void setRadioPower(boolean power) {
727        mActivePhone.setRadioPower(power);
728    }
729
730    @Override
731    public boolean getMessageWaitingIndicator() {
732        return mActivePhone.getMessageWaitingIndicator();
733    }
734
735    @Override
736    public boolean getCallForwardingIndicator() {
737        return mActivePhone.getCallForwardingIndicator();
738    }
739
740    @Override
741    public String getLine1Number() {
742        return mActivePhone.getLine1Number();
743    }
744
745    @Override
746    public String getCdmaMin() {
747        return mActivePhone.getCdmaMin();
748    }
749
750    @Override
751    public boolean isMinInfoReady() {
752        return mActivePhone.isMinInfoReady();
753    }
754
755    @Override
756    public String getCdmaPrlVersion() {
757        return mActivePhone.getCdmaPrlVersion();
758    }
759
760    @Override
761    public String getLine1AlphaTag() {
762        return mActivePhone.getLine1AlphaTag();
763    }
764
765    @Override
766    public void setLine1Number(String alphaTag, String number, Message onComplete) {
767        mActivePhone.setLine1Number(alphaTag, number, onComplete);
768    }
769
770    @Override
771    public String getVoiceMailNumber() {
772        return mActivePhone.getVoiceMailNumber();
773    }
774
775     /** @hide */
776    @Override
777    public int getVoiceMessageCount(){
778        return mActivePhone.getVoiceMessageCount();
779    }
780
781    @Override
782    public String getVoiceMailAlphaTag() {
783        return mActivePhone.getVoiceMailAlphaTag();
784    }
785
786    @Override
787    public void setVoiceMailNumber(String alphaTag,String voiceMailNumber,
788            Message onComplete) {
789        mActivePhone.setVoiceMailNumber(alphaTag, voiceMailNumber, onComplete);
790    }
791
792    @Override
793    public void getCallForwardingOption(int commandInterfaceCFReason,
794            Message onComplete) {
795        mActivePhone.getCallForwardingOption(commandInterfaceCFReason,
796                onComplete);
797    }
798
799    @Override
800    public void setCallForwardingOption(int commandInterfaceCFReason,
801            int commandInterfaceCFAction, String dialingNumber,
802            int timerSeconds, Message onComplete) {
803        mActivePhone.setCallForwardingOption(commandInterfaceCFReason,
804            commandInterfaceCFAction, dialingNumber, timerSeconds, onComplete);
805    }
806
807    @Override
808    public void getOutgoingCallerIdDisplay(Message onComplete) {
809        mActivePhone.getOutgoingCallerIdDisplay(onComplete);
810    }
811
812    @Override
813    public void setOutgoingCallerIdDisplay(int commandInterfaceCLIRMode,
814            Message onComplete) {
815        mActivePhone.setOutgoingCallerIdDisplay(commandInterfaceCLIRMode,
816                onComplete);
817    }
818
819    @Override
820    public void getCallWaiting(Message onComplete) {
821        mActivePhone.getCallWaiting(onComplete);
822    }
823
824    @Override
825    public void setCallWaiting(boolean enable, Message onComplete) {
826        mActivePhone.setCallWaiting(enable, onComplete);
827    }
828
829    @Override
830    public void getAvailableNetworks(Message response) {
831        mActivePhone.getAvailableNetworks(response);
832    }
833
834    @Override
835    public void setNetworkSelectionModeAutomatic(Message response) {
836        mActivePhone.setNetworkSelectionModeAutomatic(response);
837    }
838
839    @Override
840    public void selectNetworkManually(OperatorInfo network, Message response) {
841        mActivePhone.selectNetworkManually(network, response);
842    }
843
844    @Override
845    public void setPreferredNetworkType(int networkType, Message response) {
846        mActivePhone.setPreferredNetworkType(networkType, response);
847    }
848
849    @Override
850    public void getPreferredNetworkType(Message response) {
851        mActivePhone.getPreferredNetworkType(response);
852    }
853
854    @Override
855    public void getNeighboringCids(Message response) {
856        mActivePhone.getNeighboringCids(response);
857    }
858
859    @Override
860    public void setOnPostDialCharacter(Handler h, int what, Object obj) {
861        mActivePhone.setOnPostDialCharacter(h, what, obj);
862    }
863
864    @Override
865    public void setMute(boolean muted) {
866        mActivePhone.setMute(muted);
867    }
868
869    @Override
870    public boolean getMute() {
871        return mActivePhone.getMute();
872    }
873
874    @Override
875    public void setEchoSuppressionEnabled() {
876        mActivePhone.setEchoSuppressionEnabled();
877    }
878
879    @Override
880    public void invokeOemRilRequestRaw(byte[] data, Message response) {
881        mActivePhone.invokeOemRilRequestRaw(data, response);
882    }
883
884    @Override
885    public void invokeOemRilRequestStrings(String[] strings, Message response) {
886        mActivePhone.invokeOemRilRequestStrings(strings, response);
887    }
888
889    @Override
890    public void getDataCallList(Message response) {
891        mActivePhone.getDataCallList(response);
892    }
893
894    @Override
895    public void updateServiceLocation() {
896        mActivePhone.updateServiceLocation();
897    }
898
899    @Override
900    public void enableLocationUpdates() {
901        mActivePhone.enableLocationUpdates();
902    }
903
904    @Override
905    public void disableLocationUpdates() {
906        mActivePhone.disableLocationUpdates();
907    }
908
909    @Override
910    public void setUnitTestMode(boolean f) {
911        mActivePhone.setUnitTestMode(f);
912    }
913
914    @Override
915    public boolean getUnitTestMode() {
916        return mActivePhone.getUnitTestMode();
917    }
918
919    @Override
920    public void setBandMode(int bandMode, Message response) {
921        mActivePhone.setBandMode(bandMode, response);
922    }
923
924    @Override
925    public void queryAvailableBandMode(Message response) {
926        mActivePhone.queryAvailableBandMode(response);
927    }
928
929    @Override
930    public boolean getDataRoamingEnabled() {
931        return mActivePhone.getDataRoamingEnabled();
932    }
933
934    @Override
935    public void setDataRoamingEnabled(boolean enable) {
936        mActivePhone.setDataRoamingEnabled(enable);
937    }
938
939    @Override
940    public boolean getDataEnabled() {
941        return mActivePhone.getDataEnabled();
942    }
943
944    @Override
945    public void setDataEnabled(boolean enable) {
946        mActivePhone.setDataEnabled(enable);
947    }
948
949    @Override
950    public void queryCdmaRoamingPreference(Message response) {
951        mActivePhone.queryCdmaRoamingPreference(response);
952    }
953
954    @Override
955    public void setCdmaRoamingPreference(int cdmaRoamingType, Message response) {
956        mActivePhone.setCdmaRoamingPreference(cdmaRoamingType, response);
957    }
958
959    @Override
960    public void setCdmaSubscription(int cdmaSubscriptionType, Message response) {
961        mActivePhone.setCdmaSubscription(cdmaSubscriptionType, response);
962    }
963
964    @Override
965    public SimulatedRadioControl getSimulatedRadioControl() {
966        return mActivePhone.getSimulatedRadioControl();
967    }
968
969    @Override
970    public boolean isDataConnectivityPossible() {
971        return mActivePhone.isDataConnectivityPossible(PhoneConstants.APN_TYPE_DEFAULT);
972    }
973
974    @Override
975    public boolean isDataConnectivityPossible(String apnType) {
976        return mActivePhone.isDataConnectivityPossible(apnType);
977    }
978
979    @Override
980    public String getDeviceId() {
981        return mActivePhone.getDeviceId();
982    }
983
984    @Override
985    public String getDeviceSvn() {
986        return mActivePhone.getDeviceSvn();
987    }
988
989    @Override
990    public String getSubscriberId() {
991        return mActivePhone.getSubscriberId();
992    }
993
994    @Override
995    public String getGroupIdLevel1() {
996        return mActivePhone.getGroupIdLevel1();
997    }
998
999    @Override
1000    public String getIccSerialNumber() {
1001        return mActivePhone.getIccSerialNumber();
1002    }
1003
1004    @Override
1005    public String getEsn() {
1006        return mActivePhone.getEsn();
1007    }
1008
1009    @Override
1010    public String getMeid() {
1011        return mActivePhone.getMeid();
1012    }
1013
1014    @Override
1015    public String getMsisdn() {
1016        return mActivePhone.getMsisdn();
1017    }
1018
1019    @Override
1020    public String getImei() {
1021        return mActivePhone.getImei();
1022    }
1023
1024    @Override
1025    public PhoneSubInfo getPhoneSubInfo(){
1026        return mActivePhone.getPhoneSubInfo();
1027    }
1028
1029    @Override
1030    public IccPhoneBookInterfaceManager getIccPhoneBookInterfaceManager(){
1031        return mActivePhone.getIccPhoneBookInterfaceManager();
1032    }
1033
1034    @Override
1035    public void setTTYMode(int ttyMode, Message onComplete) {
1036        mActivePhone.setTTYMode(ttyMode, onComplete);
1037    }
1038
1039    @Override
1040    public void queryTTYMode(Message onComplete) {
1041        mActivePhone.queryTTYMode(onComplete);
1042    }
1043
1044    @Override
1045    public void activateCellBroadcastSms(int activate, Message response) {
1046        mActivePhone.activateCellBroadcastSms(activate, response);
1047    }
1048
1049    @Override
1050    public void getCellBroadcastSmsConfig(Message response) {
1051        mActivePhone.getCellBroadcastSmsConfig(response);
1052    }
1053
1054    @Override
1055    public void setCellBroadcastSmsConfig(int[] configValuesArray, Message response) {
1056        mActivePhone.setCellBroadcastSmsConfig(configValuesArray, response);
1057    }
1058
1059    @Override
1060    public void notifyDataActivity() {
1061         mActivePhone.notifyDataActivity();
1062    }
1063
1064    @Override
1065    public void getSmscAddress(Message result) {
1066        mActivePhone.getSmscAddress(result);
1067    }
1068
1069    @Override
1070    public void setSmscAddress(String address, Message result) {
1071        mActivePhone.setSmscAddress(address, result);
1072    }
1073
1074    @Override
1075    public int getCdmaEriIconIndex() {
1076        return mActivePhone.getCdmaEriIconIndex();
1077    }
1078
1079    @Override
1080    public String getCdmaEriText() {
1081        return mActivePhone.getCdmaEriText();
1082    }
1083
1084    @Override
1085    public int getCdmaEriIconMode() {
1086        return mActivePhone.getCdmaEriIconMode();
1087    }
1088
1089    public Phone getActivePhone() {
1090        return mActivePhone;
1091    }
1092
1093    @Override
1094    public void sendBurstDtmf(String dtmfString, int on, int off, Message onComplete){
1095        mActivePhone.sendBurstDtmf(dtmfString, on, off, onComplete);
1096    }
1097
1098    @Override
1099    public void exitEmergencyCallbackMode(){
1100        mActivePhone.exitEmergencyCallbackMode();
1101    }
1102
1103    @Override
1104    public boolean needsOtaServiceProvisioning(){
1105        return mActivePhone.needsOtaServiceProvisioning();
1106    }
1107
1108    @Override
1109    public boolean isOtaSpNumber(String dialStr){
1110        return mActivePhone.isOtaSpNumber(dialStr);
1111    }
1112
1113    @Override
1114    public void registerForCallWaiting(Handler h, int what, Object obj){
1115        mActivePhone.registerForCallWaiting(h,what,obj);
1116    }
1117
1118    @Override
1119    public void unregisterForCallWaiting(Handler h){
1120        mActivePhone.unregisterForCallWaiting(h);
1121    }
1122
1123    @Override
1124    public void registerForSignalInfo(Handler h, int what, Object obj) {
1125        mActivePhone.registerForSignalInfo(h,what,obj);
1126    }
1127
1128    @Override
1129    public void unregisterForSignalInfo(Handler h) {
1130        mActivePhone.unregisterForSignalInfo(h);
1131    }
1132
1133    @Override
1134    public void registerForDisplayInfo(Handler h, int what, Object obj) {
1135        mActivePhone.registerForDisplayInfo(h,what,obj);
1136    }
1137
1138    @Override
1139    public void unregisterForDisplayInfo(Handler h) {
1140        mActivePhone.unregisterForDisplayInfo(h);
1141    }
1142
1143    @Override
1144    public void registerForNumberInfo(Handler h, int what, Object obj) {
1145        mActivePhone.registerForNumberInfo(h, what, obj);
1146    }
1147
1148    @Override
1149    public void unregisterForNumberInfo(Handler h) {
1150        mActivePhone.unregisterForNumberInfo(h);
1151    }
1152
1153    @Override
1154    public void registerForRedirectedNumberInfo(Handler h, int what, Object obj) {
1155        mActivePhone.registerForRedirectedNumberInfo(h, what, obj);
1156    }
1157
1158    @Override
1159    public void unregisterForRedirectedNumberInfo(Handler h) {
1160        mActivePhone.unregisterForRedirectedNumberInfo(h);
1161    }
1162
1163    @Override
1164    public void registerForLineControlInfo(Handler h, int what, Object obj) {
1165        mActivePhone.registerForLineControlInfo( h, what, obj);
1166    }
1167
1168    @Override
1169    public void unregisterForLineControlInfo(Handler h) {
1170        mActivePhone.unregisterForLineControlInfo(h);
1171    }
1172
1173    @Override
1174    public void registerFoT53ClirlInfo(Handler h, int what, Object obj) {
1175        mActivePhone.registerFoT53ClirlInfo(h, what, obj);
1176    }
1177
1178    @Override
1179    public void unregisterForT53ClirInfo(Handler h) {
1180        mActivePhone.unregisterForT53ClirInfo(h);
1181    }
1182
1183    @Override
1184    public void registerForT53AudioControlInfo(Handler h, int what, Object obj) {
1185        mActivePhone.registerForT53AudioControlInfo( h, what, obj);
1186    }
1187
1188    @Override
1189    public void unregisterForT53AudioControlInfo(Handler h) {
1190        mActivePhone.unregisterForT53AudioControlInfo(h);
1191    }
1192
1193    @Override
1194    public void setOnEcbModeExitResponse(Handler h, int what, Object obj){
1195        mActivePhone.setOnEcbModeExitResponse(h,what,obj);
1196    }
1197
1198    @Override
1199    public void unsetOnEcbModeExitResponse(Handler h){
1200        mActivePhone.unsetOnEcbModeExitResponse(h);
1201    }
1202
1203    @Override
1204    public boolean isCspPlmnEnabled() {
1205        return mActivePhone.isCspPlmnEnabled();
1206    }
1207
1208    @Override
1209    public IsimRecords getIsimRecords() {
1210        return mActivePhone.getIsimRecords();
1211    }
1212
1213    /**
1214     * {@inheritDoc}
1215     */
1216    @Override
1217    public int getLteOnCdmaMode() {
1218        return mActivePhone.getLteOnCdmaMode();
1219    }
1220
1221    @Override
1222    public void setVoiceMessageWaiting(int line, int countWaiting) {
1223        mActivePhone.setVoiceMessageWaiting(line, countWaiting);
1224    }
1225
1226    @Override
1227    public UsimServiceTable getUsimServiceTable() {
1228        return mActivePhone.getUsimServiceTable();
1229    }
1230
1231    @Override
1232    public UiccCard getUiccCard() {
1233        return mActivePhone.getUiccCard();
1234    }
1235
1236    @Override
1237    public void nvReadItem(int itemID, Message response) {
1238        mActivePhone.nvReadItem(itemID, response);
1239    }
1240
1241    @Override
1242    public void nvWriteItem(int itemID, String itemValue, Message response) {
1243        mActivePhone.nvWriteItem(itemID, itemValue, response);
1244    }
1245
1246    @Override
1247    public void nvWriteCdmaPrl(byte[] preferredRoamingList, Message response) {
1248        mActivePhone.nvWriteCdmaPrl(preferredRoamingList, response);
1249    }
1250
1251    @Override
1252    public void nvResetConfig(int resetType, Message response) {
1253        mActivePhone.nvResetConfig(resetType, response);
1254    }
1255
1256    @Override
1257    public void dispose() {
1258        mCommandsInterface.unregisterForOn(this);
1259        mCommandsInterface.unregisterForVoiceRadioTechChanged(this);
1260        mCommandsInterface.unregisterForRilConnected(this);
1261    }
1262
1263    @Override
1264    public void removeReferences() {
1265        mActivePhone = null;
1266        mCommandsInterface = null;
1267    }
1268
1269    public boolean updateCurrentCarrierInProvider() {
1270        if (mActivePhone instanceof CDMALTEPhone) {
1271            return ((CDMALTEPhone)mActivePhone).updateCurrentCarrierInProvider();
1272        } else if (mActivePhone instanceof GSMPhone) {
1273            return ((GSMPhone)mActivePhone).updateCurrentCarrierInProvider();
1274        } else {
1275           loge("Phone object is not MultiSim. This should not hit!!!!");
1276           return false;
1277        }
1278    }
1279
1280    public void updateDataConnectionTracker() {
1281        logd("Updating Data Connection Tracker");
1282        if (mActivePhone instanceof CDMALTEPhone) {
1283            ((CDMALTEPhone)mActivePhone).updateDataConnectionTracker();
1284        } else if (mActivePhone instanceof GSMPhone) {
1285            ((GSMPhone)mActivePhone).updateDataConnectionTracker();
1286        } else {
1287           loge("Phone object is not MultiSim. This should not hit!!!!");
1288        }
1289    }
1290
1291    public void setInternalDataEnabled(boolean enable) {
1292        setInternalDataEnabled(enable, null);
1293    }
1294
1295    public boolean setInternalDataEnabledFlag(boolean enable) {
1296        boolean flag = false;
1297        if (mActivePhone instanceof CDMALTEPhone) {
1298            flag = ((CDMALTEPhone)mActivePhone).setInternalDataEnabledFlag(enable);
1299        } else if (mActivePhone instanceof GSMPhone) {
1300            flag = ((GSMPhone)mActivePhone).setInternalDataEnabledFlag(enable);
1301        } else {
1302           loge("Phone object is not MultiSim. This should not hit!!!!");
1303        }
1304        return flag;
1305    }
1306
1307    public void setInternalDataEnabled(boolean enable, Message onCompleteMsg) {
1308        if (mActivePhone instanceof CDMALTEPhone) {
1309            ((CDMALTEPhone)mActivePhone).setInternalDataEnabled(enable, onCompleteMsg);
1310        } else if (mActivePhone instanceof GSMPhone) {
1311            ((GSMPhone)mActivePhone).setInternalDataEnabled(enable, onCompleteMsg);
1312        } else {
1313           loge("Phone object is not MultiSim. This should not hit!!!!");
1314        }
1315    }
1316
1317    public void registerForAllDataDisconnected(Handler h, int what, Object obj) {
1318        if (mActivePhone instanceof CDMALTEPhone) {
1319            ((CDMALTEPhone)mActivePhone).registerForAllDataDisconnected(h, what, obj);
1320        } else if (mActivePhone instanceof GSMPhone) {
1321            ((GSMPhone)mActivePhone).registerForAllDataDisconnected(h, what, obj);
1322        } else {
1323           loge("Phone object is not MultiSim. This should not hit!!!!");
1324        }
1325    }
1326
1327    public void unregisterForAllDataDisconnected(Handler h) {
1328        if (mActivePhone instanceof CDMALTEPhone) {
1329            ((CDMALTEPhone)mActivePhone).unregisterForAllDataDisconnected(h);
1330        } else if (mActivePhone instanceof GSMPhone) {
1331            ((GSMPhone)mActivePhone).unregisterForAllDataDisconnected(h);
1332        } else {
1333           loge("Phone object is not MultiSim. This should not hit!!!!");
1334        }
1335    }
1336
1337
1338    public long getSubId() {
1339        return mActivePhone.getSubId();
1340    }
1341
1342    public int getPhoneId() {
1343        return mActivePhone.getPhoneId();
1344    }
1345
1346    @Override
1347    public String[] getPcscfAddress(String apnType) {
1348        return mActivePhone.getPcscfAddress(apnType);
1349    }
1350
1351    @Override
1352    public void setImsRegistrationState(boolean registered){
1353        logd("setImsRegistrationState - registered: " + registered);
1354
1355        mActivePhone.setImsRegistrationState(registered);
1356
1357        if ((mActivePhone.getPhoneName()).equals("GSM")) {
1358            GSMPhone GP = (GSMPhone)mActivePhone;
1359            GP.getServiceStateTracker().setImsRegistrationState(registered);
1360        } else if ((mActivePhone.getPhoneName()).equals("CDMA")) {
1361            CDMAPhone CP = (CDMAPhone)mActivePhone;
1362            CP.getServiceStateTracker().setImsRegistrationState(registered);
1363        }
1364    }
1365
1366    @Override
1367    public Phone getImsPhone() {
1368        return mActivePhone.getImsPhone();
1369    }
1370
1371    @Override
1372    public ImsPhone relinquishOwnershipOfImsPhone() { return null; }
1373
1374    @Override
1375    public void acquireOwnershipOfImsPhone(ImsPhone imsPhone) { }
1376
1377    @Override
1378    public int getVoicePhoneServiceState() {
1379        return mActivePhone.getVoicePhoneServiceState();
1380    }
1381
1382    @Override
1383    public boolean setOperatorBrandOverride(String brand) {
1384        return mActivePhone.setOperatorBrandOverride(brand);
1385    }
1386
1387    @Override
1388    public boolean isRadioAvailable() {
1389        return mCommandsInterface.getRadioState().isAvailable();
1390    }
1391
1392    @Override
1393    public void shutdownRadio() {
1394        mActivePhone.shutdownRadio();
1395    }
1396}
1397