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