CDMAPhone.java revision 5644b080741bb4fae103617ecbea7a62b0262a56
1/*
2 * Copyright (C) 2006 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.cdma;
18
19import android.app.ActivityManagerNative;
20import android.content.Context;
21import android.content.ContentValues;
22import android.content.Intent;
23import android.content.res.Configuration;
24import android.content.SharedPreferences;
25import android.database.SQLException;
26import android.net.Uri;
27import android.os.AsyncResult;
28import android.os.Handler;
29import android.os.Message;
30import android.os.PowerManager;
31import android.os.PowerManager.WakeLock;
32import android.os.Registrant;
33import android.os.RegistrantList;
34import android.os.RemoteException;
35import android.os.SystemProperties;
36import android.preference.PreferenceManager;
37import android.provider.Telephony;
38import android.telephony.CellLocation;
39import android.telephony.PhoneNumberUtils;
40import android.telephony.ServiceState;
41import android.telephony.SignalStrength;
42import android.text.TextUtils;
43import android.util.Log;
44
45import com.android.internal.telephony.cat.CatService;
46import com.android.internal.telephony.Call;
47import com.android.internal.telephony.CallStateException;
48import com.android.internal.telephony.CommandException;
49import com.android.internal.telephony.CommandsInterface;
50import com.android.internal.telephony.Connection;
51import com.android.internal.telephony.DataConnection;
52import com.android.internal.telephony.MccTable;
53import com.android.internal.telephony.IccCard;
54import com.android.internal.telephony.IccException;
55import com.android.internal.telephony.IccFileHandler;
56import com.android.internal.telephony.IccPhoneBookInterfaceManager;
57import com.android.internal.telephony.IccSmsInterfaceManager;
58import com.android.internal.telephony.MmiCode;
59import com.android.internal.telephony.Phone;
60import com.android.internal.telephony.PhoneBase;
61import com.android.internal.telephony.PhoneNotifier;
62import com.android.internal.telephony.PhoneProxy;
63import com.android.internal.telephony.PhoneSubInfo;
64import com.android.internal.telephony.ServiceStateTracker;
65import com.android.internal.telephony.TelephonyIntents;
66import com.android.internal.telephony.TelephonyProperties;
67import com.android.internal.telephony.UUSInfo;
68
69import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA;
70import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC;
71import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY;
72
73import java.util.ArrayList;
74import java.util.List;
75
76
77import java.util.regex.Matcher;
78import java.util.regex.Pattern;
79
80/**
81 * {@hide}
82 */
83public class CDMAPhone extends PhoneBase {
84    static final String LOG_TAG = "CDMA";
85    private static final boolean DBG = true;
86
87    // Default Emergency Callback Mode exit timer
88    private static final int DEFAULT_ECM_EXIT_TIMER_VALUE = 300000;
89
90    static final String VM_COUNT_CDMA = "vm_count_key_cdma";
91    private static final String VM_NUMBER_CDMA = "vm_number_key_cdma";
92    private String mVmNumber = null;
93
94    static final int RESTART_ECM_TIMER = 0; // restart Ecm timer
95    static final int CANCEL_ECM_TIMER = 1; // cancel Ecm timer
96
97    // Instance Variables
98    CdmaCallTracker mCT;
99    CdmaSMSDispatcher mSMS;
100    CdmaServiceStateTracker mSST;
101    RuimRecords mRuimRecords;
102    RuimCard mRuimCard;
103    ArrayList <CdmaMmiCode> mPendingMmis = new ArrayList<CdmaMmiCode>();
104    RuimPhoneBookInterfaceManager mRuimPhoneBookInterfaceManager;
105    RuimSmsInterfaceManager mRuimSmsInterfaceManager;
106    PhoneSubInfo mSubInfo;
107    EriManager mEriManager;
108    WakeLock mWakeLock;
109    CatService mCcatService;
110
111    // mNvLoadedRegistrants are informed after the EVENT_NV_READY
112    private RegistrantList mNvLoadedRegistrants = new RegistrantList();
113
114    // mEriFileLoadedRegistrants are informed after the ERI text has been loaded
115    private RegistrantList mEriFileLoadedRegistrants = new RegistrantList();
116
117    // mEcmTimerResetRegistrants are informed after Ecm timer is canceled or re-started
118    private RegistrantList mEcmTimerResetRegistrants = new RegistrantList();
119
120    // mEcmExitRespRegistrant is informed after the phone has been exited
121    //the emergency callback mode
122    //keep track of if phone is in emergency callback mode
123    private boolean mIsPhoneInEcmState;
124    private Registrant mEcmExitRespRegistrant;
125    private String mEsn;
126    private String mMeid;
127    // string to define how the carrier specifies its own ota sp number
128    private String mCarrierOtaSpNumSchema;
129
130    // A runnable which is used to automatically exit from Ecm after a period of time.
131    private Runnable mExitEcmRunnable = new Runnable() {
132        public void run() {
133            exitEmergencyCallbackMode();
134        }
135    };
136
137    Registrant mPostDialHandler;
138
139
140    // Constructors
141    public CDMAPhone(Context context, CommandsInterface ci, PhoneNotifier notifier) {
142        this(context,ci,notifier, false);
143    }
144
145    public CDMAPhone(Context context, CommandsInterface ci, PhoneNotifier notifier,
146            boolean unitTestMode) {
147        super(notifier, context, ci, unitTestMode);
148
149        mCM.setPhoneType(Phone.PHONE_TYPE_CDMA);
150        mCT = new CdmaCallTracker(this);
151        mSST = new CdmaServiceStateTracker (this);
152        mSMS = new CdmaSMSDispatcher(this);
153        mIccFileHandler = new RuimFileHandler(this);
154        mRuimRecords = new RuimRecords(this);
155        mDataConnection = new CdmaDataConnectionTracker (this);
156        mRuimCard = new RuimCard(this);
157        mRuimPhoneBookInterfaceManager = new RuimPhoneBookInterfaceManager(this);
158        mRuimSmsInterfaceManager = new RuimSmsInterfaceManager(this, mSMS);
159        mSubInfo = new PhoneSubInfo(this);
160        mEriManager = new EriManager(this, context, EriManager.ERI_FROM_XML);
161        mCcatService = CatService.getInstance(mCM, mRuimRecords, mContext,
162                mIccFileHandler, mRuimCard);
163
164        mCM.registerForAvailable(this, EVENT_RADIO_AVAILABLE, null);
165        mRuimRecords.registerForRecordsLoaded(this, EVENT_RUIM_RECORDS_LOADED, null);
166        mCM.registerForOffOrNotAvailable(this, EVENT_RADIO_OFF_OR_NOT_AVAILABLE, null);
167        mCM.registerForOn(this, EVENT_RADIO_ON, null);
168        mCM.setOnSuppServiceNotification(this, EVENT_SSN, null);
169        mSST.registerForNetworkAttach(this, EVENT_REGISTERED_TO_NETWORK, null);
170        mCM.registerForNVReady(this, EVENT_NV_READY, null);
171        mCM.setEmergencyCallbackMode(this, EVENT_EMERGENCY_CALLBACK_MODE_ENTER, null);
172
173        PowerManager pm
174            = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
175        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,LOG_TAG);
176
177        //Change the system setting
178        SystemProperties.set(TelephonyProperties.CURRENT_ACTIVE_PHONE,
179                new Integer(Phone.PHONE_TYPE_CDMA).toString());
180
181        // This is needed to handle phone process crashes
182        String inEcm=SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE, "false");
183        mIsPhoneInEcmState = inEcm.equals("true");
184        if (mIsPhoneInEcmState) {
185            // Send a message which will invoke handleExitEmergencyCallbackMode
186            mCM.exitEmergencyCallbackMode(obtainMessage(EVENT_EXIT_EMERGENCY_CALLBACK_RESPONSE));
187        }
188
189        // get the string that specifies the carrier OTA Sp number
190        mCarrierOtaSpNumSchema = SystemProperties.get(
191                TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA,"");
192
193        // Sets operator alpha property by retrieving from build-time system property
194        String operatorAlpha = SystemProperties.get("ro.cdma.home.operator.alpha");
195        setSystemProperty(PROPERTY_ICC_OPERATOR_ALPHA, operatorAlpha);
196
197        // Sets operator numeric property by retrieving from build-time system property
198        String operatorNumeric = SystemProperties.get("ro.cdma.home.operator.numeric");
199        setSystemProperty(PROPERTY_ICC_OPERATOR_NUMERIC, operatorNumeric);
200
201        // Sets iso country property by retrieving from build-time system property
202        setIsoCountryProperty(operatorNumeric);
203
204        // Sets current entry in the telephony carrier table
205        updateCurrentCarrierInProvider(operatorNumeric);
206
207        // Notify voicemails.
208        notifier.notifyMessageWaitingChanged(this);
209    }
210
211    public void dispose() {
212        synchronized(PhoneProxy.lockForRadioTechnologyChange) {
213            super.dispose();
214
215            //Unregister from all former registered events
216            mRuimRecords.unregisterForRecordsLoaded(this); //EVENT_RUIM_RECORDS_LOADED
217            mCM.unregisterForAvailable(this); //EVENT_RADIO_AVAILABLE
218            mCM.unregisterForOffOrNotAvailable(this); //EVENT_RADIO_OFF_OR_NOT_AVAILABLE
219            mCM.unregisterForOn(this); //EVENT_RADIO_ON
220            mCM.unregisterForNVReady(this); //EVENT_NV_READY
221            mSST.unregisterForNetworkAttach(this); //EVENT_REGISTERED_TO_NETWORK
222            mCM.unSetOnSuppServiceNotification(this);
223            removeCallbacks(mExitEcmRunnable);
224
225            mPendingMmis.clear();
226
227            //Force all referenced classes to unregister their former registered events
228            mCT.dispose();
229            mDataConnection.dispose();
230            mSST.dispose();
231            mSMS.dispose();
232            mIccFileHandler.dispose(); // instance of RuimFileHandler
233            mRuimRecords.dispose();
234            mRuimCard.dispose();
235            mRuimPhoneBookInterfaceManager.dispose();
236            mRuimSmsInterfaceManager.dispose();
237            mSubInfo.dispose();
238            mEriManager.dispose();
239            mCcatService.dispose();
240        }
241    }
242
243    public void removeReferences() {
244            this.mRuimPhoneBookInterfaceManager = null;
245            this.mRuimSmsInterfaceManager = null;
246            this.mSMS = null;
247            this.mSubInfo = null;
248            this.mRuimRecords = null;
249            this.mIccFileHandler = null;
250            this.mRuimCard = null;
251            this.mDataConnection = null;
252            this.mCT = null;
253            this.mSST = null;
254            this.mEriManager = null;
255            this.mCcatService = null;
256            this.mExitEcmRunnable = null;
257    }
258
259    protected void finalize() {
260        if(DBG) Log.d(LOG_TAG, "CDMAPhone finalized");
261        if (mWakeLock.isHeld()) {
262            Log.e(LOG_TAG, "UNEXPECTED; mWakeLock is held when finalizing.");
263            mWakeLock.release();
264        }
265    }
266
267    public ServiceState getServiceState() {
268        return mSST.ss;
269    }
270
271    public Phone.State getState() {
272        return mCT.state;
273    }
274
275    public String getPhoneName() {
276        return "CDMA";
277    }
278
279    public int getPhoneType() {
280        return Phone.PHONE_TYPE_CDMA;
281    }
282
283    public boolean canTransfer() {
284        Log.e(LOG_TAG, "canTransfer: not possible in CDMA");
285        return false;
286    }
287
288    public CdmaCall getRingingCall() {
289        return mCT.ringingCall;
290    }
291
292    public void setMute(boolean muted) {
293        mCT.setMute(muted);
294    }
295
296    public boolean getMute() {
297        return mCT.getMute();
298    }
299
300    public void conference() throws CallStateException {
301        // three way calls in CDMA will be handled by feature codes
302        Log.e(LOG_TAG, "conference: not possible in CDMA");
303    }
304
305    public void enableEnhancedVoicePrivacy(boolean enable, Message onComplete) {
306        this.mCM.setPreferredVoicePrivacy(enable, onComplete);
307    }
308
309    public void getEnhancedVoicePrivacy(Message onComplete) {
310        this.mCM.getPreferredVoicePrivacy(onComplete);
311    }
312
313    public void clearDisconnected() {
314        mCT.clearDisconnected();
315    }
316
317    public DataActivityState getDataActivityState() {
318        DataActivityState ret = DataActivityState.NONE;
319
320        if (mSST.getCurrentCdmaDataConnectionState() == ServiceState.STATE_IN_SERVICE) {
321
322            switch (mDataConnection.getActivity()) {
323                case DATAIN:
324                    ret = DataActivityState.DATAIN;
325                break;
326
327                case DATAOUT:
328                    ret = DataActivityState.DATAOUT;
329                break;
330
331                case DATAINANDOUT:
332                    ret = DataActivityState.DATAINANDOUT;
333                break;
334
335                case DORMANT:
336                    ret = DataActivityState.DORMANT;
337                break;
338            }
339        }
340        return ret;
341    }
342
343    /*package*/ void
344    notifySignalStrength() {
345        mNotifier.notifySignalStrength(this);
346    }
347
348    public Connection
349    dial (String dialString) throws CallStateException {
350        // Need to make sure dialString gets parsed properly
351        String newDialString = PhoneNumberUtils.stripSeparators(dialString);
352        return mCT.dial(newDialString);
353    }
354
355    public Connection dial(String dialString, UUSInfo uusInfo) throws CallStateException {
356        throw new CallStateException("Sending UUS information NOT supported in CDMA!");
357    }
358
359    public SignalStrength getSignalStrength() {
360        return mSST.mSignalStrength;
361    }
362
363    public boolean
364    getMessageWaitingIndicator() {
365        return (getVoiceMessageCount() > 0);
366    }
367
368    public List<? extends MmiCode>
369    getPendingMmiCodes() {
370        return mPendingMmis;
371    }
372
373    public void registerForSuppServiceNotification(
374            Handler h, int what, Object obj) {
375        Log.e(LOG_TAG, "method registerForSuppServiceNotification is NOT supported in CDMA!");
376    }
377
378    public CdmaCall getBackgroundCall() {
379        return mCT.backgroundCall;
380    }
381
382    public boolean handleInCallMmiCommands(String dialString) {
383        Log.e(LOG_TAG, "method handleInCallMmiCommands is NOT supported in CDMA!");
384        return false;
385    }
386
387    boolean isInCall() {
388        CdmaCall.State foregroundCallState = getForegroundCall().getState();
389        CdmaCall.State backgroundCallState = getBackgroundCall().getState();
390        CdmaCall.State ringingCallState = getRingingCall().getState();
391
392        return (foregroundCallState.isAlive() || backgroundCallState.isAlive() || ringingCallState
393                .isAlive());
394    }
395
396    public void
397    setNetworkSelectionModeAutomatic(Message response) {
398        Log.e(LOG_TAG, "method setNetworkSelectionModeAutomatic is NOT supported in CDMA!");
399    }
400
401    public void unregisterForSuppServiceNotification(Handler h) {
402        Log.e(LOG_TAG, "method unregisterForSuppServiceNotification is NOT supported in CDMA!");
403    }
404
405    public void
406    acceptCall() throws CallStateException {
407        mCT.acceptCall();
408    }
409
410    public void
411    rejectCall() throws CallStateException {
412        mCT.rejectCall();
413    }
414
415    public void
416    switchHoldingAndActive() throws CallStateException {
417        mCT.switchWaitingOrHoldingAndActive();
418    }
419
420    public String getLine1Number() {
421        return mSST.getMdnNumber();
422    }
423
424    public String getCdmaPrlVersion(){
425        return mSST.getPrlVersion();
426    }
427
428    public String getCdmaMin() {
429        return mSST.getCdmaMin();
430    }
431
432    public boolean isMinInfoReady() {
433        return mSST.isMinInfoReady();
434    }
435
436    public void getCallWaiting(Message onComplete) {
437        mCM.queryCallWaiting(CommandsInterface.SERVICE_CLASS_VOICE, onComplete);
438    }
439
440    public void
441    setRadioPower(boolean power) {
442        mSST.setRadioPower(power);
443    }
444
445    public String getEsn() {
446        return mEsn;
447    }
448
449    public String getMeid() {
450        return mMeid;
451    }
452
453    //returns MEID or ESN in CDMA
454    public String getDeviceId() {
455        String id = getMeid();
456        if ((id == null) || id.matches("^0*$")) {
457            Log.d(LOG_TAG, "getDeviceId(): MEID is not initialized use ESN");
458            id = getEsn();
459        }
460        return id;
461    }
462
463    public String getDeviceSvn() {
464        Log.d(LOG_TAG, "getDeviceSvn(): return 0");
465        return "0";
466    }
467
468    public String getSubscriberId() {
469        return mSST.getImsi();
470    }
471
472    public boolean canConference() {
473        Log.e(LOG_TAG, "canConference: not possible in CDMA");
474        return false;
475    }
476
477    public CellLocation getCellLocation() {
478        return mSST.cellLoc;
479    }
480
481    public boolean disableDataConnectivity() {
482        return mDataConnection.setDataEnabled(false);
483    }
484
485    public CdmaCall getForegroundCall() {
486        return mCT.foregroundCall;
487    }
488
489    public void
490    selectNetworkManually(com.android.internal.telephony.gsm.NetworkInfo network,
491            Message response) {
492        Log.e(LOG_TAG, "selectNetworkManually: not possible in CDMA");
493    }
494
495    public void setOnPostDialCharacter(Handler h, int what, Object obj) {
496        mPostDialHandler = new Registrant(h, what, obj);
497    }
498
499    public boolean handlePinMmi(String dialString) {
500        CdmaMmiCode mmi = CdmaMmiCode.newFromDialString(dialString, this);
501
502        if (mmi == null) {
503            Log.e(LOG_TAG, "Mmi is NULL!");
504            return false;
505        } else if (mmi.isPukCommand()) {
506            mPendingMmis.add(mmi);
507            mMmiRegistrants.notifyRegistrants(new AsyncResult(null, mmi, null));
508            mmi.processCode();
509            return true;
510        }
511        Log.e(LOG_TAG, "Unrecognized mmi!");
512        return false;
513    }
514
515    /**
516     * Removes the given MMI from the pending list and notifies registrants that
517     * it is complete.
518     *
519     * @param mmi MMI that is done
520     */
521    void onMMIDone(CdmaMmiCode mmi) {
522        /*
523         * Only notify complete if it's on the pending list. Otherwise, it's
524         * already been handled (eg, previously canceled).
525         */
526        if (mPendingMmis.remove(mmi)) {
527            mMmiCompleteRegistrants.notifyRegistrants(new AsyncResult(null, mmi, null));
528        }
529    }
530
531    public void setLine1Number(String alphaTag, String number, Message onComplete) {
532        Log.e(LOG_TAG, "setLine1Number: not possible in CDMA");
533    }
534
535    public IccCard getIccCard() {
536        return mRuimCard;
537    }
538
539    public String getIccSerialNumber() {
540        return mRuimRecords.iccid;
541    }
542
543    public void setCallWaiting(boolean enable, Message onComplete) {
544        Log.e(LOG_TAG, "method setCallWaiting is NOT supported in CDMA!");
545    }
546
547    public void updateServiceLocation() {
548        mSST.enableSingleLocationUpdate();
549    }
550
551    public void setDataRoamingEnabled(boolean enable) {
552        mDataConnection.setDataOnRoamingEnabled(enable);
553    }
554
555    public void registerForCdmaOtaStatusChange(Handler h, int what, Object obj) {
556        mCM.registerForCdmaOtaProvision(h, what, obj);
557    }
558
559    public void unregisterForCdmaOtaStatusChange(Handler h) {
560        mCM.unregisterForCdmaOtaProvision(h);
561    }
562
563    public void registerForSubscriptionInfoReady(Handler h, int what, Object obj) {
564        mSST.registerForSubscriptionInfoReady(h, what, obj);
565    }
566
567    public void unregisterForSubscriptionInfoReady(Handler h) {
568        mSST.unregisterForSubscriptionInfoReady(h);
569    }
570
571    public void setOnEcbModeExitResponse(Handler h, int what, Object obj) {
572        mEcmExitRespRegistrant = new Registrant (h, what, obj);
573    }
574
575    public void unsetOnEcbModeExitResponse(Handler h) {
576        mEcmExitRespRegistrant.clear();
577    }
578
579    public void registerForCallWaiting(Handler h, int what, Object obj) {
580        mCT.registerForCallWaiting(h, what, obj);
581    }
582
583    public void unregisterForCallWaiting(Handler h) {
584        mCT.unregisterForCallWaiting(h);
585    }
586
587    public void
588    getNeighboringCids(Message response) {
589        /*
590         * This is currently not implemented.  At least as of June
591         * 2009, there is no neighbor cell information available for
592         * CDMA because some party is resisting making this
593         * information readily available.  Consequently, calling this
594         * function can have no useful effect.  This situation may
595         * (and hopefully will) change in the future.
596         */
597        if (response != null) {
598            CommandException ce = new CommandException(
599                    CommandException.Error.REQUEST_NOT_SUPPORTED);
600            AsyncResult.forMessage(response).exception = ce;
601            response.sendToTarget();
602        }
603    }
604
605    public DataState getDataConnectionState(String apnType) {
606        DataState ret = DataState.DISCONNECTED;
607
608        if (mSST == null) {
609             // Radio Technology Change is ongoning, dispose() and removeReferences() have
610             // already been called
611
612             ret = DataState.DISCONNECTED;
613        } else if (mSST.getCurrentCdmaDataConnectionState() != ServiceState.STATE_IN_SERVICE) {
614            // If we're out of service, open TCP sockets may still work
615            // but no data will flow
616            ret = DataState.DISCONNECTED;
617        } else if (mDataConnection.isApnTypeEnabled(apnType) == false) {
618            ret = DataState.DISCONNECTED;
619        } else {
620            switch (mDataConnection.getState()) {
621                case FAILED:
622                case IDLE:
623                    ret = DataState.DISCONNECTED;
624                break;
625
626                case CONNECTED:
627                case DISCONNECTING:
628                    if ( mCT.state != Phone.State.IDLE
629                            && !mSST.isConcurrentVoiceAndData()) {
630                        ret = DataState.SUSPENDED;
631                    } else {
632                        ret = DataState.CONNECTED;
633                    }
634                break;
635
636                case INITING:
637                case CONNECTING:
638                case SCANNING:
639                    ret = DataState.CONNECTING;
640                break;
641            }
642        }
643
644        return ret;
645    }
646
647    public void sendUssdResponse(String ussdMessge) {
648        Log.e(LOG_TAG, "sendUssdResponse: not possible in CDMA");
649    }
650
651    public void sendDtmf(char c) {
652        if (!PhoneNumberUtils.is12Key(c)) {
653            Log.e(LOG_TAG,
654                    "sendDtmf called with invalid character '" + c + "'");
655        } else {
656            if (mCT.state ==  Phone.State.OFFHOOK) {
657                mCM.sendDtmf(c, null);
658            }
659        }
660    }
661
662    public void startDtmf(char c) {
663        if (!PhoneNumberUtils.is12Key(c)) {
664            Log.e(LOG_TAG,
665                    "startDtmf called with invalid character '" + c + "'");
666        } else {
667            mCM.startDtmf(c, null);
668        }
669    }
670
671    public void stopDtmf() {
672        mCM.stopDtmf(null);
673    }
674
675    public void sendBurstDtmf(String dtmfString, int on, int off, Message onComplete) {
676        boolean check = true;
677        for (int itr = 0;itr < dtmfString.length(); itr++) {
678            if (!PhoneNumberUtils.is12Key(dtmfString.charAt(itr))) {
679                Log.e(LOG_TAG,
680                        "sendDtmf called with invalid character '" + dtmfString.charAt(itr)+ "'");
681                check = false;
682                break;
683            }
684        }
685        if ((mCT.state ==  Phone.State.OFFHOOK)&&(check)) {
686            mCM.sendBurstDtmf(dtmfString, on, off, onComplete);
687        }
688     }
689
690    public void getAvailableNetworks(Message response) {
691        Log.e(LOG_TAG, "getAvailableNetworks: not possible in CDMA");
692    }
693
694    public void setOutgoingCallerIdDisplay(int commandInterfaceCLIRMode, Message onComplete) {
695        Log.e(LOG_TAG, "setOutgoingCallerIdDisplay: not possible in CDMA");
696    }
697
698    public void enableLocationUpdates() {
699        mSST.enableLocationUpdates();
700    }
701
702    public void disableLocationUpdates() {
703        mSST.disableLocationUpdates();
704    }
705
706    public void getDataCallList(Message response) {
707        mCM.getDataCallList(response);
708    }
709
710    public boolean getDataRoamingEnabled() {
711        return mDataConnection.getDataOnRoamingEnabled();
712    }
713
714    public List<DataConnection> getCurrentDataConnectionList () {
715        return mDataConnection.getAllDataConnections();
716    }
717
718    public void setVoiceMailNumber(String alphaTag,
719                                   String voiceMailNumber,
720                                   Message onComplete) {
721        Message resp;
722        mVmNumber = voiceMailNumber;
723        resp = obtainMessage(EVENT_SET_VM_NUMBER_DONE, 0, 0, onComplete);
724        mRuimRecords.setVoiceMailNumber(alphaTag, mVmNumber, resp);
725    }
726
727    public String getVoiceMailNumber() {
728        String number = null;
729        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
730        // TODO: The default value of voicemail number should be read from a system property
731        number = sp.getString(VM_NUMBER_CDMA, "*86");
732        return number;
733    }
734
735    /* Returns Number of Voicemails
736     * @hide
737     */
738    public int getVoiceMessageCount() {
739        int voicemailCount =  mRuimRecords.getVoiceMessageCount();
740        // If mRuimRecords.getVoiceMessageCount returns zero, then there is possibility
741        // that phone was power cycled and would have lost the voicemail count.
742        // So get the count from preferences.
743        if (voicemailCount == 0) {
744            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
745            voicemailCount = sp.getInt(VM_COUNT_CDMA, 0);
746        }
747        return voicemailCount;
748    }
749
750    public String getVoiceMailAlphaTag() {
751        // TODO: Where can we get this value has to be clarified with QC.
752        String ret = "";//TODO: Remove = "", if we know where to get this value.
753
754        //ret = mSIMRecords.getVoiceMailAlphaTag();
755
756        if (ret == null || ret.length() == 0) {
757            return mContext.getText(
758                com.android.internal.R.string.defaultVoiceMailAlphaTag).toString();
759        }
760
761        return ret;
762    }
763
764    public boolean enableDataConnectivity() {
765
766        // block data activities when phone is in emergency callback mode
767        if (mIsPhoneInEcmState) {
768            Intent intent = new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS);
769            ActivityManagerNative.broadcastStickyIntent(intent, null);
770            return false;
771        } else if ((mCT.state == Phone.State.OFFHOOK) && mCT.isInEmergencyCall()) {
772            // Do not allow data call to be enabled when emergency call is going on
773            return false;
774        } else {
775            return mDataConnection.setDataEnabled(true);
776        }
777    }
778
779    public boolean getIccRecordsLoaded() {
780        return mRuimRecords.getRecordsLoaded();
781    }
782
783    public void getCallForwardingOption(int commandInterfaceCFReason, Message onComplete) {
784        Log.e(LOG_TAG, "getCallForwardingOption: not possible in CDMA");
785    }
786
787    public void setCallForwardingOption(int commandInterfaceCFAction,
788            int commandInterfaceCFReason,
789            String dialingNumber,
790            int timerSeconds,
791            Message onComplete) {
792        Log.e(LOG_TAG, "setCallForwardingOption: not possible in CDMA");
793    }
794
795    public void
796    getOutgoingCallerIdDisplay(Message onComplete) {
797        Log.e(LOG_TAG, "getOutgoingCallerIdDisplay: not possible in CDMA");
798    }
799
800    public boolean
801    getCallForwardingIndicator() {
802        Log.e(LOG_TAG, "getCallForwardingIndicator: not possible in CDMA");
803        return false;
804    }
805
806    public void explicitCallTransfer() {
807        Log.e(LOG_TAG, "explicitCallTransfer: not possible in CDMA");
808    }
809
810    public String getLine1AlphaTag() {
811        Log.e(LOG_TAG, "getLine1AlphaTag: not possible in CDMA");
812        return null;
813    }
814
815   /**
816     * Notify any interested party of a Phone state change  {@link Phone.State}
817     */
818    /*package*/ void notifyPhoneStateChanged() {
819        mNotifier.notifyPhoneState(this);
820    }
821
822    /**
823     * Notify registrants of a change in the call state. This notifies changes in {@link Call.State}
824     * Use this when changes in the precise call state are needed, else use notifyPhoneStateChanged.
825     */
826    /*package*/ void notifyPreciseCallStateChanged() {
827        /* we'd love it if this was package-scoped*/
828        super.notifyPreciseCallStateChangedP();
829    }
830
831     void notifyServiceStateChanged(ServiceState ss) {
832         super.notifyServiceStateChangedP(ss);
833     }
834
835     void notifyLocationChanged() {
836         mNotifier.notifyCellLocation(this);
837     }
838
839    /*package*/ void notifyNewRingingConnection(Connection c) {
840        /* we'd love it if this was package-scoped*/
841        super.notifyNewRingingConnectionP(c);
842    }
843
844    /*package*/ void notifyDisconnect(Connection cn) {
845        mDisconnectRegistrants.notifyResult(cn);
846    }
847
848    void notifyUnknownConnection() {
849        mUnknownConnectionRegistrants.notifyResult(this);
850    }
851
852    void sendEmergencyCallbackModeChange(){
853        //Send an Intent
854        Intent intent = new Intent(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
855        intent.putExtra(PHONE_IN_ECM_STATE, mIsPhoneInEcmState);
856        ActivityManagerNative.broadcastStickyIntent(intent,null);
857        if (DBG) Log.d(LOG_TAG, "sendEmergencyCallbackModeChange");
858    }
859
860    /*package*/ void
861    updateMessageWaitingIndicator(boolean mwi) {
862        // this also calls notifyMessageWaitingIndicator()
863        mRuimRecords.setVoiceMessageWaiting(1, mwi ? -1 : 0);
864    }
865
866    /* This function is overloaded to send number of voicemails instead of sending true/false */
867    /*package*/ void
868    updateMessageWaitingIndicator(int mwi) {
869        mRuimRecords.setVoiceMessageWaiting(1, mwi);
870    }
871
872    @Override
873    public void exitEmergencyCallbackMode() {
874        if (mWakeLock.isHeld()) {
875            mWakeLock.release();
876        }
877        // Send a message which will invoke handleExitEmergencyCallbackMode
878        mCM.exitEmergencyCallbackMode(obtainMessage(EVENT_EXIT_EMERGENCY_CALLBACK_RESPONSE));
879    }
880
881    private void handleEnterEmergencyCallbackMode(Message msg) {
882        if (DBG) {
883            Log.d(LOG_TAG, "handleEnterEmergencyCallbackMode,mIsPhoneInEcmState= "
884                    + mIsPhoneInEcmState);
885        }
886        // if phone is not in Ecm mode, and it's changed to Ecm mode
887        if (mIsPhoneInEcmState == false) {
888            mIsPhoneInEcmState = true;
889            // notify change
890            sendEmergencyCallbackModeChange();
891            setSystemProperty(TelephonyProperties.PROPERTY_INECM_MODE, "true");
892
893            // Post this runnable so we will automatically exit
894            // if no one invokes exitEmergencyCallbackMode() directly.
895            long delayInMillis = SystemProperties.getLong(
896                    TelephonyProperties.PROPERTY_ECM_EXIT_TIMER, DEFAULT_ECM_EXIT_TIMER_VALUE);
897            postDelayed(mExitEcmRunnable, delayInMillis);
898            // We don't want to go to sleep while in Ecm
899            mWakeLock.acquire();
900        }
901    }
902
903    private void handleExitEmergencyCallbackMode(Message msg) {
904        AsyncResult ar = (AsyncResult)msg.obj;
905        if (DBG) {
906            Log.d(LOG_TAG, "handleExitEmergencyCallbackMode,ar.exception , mIsPhoneInEcmState "
907                    + ar.exception + mIsPhoneInEcmState);
908        }
909        // Remove pending exit Ecm runnable, if any
910        removeCallbacks(mExitEcmRunnable);
911
912        if (mEcmExitRespRegistrant != null) {
913            mEcmExitRespRegistrant.notifyRegistrant(ar);
914        }
915        // if exiting ecm success
916        if (ar.exception == null) {
917            if (mIsPhoneInEcmState) {
918                mIsPhoneInEcmState = false;
919                setSystemProperty(TelephonyProperties.PROPERTY_INECM_MODE, "false");
920            }
921            // send an Intent
922            sendEmergencyCallbackModeChange();
923            // Re-initiate data connection
924            mDataConnection.setDataEnabled(true);
925        }
926    }
927
928    /**
929     * Handle to cancel or restart Ecm timer in emergency call back mode
930     * if action is CANCEL_ECM_TIMER, cancel Ecm timer and notify apps the timer is canceled;
931     * otherwise, restart Ecm timer and notify apps the timer is restarted.
932     */
933    void handleTimerInEmergencyCallbackMode(int action) {
934        switch(action) {
935        case CANCEL_ECM_TIMER:
936            removeCallbacks(mExitEcmRunnable);
937            mEcmTimerResetRegistrants.notifyResult(Boolean.TRUE);
938            break;
939        case RESTART_ECM_TIMER:
940            long delayInMillis = SystemProperties.getLong(
941                    TelephonyProperties.PROPERTY_ECM_EXIT_TIMER, DEFAULT_ECM_EXIT_TIMER_VALUE);
942            postDelayed(mExitEcmRunnable, delayInMillis);
943            mEcmTimerResetRegistrants.notifyResult(Boolean.FALSE);
944            break;
945        default:
946            Log.e(LOG_TAG, "handleTimerInEmergencyCallbackMode, unsupported action " + action);
947        }
948    }
949
950    /**
951     * Registration point for Ecm timer reset
952     * @param h handler to notify
953     * @param what User-defined message code
954     * @param obj placed in Message.obj
955     */
956    public void registerForEcmTimerReset(Handler h, int what, Object obj) {
957        mEcmTimerResetRegistrants.addUnique(h, what, obj);
958    }
959
960    public void unregisterForEcmTimerReset(Handler h) {
961        mEcmTimerResetRegistrants.remove(h);
962    }
963
964    @Override
965    public void handleMessage(Message msg) {
966        AsyncResult ar;
967        Message     onComplete;
968
969        switch(msg.what) {
970            case EVENT_RADIO_AVAILABLE: {
971                mCM.getBasebandVersion(obtainMessage(EVENT_GET_BASEBAND_VERSION_DONE));
972
973                mCM.getDeviceIdentity(obtainMessage(EVENT_GET_DEVICE_IDENTITY_DONE));
974            }
975            break;
976
977            case EVENT_GET_BASEBAND_VERSION_DONE:{
978                ar = (AsyncResult)msg.obj;
979
980                if (ar.exception != null) {
981                    break;
982                }
983
984                if (DBG) Log.d(LOG_TAG, "Baseband version: " + ar.result);
985                setSystemProperty(TelephonyProperties.PROPERTY_BASEBAND_VERSION, (String)ar.result);
986            }
987            break;
988
989            case EVENT_GET_DEVICE_IDENTITY_DONE:{
990                ar = (AsyncResult)msg.obj;
991
992                if (ar.exception != null) {
993                    break;
994                }
995                String[] respId = (String[])ar.result;
996                mEsn  =  respId[2];
997                mMeid =  respId[3];
998            }
999            break;
1000
1001            case EVENT_EMERGENCY_CALLBACK_MODE_ENTER:{
1002                handleEnterEmergencyCallbackMode(msg);
1003            }
1004            break;
1005
1006            case  EVENT_EXIT_EMERGENCY_CALLBACK_RESPONSE:{
1007                handleExitEmergencyCallbackMode(msg);
1008            }
1009            break;
1010
1011            case EVENT_RUIM_RECORDS_LOADED:{
1012                Log.d(LOG_TAG, "Event EVENT_RUIM_RECORDS_LOADED Received");
1013            }
1014            break;
1015
1016            case EVENT_RADIO_OFF_OR_NOT_AVAILABLE:{
1017                Log.d(LOG_TAG, "Event EVENT_RADIO_OFF_OR_NOT_AVAILABLE Received");
1018            }
1019            break;
1020
1021            case EVENT_RADIO_ON:{
1022                Log.d(LOG_TAG, "Event EVENT_RADIO_ON Received");
1023            }
1024            break;
1025
1026            case EVENT_SSN:{
1027                Log.d(LOG_TAG, "Event EVENT_SSN Received");
1028            }
1029            break;
1030
1031            case EVENT_REGISTERED_TO_NETWORK:{
1032                Log.d(LOG_TAG, "Event EVENT_REGISTERED_TO_NETWORK Received");
1033            }
1034            break;
1035
1036            case EVENT_NV_READY:{
1037                Log.d(LOG_TAG, "Event EVENT_NV_READY Received");
1038                //Inform the Service State Tracker
1039                mEriManager.loadEriFile();
1040                mNvLoadedRegistrants.notifyRegistrants();
1041                if(mEriManager.isEriFileLoaded()) {
1042                    // when the ERI file is loaded
1043                    Log.d(LOG_TAG, "ERI read, notify registrants");
1044                    mEriFileLoadedRegistrants.notifyRegistrants();
1045                }
1046            }
1047            break;
1048
1049            case EVENT_SET_VM_NUMBER_DONE:{
1050                ar = (AsyncResult)msg.obj;
1051                if (IccException.class.isInstance(ar.exception)) {
1052                    storeVoiceMailNumber(mVmNumber);
1053                    ar.exception = null;
1054                }
1055                onComplete = (Message) ar.userObj;
1056                if (onComplete != null) {
1057                    AsyncResult.forMessage(onComplete, ar.result, ar.exception);
1058                    onComplete.sendToTarget();
1059                }
1060            }
1061            break;
1062
1063            default:{
1064                super.handleMessage(msg);
1065            }
1066        }
1067    }
1068
1069    /**
1070     * Retrieves the PhoneSubInfo of the CDMAPhone
1071     */
1072    public PhoneSubInfo getPhoneSubInfo() {
1073        return mSubInfo;
1074    }
1075
1076    /**
1077     * Retrieves the IccSmsInterfaceManager of the CDMAPhone
1078     */
1079    public IccSmsInterfaceManager getIccSmsInterfaceManager() {
1080        return mRuimSmsInterfaceManager;
1081    }
1082
1083    /**
1084     * Retrieves the IccPhoneBookInterfaceManager of the CDMAPhone
1085     */
1086    public IccPhoneBookInterfaceManager getIccPhoneBookInterfaceManager() {
1087        return mRuimPhoneBookInterfaceManager;
1088    }
1089
1090    public void registerForNvLoaded(Handler h, int what, Object obj) {
1091        Registrant r = new Registrant (h, what, obj);
1092        mNvLoadedRegistrants.add(r);
1093    }
1094
1095    public void unregisterForNvLoaded(Handler h) {
1096        mNvLoadedRegistrants.remove(h);
1097    }
1098
1099    public void registerForEriFileLoaded(Handler h, int what, Object obj) {
1100        Registrant r = new Registrant (h, what, obj);
1101        mEriFileLoadedRegistrants.add(r);
1102    }
1103
1104    public void unregisterForEriFileLoaded(Handler h) {
1105        mEriFileLoadedRegistrants.remove(h);
1106    }
1107
1108    // override for allowing access from other classes of this package
1109    /**
1110     * {@inheritDoc}
1111     */
1112    public final void setSystemProperty(String property, String value) {
1113        super.setSystemProperty(property, value);
1114    }
1115
1116    /**
1117     * {@inheritDoc}
1118     */
1119    public IccFileHandler getIccFileHandler() {
1120        return this.mIccFileHandler;
1121    }
1122
1123    /**
1124     * Set the TTY mode of the CDMAPhone
1125     */
1126    public void setTTYMode(int ttyMode, Message onComplete) {
1127        this.mCM.setTTYMode(ttyMode, onComplete);
1128    }
1129
1130    /**
1131     * Queries the TTY mode of the CDMAPhone
1132     */
1133    public void queryTTYMode(Message onComplete) {
1134        this.mCM.queryTTYMode(onComplete);
1135    }
1136
1137    /**
1138     * Activate or deactivate cell broadcast SMS.
1139     *
1140     * @param activate 0 = activate, 1 = deactivate
1141     * @param response Callback message is empty on completion
1142     */
1143    public void activateCellBroadcastSms(int activate, Message response) {
1144        mSMS.activateCellBroadcastSms(activate, response);
1145    }
1146
1147    /**
1148     * Query the current configuration of cdma cell broadcast SMS.
1149     *
1150     * @param response Callback message is empty on completion
1151     */
1152    public void getCellBroadcastSmsConfig(Message response) {
1153        mSMS.getCellBroadcastSmsConfig(response);
1154    }
1155
1156    /**
1157     * Configure cdma cell broadcast SMS.
1158     *
1159     * @param response Callback message is empty on completion
1160     */
1161    public void setCellBroadcastSmsConfig(int[] configValuesArray, Message response) {
1162        mSMS.setCellBroadcastConfig(configValuesArray, response);
1163    }
1164
1165    /**
1166     * Returns true if OTA Service Provisioning needs to be performed.
1167     */
1168    @Override
1169    public boolean needsOtaServiceProvisioning() {
1170        return mSST.getOtasp() != ServiceStateTracker.OTASP_NOT_NEEDED;
1171    }
1172
1173    private static final String IS683A_FEATURE_CODE = "*228";
1174    private static final int IS683A_FEATURE_CODE_NUM_DIGITS = 4;
1175    private static final int IS683A_SYS_SEL_CODE_NUM_DIGITS = 2;
1176    private static final int IS683A_SYS_SEL_CODE_OFFSET = 4;
1177
1178    private static final int IS683_CONST_800MHZ_A_BAND = 0;
1179    private static final int IS683_CONST_800MHZ_B_BAND = 1;
1180    private static final int IS683_CONST_1900MHZ_A_BLOCK = 2;
1181    private static final int IS683_CONST_1900MHZ_B_BLOCK = 3;
1182    private static final int IS683_CONST_1900MHZ_C_BLOCK = 4;
1183    private static final int IS683_CONST_1900MHZ_D_BLOCK = 5;
1184    private static final int IS683_CONST_1900MHZ_E_BLOCK = 6;
1185    private static final int IS683_CONST_1900MHZ_F_BLOCK = 7;
1186    private static final int INVALID_SYSTEM_SELECTION_CODE = -1;
1187
1188    private boolean isIs683OtaSpDialStr(String dialStr) {
1189        int sysSelCodeInt;
1190        boolean isOtaspDialString = false;
1191        int dialStrLen = dialStr.length();
1192
1193        if (dialStrLen == IS683A_FEATURE_CODE_NUM_DIGITS) {
1194            if (dialStr.equals(IS683A_FEATURE_CODE)) {
1195                isOtaspDialString = true;
1196            }
1197        } else {
1198            sysSelCodeInt = extractSelCodeFromOtaSpNum(dialStr);
1199            switch (sysSelCodeInt) {
1200                case IS683_CONST_800MHZ_A_BAND:
1201                case IS683_CONST_800MHZ_B_BAND:
1202                case IS683_CONST_1900MHZ_A_BLOCK:
1203                case IS683_CONST_1900MHZ_B_BLOCK:
1204                case IS683_CONST_1900MHZ_C_BLOCK:
1205                case IS683_CONST_1900MHZ_D_BLOCK:
1206                case IS683_CONST_1900MHZ_E_BLOCK:
1207                case IS683_CONST_1900MHZ_F_BLOCK:
1208                    isOtaspDialString = true;
1209                    break;
1210                default:
1211                    break;
1212            }
1213        }
1214        return isOtaspDialString;
1215    }
1216    /**
1217     * This function extracts the system selection code from the dial string.
1218     */
1219    private int extractSelCodeFromOtaSpNum(String dialStr) {
1220        int dialStrLen = dialStr.length();
1221        int sysSelCodeInt = INVALID_SYSTEM_SELECTION_CODE;
1222
1223        if ((dialStr.regionMatches(0, IS683A_FEATURE_CODE,
1224                                   0, IS683A_FEATURE_CODE_NUM_DIGITS)) &&
1225            (dialStrLen >= (IS683A_FEATURE_CODE_NUM_DIGITS +
1226                            IS683A_SYS_SEL_CODE_NUM_DIGITS))) {
1227                // Since we checked the condition above, the system selection code
1228                // extracted from dialStr will not cause any exception
1229                sysSelCodeInt = Integer.parseInt (
1230                                dialStr.substring (IS683A_FEATURE_CODE_NUM_DIGITS,
1231                                IS683A_FEATURE_CODE_NUM_DIGITS + IS683A_SYS_SEL_CODE_NUM_DIGITS));
1232        }
1233        if (DBG) Log.d(LOG_TAG, "extractSelCodeFromOtaSpNum " + sysSelCodeInt);
1234        return sysSelCodeInt;
1235    }
1236
1237    /**
1238     * This function checks if the system selection code extracted from
1239     * the dial string "sysSelCodeInt' is the system selection code specified
1240     * in the carrier ota sp number schema "sch".
1241     */
1242    private boolean
1243    checkOtaSpNumBasedOnSysSelCode (int sysSelCodeInt, String sch[]) {
1244        boolean isOtaSpNum = false;
1245        try {
1246            // Get how many number of system selection code ranges
1247            int selRc = Integer.parseInt((String)sch[1]);
1248            for (int i = 0; i < selRc; i++) {
1249                if (!TextUtils.isEmpty(sch[i+2]) && !TextUtils.isEmpty(sch[i+3])) {
1250                    int selMin = Integer.parseInt((String)sch[i+2]);
1251                    int selMax = Integer.parseInt((String)sch[i+3]);
1252                    // Check if the selection code extracted from the dial string falls
1253                    // within any of the range pairs specified in the schema.
1254                    if ((sysSelCodeInt >= selMin) && (sysSelCodeInt <= selMax)) {
1255                        isOtaSpNum = true;
1256                        break;
1257                    }
1258                }
1259            }
1260        } catch (NumberFormatException ex) {
1261            // If the carrier ota sp number schema is not correct, we still allow dial
1262            // and only log the error:
1263            Log.e(LOG_TAG, "checkOtaSpNumBasedOnSysSelCode, error", ex);
1264        }
1265        return isOtaSpNum;
1266    }
1267
1268    // Define the pattern/format for carrier specified OTASP number schema.
1269    // It separates by comma and/or whitespace.
1270    private static Pattern pOtaSpNumSchema = Pattern.compile("[,\\s]+");
1271
1272    /**
1273     * The following function checks if a dial string is a carrier specified
1274     * OTASP number or not by checking against the OTASP number schema stored
1275     * in PROPERTY_OTASP_NUM_SCHEMA.
1276     *
1277     * Currently, there are 2 schemas for carriers to specify the OTASP number:
1278     * 1) Use system selection code:
1279     *    The schema is:
1280     *    SELC,the # of code pairs,min1,max1,min2,max2,...
1281     *    e.g "SELC,3,10,20,30,40,60,70" indicates that there are 3 pairs of
1282     *    selection codes, and they are {10,20}, {30,40} and {60,70} respectively.
1283     *
1284     * 2) Use feature code:
1285     *    The schema is:
1286     *    "FC,length of feature code,feature code".
1287     *     e.g "FC,2,*2" indicates that the length of the feature code is 2,
1288     *     and the code itself is "*2".
1289     */
1290    private boolean isCarrierOtaSpNum(String dialStr) {
1291        boolean isOtaSpNum = false;
1292        int sysSelCodeInt = extractSelCodeFromOtaSpNum(dialStr);
1293        if (sysSelCodeInt == INVALID_SYSTEM_SELECTION_CODE) {
1294            return isOtaSpNum;
1295        }
1296        // mCarrierOtaSpNumSchema is retrieved from PROPERTY_OTASP_NUM_SCHEMA:
1297        if (!TextUtils.isEmpty(mCarrierOtaSpNumSchema)) {
1298            Matcher m = pOtaSpNumSchema.matcher(mCarrierOtaSpNumSchema);
1299            if (DBG) {
1300                Log.d(LOG_TAG, "isCarrierOtaSpNum,schema" + mCarrierOtaSpNumSchema);
1301            }
1302
1303            if (m.find()) {
1304                String sch[] = pOtaSpNumSchema.split(mCarrierOtaSpNumSchema);
1305                // If carrier uses system selection code mechanism
1306                if (!TextUtils.isEmpty(sch[0]) && sch[0].equals("SELC")) {
1307                    if (sysSelCodeInt!=INVALID_SYSTEM_SELECTION_CODE) {
1308                        isOtaSpNum=checkOtaSpNumBasedOnSysSelCode(sysSelCodeInt,sch);
1309                    } else {
1310                        if (DBG) {
1311                            Log.d(LOG_TAG, "isCarrierOtaSpNum,sysSelCodeInt is invalid");
1312                        }
1313                    }
1314                } else if (!TextUtils.isEmpty(sch[0]) && sch[0].equals("FC")) {
1315                    int fcLen =  Integer.parseInt((String)sch[1]);
1316                    String fc = (String)sch[2];
1317                    if (dialStr.regionMatches(0,fc,0,fcLen)) {
1318                        isOtaSpNum = true;
1319                    } else {
1320                        if (DBG) Log.d(LOG_TAG, "isCarrierOtaSpNum,not otasp number");
1321                    }
1322                } else {
1323                    if (DBG) {
1324                        Log.d(LOG_TAG, "isCarrierOtaSpNum,ota schema not supported" + sch[0]);
1325                    }
1326                }
1327            } else {
1328                if (DBG) {
1329                    Log.d(LOG_TAG, "isCarrierOtaSpNum,ota schema pattern not right" +
1330                          mCarrierOtaSpNumSchema);
1331                }
1332            }
1333        } else {
1334            if (DBG) Log.d(LOG_TAG, "isCarrierOtaSpNum,ota schema pattern empty");
1335        }
1336        return isOtaSpNum;
1337    }
1338
1339    /**
1340     * isOTASPNumber: checks a given number against the IS-683A OTASP dial string and carrier
1341     * OTASP dial string.
1342     *
1343     * @param dialStr the number to look up.
1344     * @return true if the number is in IS-683A OTASP dial string or carrier OTASP dial string
1345     */
1346    @Override
1347    public  boolean isOtaSpNumber(String dialStr){
1348        boolean isOtaSpNum = false;
1349        String dialableStr = PhoneNumberUtils.extractNetworkPortionAlt(dialStr);
1350        if (dialableStr != null) {
1351            isOtaSpNum = isIs683OtaSpDialStr(dialableStr);
1352            if (isOtaSpNum == false) {
1353                isOtaSpNum = isCarrierOtaSpNum(dialableStr);
1354            }
1355        }
1356        if (DBG) Log.d(LOG_TAG, "isOtaSpNumber " + isOtaSpNum);
1357        return isOtaSpNum;
1358    }
1359
1360    @Override
1361    public int getCdmaEriIconIndex() {
1362        return getServiceState().getCdmaEriIconIndex();
1363    }
1364
1365    /**
1366     * Returns the CDMA ERI icon mode,
1367     * 0 - ON
1368     * 1 - FLASHING
1369     */
1370    @Override
1371    public int getCdmaEriIconMode() {
1372        return getServiceState().getCdmaEriIconMode();
1373    }
1374
1375    /**
1376     * Returns the CDMA ERI text,
1377     */
1378    @Override
1379    public String getCdmaEriText() {
1380        int roamInd = getServiceState().getCdmaRoamingIndicator();
1381        int defRoamInd = getServiceState().getCdmaDefaultRoamingIndicator();
1382        return mEriManager.getCdmaEriText(roamInd, defRoamInd);
1383    }
1384
1385    /**
1386     * Store the voicemail number in preferences
1387     */
1388    private void storeVoiceMailNumber(String number) {
1389        // Update the preference value of voicemail number
1390        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
1391        SharedPreferences.Editor editor = sp.edit();
1392        editor.putString(VM_NUMBER_CDMA, number);
1393        editor.apply();
1394    }
1395
1396    /**
1397     * Sets PROPERTY_ICC_OPERATOR_ISO_COUNTRY property
1398     *
1399     */
1400    private void setIsoCountryProperty(String operatorNumeric) {
1401        if (TextUtils.isEmpty(operatorNumeric)) {
1402            setSystemProperty(PROPERTY_ICC_OPERATOR_ISO_COUNTRY, "");
1403        } else {
1404            String iso = "";
1405            try {
1406                iso = MccTable.countryCodeForMcc(Integer.parseInt(
1407                        operatorNumeric.substring(0,3)));
1408            } catch (NumberFormatException ex) {
1409                Log.w(LOG_TAG, "countryCodeForMcc error" + ex);
1410            } catch (StringIndexOutOfBoundsException ex) {
1411                Log.w(LOG_TAG, "countryCodeForMcc error" + ex);
1412            }
1413
1414            setSystemProperty(PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso);
1415        }
1416    }
1417
1418    /**
1419     * Sets the "current" field in the telephony provider according to the
1420     * build-time operator numeric property
1421     *
1422     * @return true for success; false otherwise.
1423     */
1424    boolean updateCurrentCarrierInProvider(String operatorNumeric) {
1425        if (!TextUtils.isEmpty(operatorNumeric)) {
1426            try {
1427                Uri uri = Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current");
1428                ContentValues map = new ContentValues();
1429                map.put(Telephony.Carriers.NUMERIC, operatorNumeric);
1430                getContext().getContentResolver().insert(uri, map);
1431
1432                // Updates MCC MNC device configuration information
1433                MccTable.updateMccMncConfiguration(this, operatorNumeric);
1434
1435                return true;
1436            } catch (SQLException e) {
1437                Log.e(LOG_TAG, "Can't store current operator", e);
1438            }
1439        }
1440        return false;
1441    }
1442}
1443