Home | History | Annotate | Download | only in gsm
      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 
     17 package com.android.internal.telephony.gsm;
     18 import android.content.Context;
     19 import android.os.AsyncResult;
     20 import android.os.Handler;
     21 import android.os.Looper;
     22 import android.os.Message;
     23 import android.os.PowerManager;
     24 import android.os.Registrant;
     25 import android.os.SystemClock;
     26 import android.telephony.Rlog;
     27 import android.telephony.PhoneNumberUtils;
     28 import android.telephony.ServiceState;
     29 import android.text.TextUtils;
     30 
     31 import com.android.internal.telephony.*;
     32 import com.android.internal.telephony.uicc.UiccCardApplication;
     33 import com.android.internal.telephony.uicc.UiccController;
     34 import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppState;
     35 
     36 /**
     37  * {@hide}
     38  */
     39 public class GsmConnection extends Connection {
     40     private static final String LOG_TAG = "GsmConnection";
     41     private static final boolean DBG = true;
     42 
     43     //***** Instance Variables
     44 
     45     GsmCallTracker mOwner;
     46     GsmCall mParent;
     47 
     48     String mAddress;     // MAY BE NULL!!!
     49     String mDialString;          // outgoing calls only
     50     String mPostDialString;      // outgoing calls only
     51     boolean mIsIncoming;
     52     boolean mDisconnected;
     53 
     54     int mIndex;          // index in GsmCallTracker.connections[], -1 if unassigned
     55                         // The GSM index is 1 + this
     56 
     57     /*
     58      * These time/timespan values are based on System.currentTimeMillis(),
     59      * i.e., "wall clock" time.
     60      */
     61     long mCreateTime;
     62     long mConnectTime;
     63     long mDisconnectTime;
     64 
     65     /*
     66      * These time/timespan values are based on SystemClock.elapsedRealTime(),
     67      * i.e., time since boot.  They are appropriate for comparison and
     68      * calculating deltas.
     69      */
     70     long mConnectTimeReal;
     71     long mDuration;
     72     long mHoldingStartTime;  // The time when the Connection last transitioned
     73                             // into HOLDING
     74 
     75     int mNextPostDialChar;       // index into postDialString
     76 
     77     DisconnectCause mCause = DisconnectCause.NOT_DISCONNECTED;
     78     PostDialState mPostDialState = PostDialState.NOT_STARTED;
     79     int mNumberPresentation = PhoneConstants.PRESENTATION_ALLOWED;
     80     UUSInfo mUusInfo;
     81 
     82     Handler mHandler;
     83 
     84     private PowerManager.WakeLock mPartialWakeLock;
     85 
     86     //***** Event Constants
     87     static final int EVENT_DTMF_DONE = 1;
     88     static final int EVENT_PAUSE_DONE = 2;
     89     static final int EVENT_NEXT_POST_DIAL = 3;
     90     static final int EVENT_WAKE_LOCK_TIMEOUT = 4;
     91 
     92     //***** Constants
     93     static final int PAUSE_DELAY_MILLIS = 3 * 1000;
     94     static final int WAKE_LOCK_TIMEOUT_MILLIS = 60*1000;
     95 
     96     //***** Inner Classes
     97 
     98     class MyHandler extends Handler {
     99         MyHandler(Looper l) {super(l);}
    100 
    101         @Override
    102         public void
    103         handleMessage(Message msg) {
    104 
    105             switch (msg.what) {
    106                 case EVENT_NEXT_POST_DIAL:
    107                 case EVENT_DTMF_DONE:
    108                 case EVENT_PAUSE_DONE:
    109                     processNextPostDialChar();
    110                     break;
    111                 case EVENT_WAKE_LOCK_TIMEOUT:
    112                     releaseWakeLock();
    113                     break;
    114             }
    115         }
    116     }
    117 
    118     //***** Constructors
    119 
    120     /** This is probably an MT call that we first saw in a CLCC response */
    121     /*package*/
    122     GsmConnection (Context context, DriverCall dc, GsmCallTracker ct, int index) {
    123         createWakeLock(context);
    124         acquireWakeLock();
    125 
    126         mOwner = ct;
    127         mHandler = new MyHandler(mOwner.getLooper());
    128 
    129         mAddress = dc.number;
    130 
    131         mIsIncoming = dc.isMT;
    132         mCreateTime = System.currentTimeMillis();
    133         mCnapName = dc.name;
    134         mCnapNamePresentation = dc.namePresentation;
    135         mNumberPresentation = dc.numberPresentation;
    136         mUusInfo = dc.uusInfo;
    137 
    138         mIndex = index;
    139 
    140         mParent = parentFromDCState (dc.state);
    141         mParent.attach(this, dc);
    142     }
    143 
    144     /** This is an MO call, created when dialing */
    145     /*package*/
    146     GsmConnection (Context context, String dialString, GsmCallTracker ct, GsmCall parent) {
    147         createWakeLock(context);
    148         acquireWakeLock();
    149 
    150         mOwner = ct;
    151         mHandler = new MyHandler(mOwner.getLooper());
    152 
    153         mDialString = dialString;
    154 
    155         mAddress = PhoneNumberUtils.extractNetworkPortionAlt(dialString);
    156         mPostDialString = PhoneNumberUtils.extractPostDialPortion(dialString);
    157 
    158         mIndex = -1;
    159 
    160         mIsIncoming = false;
    161         mCnapName = null;
    162         mCnapNamePresentation = PhoneConstants.PRESENTATION_ALLOWED;
    163         mNumberPresentation = PhoneConstants.PRESENTATION_ALLOWED;
    164         mCreateTime = System.currentTimeMillis();
    165 
    166         mParent = parent;
    167         parent.attachFake(this, GsmCall.State.DIALING);
    168     }
    169 
    170     public void dispose() {
    171     }
    172 
    173     static boolean
    174     equalsHandlesNulls (Object a, Object b) {
    175         return (a == null) ? (b == null) : a.equals (b);
    176     }
    177 
    178     /*package*/ boolean
    179     compareTo(DriverCall c) {
    180         // On mobile originated (MO) calls, the phone number may have changed
    181         // due to a SIM Toolkit call control modification.
    182         //
    183         // We assume we know when MO calls are created (since we created them)
    184         // and therefore don't need to compare the phone number anyway.
    185         if (! (mIsIncoming || c.isMT)) return true;
    186 
    187         // ... but we can compare phone numbers on MT calls, and we have
    188         // no control over when they begin, so we might as well
    189 
    190         String cAddress = PhoneNumberUtils.stringFromStringAndTOA(c.number, c.TOA);
    191         return mIsIncoming == c.isMT && equalsHandlesNulls(mAddress, cAddress);
    192     }
    193 
    194     @Override
    195     public String getAddress() {
    196         return mAddress;
    197     }
    198 
    199     @Override
    200     public GsmCall getCall() {
    201         return mParent;
    202     }
    203 
    204     @Override
    205     public long getCreateTime() {
    206         return mCreateTime;
    207     }
    208 
    209     @Override
    210     public long getConnectTime() {
    211         return mConnectTime;
    212     }
    213 
    214     @Override
    215     public long getDisconnectTime() {
    216         return mDisconnectTime;
    217     }
    218 
    219     @Override
    220     public long getDurationMillis() {
    221         if (mConnectTimeReal == 0) {
    222             return 0;
    223         } else if (mDuration == 0) {
    224             return SystemClock.elapsedRealtime() - mConnectTimeReal;
    225         } else {
    226             return mDuration;
    227         }
    228     }
    229 
    230     @Override
    231     public long getHoldDurationMillis() {
    232         if (getState() != GsmCall.State.HOLDING) {
    233             // If not holding, return 0
    234             return 0;
    235         } else {
    236             return SystemClock.elapsedRealtime() - mHoldingStartTime;
    237         }
    238     }
    239 
    240     @Override
    241     public DisconnectCause getDisconnectCause() {
    242         return mCause;
    243     }
    244 
    245     @Override
    246     public boolean isIncoming() {
    247         return mIsIncoming;
    248     }
    249 
    250     @Override
    251     public GsmCall.State getState() {
    252         if (mDisconnected) {
    253             return GsmCall.State.DISCONNECTED;
    254         } else {
    255             return super.getState();
    256         }
    257     }
    258 
    259     @Override
    260     public void hangup() throws CallStateException {
    261         if (!mDisconnected) {
    262             mOwner.hangup(this);
    263         } else {
    264             throw new CallStateException ("disconnected");
    265         }
    266     }
    267 
    268     @Override
    269     public void separate() throws CallStateException {
    270         if (!mDisconnected) {
    271             mOwner.separate(this);
    272         } else {
    273             throw new CallStateException ("disconnected");
    274         }
    275     }
    276 
    277     @Override
    278     public PostDialState getPostDialState() {
    279         return mPostDialState;
    280     }
    281 
    282     @Override
    283     public void proceedAfterWaitChar() {
    284         if (mPostDialState != PostDialState.WAIT) {
    285             Rlog.w(LOG_TAG, "GsmConnection.proceedAfterWaitChar(): Expected "
    286                 + "getPostDialState() to be WAIT but was " + mPostDialState);
    287             return;
    288         }
    289 
    290         setPostDialState(PostDialState.STARTED);
    291 
    292         processNextPostDialChar();
    293     }
    294 
    295     @Override
    296     public void proceedAfterWildChar(String str) {
    297         if (mPostDialState != PostDialState.WILD) {
    298             Rlog.w(LOG_TAG, "GsmConnection.proceedAfterWaitChar(): Expected "
    299                 + "getPostDialState() to be WILD but was " + mPostDialState);
    300             return;
    301         }
    302 
    303         setPostDialState(PostDialState.STARTED);
    304 
    305         // make a new postDialString, with the wild char replacement string
    306         // at the beginning, followed by the remaining postDialString.
    307 
    308         StringBuilder buf = new StringBuilder(str);
    309         buf.append(mPostDialString.substring(mNextPostDialChar));
    310         mPostDialString = buf.toString();
    311         mNextPostDialChar = 0;
    312         if (Phone.DEBUG_PHONE) {
    313             log("proceedAfterWildChar: new postDialString is " +
    314                     mPostDialString);
    315         }
    316 
    317         processNextPostDialChar();
    318     }
    319 
    320     @Override
    321     public void cancelPostDial() {
    322         setPostDialState(PostDialState.CANCELLED);
    323     }
    324 
    325     /**
    326      * Called when this Connection is being hung up locally (eg, user pressed "end")
    327      * Note that at this point, the hangup request has been dispatched to the radio
    328      * but no response has yet been received so update() has not yet been called
    329      */
    330     void
    331     onHangupLocal() {
    332         mCause = DisconnectCause.LOCAL;
    333     }
    334 
    335     DisconnectCause
    336     disconnectCauseFromCode(int causeCode) {
    337         /**
    338          * See 22.001 Annex F.4 for mapping of cause codes
    339          * to local tones
    340          */
    341 
    342         switch (causeCode) {
    343             case CallFailCause.USER_BUSY:
    344                 return DisconnectCause.BUSY;
    345 
    346             case CallFailCause.NO_CIRCUIT_AVAIL:
    347             case CallFailCause.TEMPORARY_FAILURE:
    348             case CallFailCause.SWITCHING_CONGESTION:
    349             case CallFailCause.CHANNEL_NOT_AVAIL:
    350             case CallFailCause.QOS_NOT_AVAIL:
    351             case CallFailCause.BEARER_NOT_AVAIL:
    352                 return DisconnectCause.CONGESTION;
    353 
    354             case CallFailCause.ACM_LIMIT_EXCEEDED:
    355                 return DisconnectCause.LIMIT_EXCEEDED;
    356 
    357             case CallFailCause.CALL_BARRED:
    358                 return DisconnectCause.CALL_BARRED;
    359 
    360             case CallFailCause.FDN_BLOCKED:
    361                 return DisconnectCause.FDN_BLOCKED;
    362 
    363             case CallFailCause.UNOBTAINABLE_NUMBER:
    364                 return DisconnectCause.UNOBTAINABLE_NUMBER;
    365 
    366             case CallFailCause.ERROR_UNSPECIFIED:
    367             case CallFailCause.NORMAL_CLEARING:
    368             default:
    369                 GSMPhone phone = mOwner.mPhone;
    370                 int serviceState = phone.getServiceState().getState();
    371                 UiccCardApplication cardApp = UiccController
    372                         .getInstance()
    373                         .getUiccCardApplication(UiccController.APP_FAM_3GPP);
    374                 AppState uiccAppState = (cardApp != null) ? cardApp.getState() :
    375                                                             AppState.APPSTATE_UNKNOWN;
    376                 if (serviceState == ServiceState.STATE_POWER_OFF) {
    377                     return DisconnectCause.POWER_OFF;
    378                 } else if (serviceState == ServiceState.STATE_OUT_OF_SERVICE
    379                         || serviceState == ServiceState.STATE_EMERGENCY_ONLY ) {
    380                     return DisconnectCause.OUT_OF_SERVICE;
    381                 } else if (uiccAppState != AppState.APPSTATE_READY) {
    382                     return DisconnectCause.ICC_ERROR;
    383                 } else if (causeCode == CallFailCause.ERROR_UNSPECIFIED) {
    384                     if (phone.mSST.mRestrictedState.isCsRestricted()) {
    385                         return DisconnectCause.CS_RESTRICTED;
    386                     } else if (phone.mSST.mRestrictedState.isCsEmergencyRestricted()) {
    387                         return DisconnectCause.CS_RESTRICTED_EMERGENCY;
    388                     } else if (phone.mSST.mRestrictedState.isCsNormalRestricted()) {
    389                         return DisconnectCause.CS_RESTRICTED_NORMAL;
    390                     } else {
    391                         return DisconnectCause.ERROR_UNSPECIFIED;
    392                     }
    393                 } else if (causeCode == CallFailCause.NORMAL_CLEARING) {
    394                     return DisconnectCause.NORMAL;
    395                 } else {
    396                     // If nothing else matches, report unknown call drop reason
    397                     // to app, not NORMAL call end.
    398                     return DisconnectCause.ERROR_UNSPECIFIED;
    399                 }
    400         }
    401     }
    402 
    403     /*package*/ void
    404     onRemoteDisconnect(int causeCode) {
    405         onDisconnect(disconnectCauseFromCode(causeCode));
    406     }
    407 
    408     /** Called when the radio indicates the connection has been disconnected */
    409     /*package*/ void
    410     onDisconnect(DisconnectCause cause) {
    411         mCause = cause;
    412 
    413         if (!mDisconnected) {
    414             mIndex = -1;
    415 
    416             mDisconnectTime = System.currentTimeMillis();
    417             mDuration = SystemClock.elapsedRealtime() - mConnectTimeReal;
    418             mDisconnected = true;
    419 
    420             if (DBG) Rlog.d(LOG_TAG, "onDisconnect: cause=" + cause);
    421 
    422             mOwner.mPhone.notifyDisconnect(this);
    423 
    424             if (mParent != null) {
    425                 mParent.connectionDisconnected(this);
    426             }
    427         }
    428         releaseWakeLock();
    429     }
    430 
    431     // Returns true if state has changed, false if nothing changed
    432     /*package*/ boolean
    433     update (DriverCall dc) {
    434         GsmCall newParent;
    435         boolean changed = false;
    436         boolean wasConnectingInOrOut = isConnectingInOrOut();
    437         boolean wasHolding = (getState() == GsmCall.State.HOLDING);
    438 
    439         newParent = parentFromDCState(dc.state);
    440 
    441         if (!equalsHandlesNulls(mAddress, dc.number)) {
    442             if (Phone.DEBUG_PHONE) log("update: phone # changed!");
    443             mAddress = dc.number;
    444             changed = true;
    445         }
    446 
    447         // A null cnapName should be the same as ""
    448         if (TextUtils.isEmpty(dc.name)) {
    449             if (!TextUtils.isEmpty(mCnapName)) {
    450                 changed = true;
    451                 mCnapName = "";
    452             }
    453         } else if (!dc.name.equals(mCnapName)) {
    454             changed = true;
    455             mCnapName = dc.name;
    456         }
    457 
    458         if (Phone.DEBUG_PHONE) log("--dssds----"+mCnapName);
    459         mCnapNamePresentation = dc.namePresentation;
    460         mNumberPresentation = dc.numberPresentation;
    461 
    462         if (newParent != mParent) {
    463             if (mParent != null) {
    464                 mParent.detach(this);
    465             }
    466             newParent.attach(this, dc);
    467             mParent = newParent;
    468             changed = true;
    469         } else {
    470             boolean parentStateChange;
    471             parentStateChange = mParent.update (this, dc);
    472             changed = changed || parentStateChange;
    473         }
    474 
    475         /** Some state-transition events */
    476 
    477         if (Phone.DEBUG_PHONE) log(
    478                 "update: parent=" + mParent +
    479                 ", hasNewParent=" + (newParent != mParent) +
    480                 ", wasConnectingInOrOut=" + wasConnectingInOrOut +
    481                 ", wasHolding=" + wasHolding +
    482                 ", isConnectingInOrOut=" + isConnectingInOrOut() +
    483                 ", changed=" + changed);
    484 
    485 
    486         if (wasConnectingInOrOut && !isConnectingInOrOut()) {
    487             onConnectedInOrOut();
    488         }
    489 
    490         if (changed && !wasHolding && (getState() == GsmCall.State.HOLDING)) {
    491             // We've transitioned into HOLDING
    492             onStartedHolding();
    493         }
    494 
    495         return changed;
    496     }
    497 
    498     /**
    499      * Called when this Connection is in the foregroundCall
    500      * when a dial is initiated.
    501      * We know we're ACTIVE, and we know we're going to end up
    502      * HOLDING in the backgroundCall
    503      */
    504     void
    505     fakeHoldBeforeDial() {
    506         if (mParent != null) {
    507             mParent.detach(this);
    508         }
    509 
    510         mParent = mOwner.mBackgroundCall;
    511         mParent.attachFake(this, GsmCall.State.HOLDING);
    512 
    513         onStartedHolding();
    514     }
    515 
    516     /*package*/ int
    517     getGSMIndex() throws CallStateException {
    518         if (mIndex >= 0) {
    519             return mIndex + 1;
    520         } else {
    521             throw new CallStateException ("GSM index not yet assigned");
    522         }
    523     }
    524 
    525     /**
    526      * An incoming or outgoing call has connected
    527      */
    528     void
    529     onConnectedInOrOut() {
    530         mConnectTime = System.currentTimeMillis();
    531         mConnectTimeReal = SystemClock.elapsedRealtime();
    532         mDuration = 0;
    533 
    534         // bug #678474: incoming call interpreted as missed call, even though
    535         // it sounds like the user has picked up the call.
    536         if (Phone.DEBUG_PHONE) {
    537             log("onConnectedInOrOut: connectTime=" + mConnectTime);
    538         }
    539 
    540         if (!mIsIncoming) {
    541             // outgoing calls only
    542             processNextPostDialChar();
    543         }
    544         releaseWakeLock();
    545     }
    546 
    547     /*package*/ void
    548     onStartedHolding() {
    549         mHoldingStartTime = SystemClock.elapsedRealtime();
    550     }
    551     /**
    552      * Performs the appropriate action for a post-dial char, but does not
    553      * notify application. returns false if the character is invalid and
    554      * should be ignored
    555      */
    556     private boolean
    557     processPostDialChar(char c) {
    558         if (PhoneNumberUtils.is12Key(c)) {
    559             mOwner.mCi.sendDtmf(c, mHandler.obtainMessage(EVENT_DTMF_DONE));
    560         } else if (c == PhoneNumberUtils.PAUSE) {
    561             // From TS 22.101:
    562             // It continues...
    563             // Upon the called party answering the UE shall send the DTMF digits
    564             // automatically to the network after a delay of 3 seconds( 20 ).
    565             // The digits shall be sent according to the procedures and timing
    566             // specified in 3GPP TS 24.008 [13]. The first occurrence of the
    567             // "DTMF Control Digits Separator" shall be used by the ME to
    568             // distinguish between the addressing digits (i.e. the phone number)
    569             // and the DTMF digits. Upon subsequent occurrences of the
    570             // separator,
    571             // the UE shall pause again for 3 seconds ( 20 ) before sending
    572             // any further DTMF digits.
    573             mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_PAUSE_DONE),
    574                     PAUSE_DELAY_MILLIS);
    575         } else if (c == PhoneNumberUtils.WAIT) {
    576             setPostDialState(PostDialState.WAIT);
    577         } else if (c == PhoneNumberUtils.WILD) {
    578             setPostDialState(PostDialState.WILD);
    579         } else {
    580             return false;
    581         }
    582 
    583         return true;
    584     }
    585 
    586     @Override
    587     public String
    588     getRemainingPostDialString() {
    589         if (mPostDialState == PostDialState.CANCELLED
    590             || mPostDialState == PostDialState.COMPLETE
    591             || mPostDialString == null
    592             || mPostDialString.length() <= mNextPostDialChar
    593         ) {
    594             return "";
    595         }
    596 
    597         return mPostDialString.substring(mNextPostDialChar);
    598     }
    599 
    600     @Override
    601     protected void finalize()
    602     {
    603         /**
    604          * It is understood that This finializer is not guaranteed
    605          * to be called and the release lock call is here just in
    606          * case there is some path that doesn't call onDisconnect
    607          * and or onConnectedInOrOut.
    608          */
    609         if (mPartialWakeLock.isHeld()) {
    610             Rlog.e(LOG_TAG, "[GSMConn] UNEXPECTED; mPartialWakeLock is held when finalizing.");
    611         }
    612         releaseWakeLock();
    613     }
    614 
    615     private void
    616     processNextPostDialChar() {
    617         char c = 0;
    618         Registrant postDialHandler;
    619 
    620         if (mPostDialState == PostDialState.CANCELLED) {
    621             //Rlog.v("GSM", "##### processNextPostDialChar: postDialState == CANCELLED, bail");
    622             return;
    623         }
    624 
    625         if (mPostDialString == null ||
    626                 mPostDialString.length() <= mNextPostDialChar) {
    627             setPostDialState(PostDialState.COMPLETE);
    628 
    629             // notifyMessage.arg1 is 0 on complete
    630             c = 0;
    631         } else {
    632             boolean isValid;
    633 
    634             setPostDialState(PostDialState.STARTED);
    635 
    636             c = mPostDialString.charAt(mNextPostDialChar++);
    637 
    638             isValid = processPostDialChar(c);
    639 
    640             if (!isValid) {
    641                 // Will call processNextPostDialChar
    642                 mHandler.obtainMessage(EVENT_NEXT_POST_DIAL).sendToTarget();
    643                 // Don't notify application
    644                 Rlog.e("GSM", "processNextPostDialChar: c=" + c + " isn't valid!");
    645                 return;
    646             }
    647         }
    648 
    649         postDialHandler = mOwner.mPhone.mPostDialHandler;
    650 
    651         Message notifyMessage;
    652 
    653         if (postDialHandler != null
    654                 && (notifyMessage = postDialHandler.messageForRegistrant()) != null) {
    655             // The AsyncResult.result is the Connection object
    656             PostDialState state = mPostDialState;
    657             AsyncResult ar = AsyncResult.forMessage(notifyMessage);
    658             ar.result = this;
    659             ar.userObj = state;
    660 
    661             // arg1 is the character that was/is being processed
    662             notifyMessage.arg1 = c;
    663 
    664             //Rlog.v("GSM", "##### processNextPostDialChar: send msg to postDialHandler, arg1=" + c);
    665             notifyMessage.sendToTarget();
    666         }
    667     }
    668 
    669 
    670     /** "connecting" means "has never been ACTIVE" for both incoming
    671      *  and outgoing calls
    672      */
    673     private boolean
    674     isConnectingInOrOut() {
    675         return mParent == null || mParent == mOwner.mRingingCall
    676             || mParent.mState == GsmCall.State.DIALING
    677             || mParent.mState == GsmCall.State.ALERTING;
    678     }
    679 
    680     private GsmCall
    681     parentFromDCState (DriverCall.State state) {
    682         switch (state) {
    683             case ACTIVE:
    684             case DIALING:
    685             case ALERTING:
    686                 return mOwner.mForegroundCall;
    687             //break;
    688 
    689             case HOLDING:
    690                 return mOwner.mBackgroundCall;
    691             //break;
    692 
    693             case INCOMING:
    694             case WAITING:
    695                 return mOwner.mRingingCall;
    696             //break;
    697 
    698             default:
    699                 throw new RuntimeException("illegal call state: " + state);
    700         }
    701     }
    702 
    703     /**
    704      * Set post dial state and acquire wake lock while switching to "started"
    705      * state, the wake lock will be released if state switches out of "started"
    706      * state or after WAKE_LOCK_TIMEOUT_MILLIS.
    707      * @param s new PostDialState
    708      */
    709     private void setPostDialState(PostDialState s) {
    710         if (mPostDialState != PostDialState.STARTED
    711                 && s == PostDialState.STARTED) {
    712             acquireWakeLock();
    713             Message msg = mHandler.obtainMessage(EVENT_WAKE_LOCK_TIMEOUT);
    714             mHandler.sendMessageDelayed(msg, WAKE_LOCK_TIMEOUT_MILLIS);
    715         } else if (mPostDialState == PostDialState.STARTED
    716                 && s != PostDialState.STARTED) {
    717             mHandler.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
    718             releaseWakeLock();
    719         }
    720         mPostDialState = s;
    721     }
    722 
    723     private void
    724     createWakeLock(Context context) {
    725         PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    726         mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOG_TAG);
    727     }
    728 
    729     private void
    730     acquireWakeLock() {
    731         log("acquireWakeLock");
    732         mPartialWakeLock.acquire();
    733     }
    734 
    735     private void
    736     releaseWakeLock() {
    737         synchronized(mPartialWakeLock) {
    738             if (mPartialWakeLock.isHeld()) {
    739                 log("releaseWakeLock");
    740                 mPartialWakeLock.release();
    741             }
    742         }
    743     }
    744 
    745     private void log(String msg) {
    746         Rlog.d(LOG_TAG, "[GSMConn] " + msg);
    747     }
    748 
    749     @Override
    750     public int getNumberPresentation() {
    751         return mNumberPresentation;
    752     }
    753 
    754     @Override
    755     public UUSInfo getUUSInfo() {
    756         return mUusInfo;
    757     }
    758 }
    759