InCallPresenter.java revision 86a4e32687a12f50f877a85a6764d6d03f55aff7
1/* 2 * Copyright (C) 2013 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.incallui; 18 19import com.android.incallui.service.PhoneNumberService; 20import com.google.common.collect.Sets; 21import com.google.common.base.Preconditions; 22 23import android.content.Context; 24import android.content.Intent; 25 26import com.android.services.telephony.common.Call; 27import com.android.services.telephony.common.Call.Capabilities; 28import com.google.common.collect.Lists; 29 30import java.util.ArrayList; 31import java.util.Set; 32 33/** 34 * Takes updates from the CallList and notifies the InCallActivity (UI) 35 * of the changes. 36 * Responsible for starting the activity for a new call and finishing the activity when all calls 37 * are disconnected. 38 * Creates and manages the in-call state and provides a listener pattern for the presenters 39 * that want to listen in on the in-call state changes. 40 * TODO: This class has become more of a state machine at this point. Consider renaming. 41 */ 42public class InCallPresenter implements CallList.Listener { 43 44 private static InCallPresenter sInCallPresenter; 45 46 private final Set<InCallStateListener> mListeners = Sets.newHashSet(); 47 private final ArrayList<IncomingCallListener> mIncomingCallListeners = Lists.newArrayList(); 48 49 private AudioModeProvider mAudioModeProvider; 50 private StatusBarNotifier mStatusBarNotifier; 51 private ContactInfoCache mContactInfoCache; 52 private Context mContext; 53 private CallList mCallList; 54 private InCallActivity mInCallActivity; 55 private InCallState mInCallState = InCallState.NO_CALLS; 56 private ProximitySensor mProximitySensor; 57 private boolean mServiceConnected = false; 58 59 /** 60 * Is true when the activity has been previously started. Some code needs to know not just if 61 * the activity is currently up, but if it had been previously shown in foreground for this 62 * in-call session (e.g., StatusBarNotifier). This gets reset when the session ends in the 63 * tear-down method. 64 */ 65 private boolean mIsActivityPreviouslyStarted = false; 66 67 public static synchronized InCallPresenter getInstance() { 68 if (sInCallPresenter == null) { 69 sInCallPresenter = new InCallPresenter(); 70 } 71 return sInCallPresenter; 72 } 73 74 public InCallState getInCallState() { 75 return mInCallState; 76 } 77 78 public CallList getCallList() { 79 return mCallList; 80 } 81 82 public void setUp(Context context, CallList callList, AudioModeProvider audioModeProvider) { 83 if (mServiceConnected) { 84 Log.i(this, "New service connection replacing existing one."); 85 // retain the current resources, no need to create new ones. 86 Preconditions.checkState(context == mContext); 87 Preconditions.checkState(callList == mCallList); 88 Preconditions.checkState(audioModeProvider == mAudioModeProvider); 89 return; 90 } 91 92 Preconditions.checkNotNull(context); 93 mContext = context; 94 95 mContactInfoCache = ContactInfoCache.getInstance(context); 96 97 mStatusBarNotifier = new StatusBarNotifier(context, mContactInfoCache, mCallList); 98 addListener(mStatusBarNotifier); 99 100 mAudioModeProvider = audioModeProvider; 101 102 mProximitySensor = new ProximitySensor(context, mAudioModeProvider); 103 addListener(mProximitySensor); 104 105 mCallList = callList; 106 107 // This only gets called by the service so this is okay. 108 mServiceConnected = true; 109 110 // The final thing we do in this set up is add ourselves as a listener to CallList. This 111 // will kick off an update and the whole process can start. 112 mCallList.addListener(this); 113 114 Log.d(this, "Finished InCallPresenter.setUp"); 115 } 116 117 /** 118 * Called when the telephony service has disconnected from us. This will happen when there are 119 * no more active calls. However, we may still want to continue showing the UI for 120 * certain cases like showing "Call Ended". 121 * What we really want is to wait for the activity and the service to both disconnect before we 122 * tear things down. This method sets a serviceConnected boolean and calls a secondary method 123 * that performs the aforementioned logic. 124 */ 125 public void tearDown() { 126 Log.d(this, "tearDown"); 127 mServiceConnected = false; 128 attemptCleanup(); 129 } 130 131 private void attemptFinishActivity() { 132 final boolean doFinish = (mInCallActivity != null && isActivityStarted()); 133 Log.i(this, "Hide in call UI: " + doFinish); 134 135 if (doFinish) { 136 mInCallActivity.finish(); 137 } 138 } 139 140 /** 141 * Called when the UI begins or ends. Starts the callstate callbacks if the UI just began. 142 * Attempts to tear down everything if the UI just ended. See #tearDown for more insight on 143 * the tear-down process. 144 */ 145 public void setActivity(InCallActivity inCallActivity) { 146 boolean updateListeners = false; 147 boolean doAttemptCleanup = false; 148 149 if (inCallActivity != null) { 150 if (mInCallActivity == null) { 151 updateListeners = true; 152 Log.i(this, "UI Initialized"); 153 } else if (mInCallActivity != inCallActivity) { 154 Log.wtf(this, "Setting a second activity before destroying the first."); 155 } else { 156 // since setActivity is called onStart(), it can be called multiple times. 157 // This is fine and ignorable, but we do not want to update the world every time 158 // this happens (like going to/from background) so we do not set updateListeners. 159 } 160 161 mInCallActivity = inCallActivity; 162 163 // By the time the UI finally comes up, the call may already be disconnected. 164 // If that's the case, we may need to show an error dialog. 165 if (mCallList != null && mCallList.getDisconnectedCall() != null) { 166 maybeShowErrorDialogOnDisconnect(mCallList.getDisconnectedCall()); 167 } 168 169 // When the UI comes up, we need to first check the in-call state. 170 // If we are showing NO_CALLS, that means that a call probably connected and 171 // then immediately disconnected before the UI was able to come up. 172 // If we dont have any calls, start tearing down the UI instead. 173 // NOTE: This code relies on {@link #mInCallActivity} being set so we run it after 174 // it has been set. 175 if (mInCallState == InCallState.NO_CALLS) { 176 Log.i(this, "UI Intialized, but no calls left. shut down."); 177 attemptFinishActivity(); 178 return; 179 } 180 } else { 181 Log.i(this, "UI Destroyed)"); 182 updateListeners = true; 183 mInCallActivity = null; 184 185 // We attempt cleanup for the destroy case but only after we recalculate the state 186 // to see if we need to come back up or stay shut down. This is why we do the cleanup 187 // after the call to onCallListChange() instead of directly here. 188 doAttemptCleanup = true; 189 } 190 191 // Messages can come from the telephony layer while the activity is coming up 192 // and while the activity is going down. So in both cases we need to recalculate what 193 // state we should be in after they complete. 194 // Examples: (1) A new incoming call could come in and then get disconnected before 195 // the activity is created. 196 // (2) All calls could disconnect and then get a new incoming call before the 197 // activity is destroyed. 198 // 199 // b/1122139 - We previously had a check for mServiceConnected here as well, but there are 200 // cases where we need to recalculate the current state even if the service in not 201 // connected. In particular the case where startOrFinish() is called while the app is 202 // already finish()ing. In that case, we skip updating the state with the knowledge that 203 // we will check again once the activity has finished. That means we have to recalculate the 204 // state here even if the service is disconnected since we may not have finished a state 205 // transition while finish()ing. 206 if (updateListeners) { 207 onCallListChange(mCallList); 208 } 209 210 if (doAttemptCleanup) { 211 attemptCleanup(); 212 } 213 } 214 215 /** 216 * Called when there is a change to the call list. 217 * Sets the In-Call state for the entire in-call app based on the information it gets from 218 * CallList. Dispatches the in-call state to all listeners. Can trigger the creation or 219 * destruction of the UI based on the states that is calculates. 220 */ 221 @Override 222 public void onCallListChange(CallList callList) { 223 if (callList == null) { 224 return; 225 } 226 InCallState newState = getPotentialStateFromCallList(callList); 227 newState = startOrFinishUi(newState); 228 229 // Renable notification shade and soft navigation buttons, if we are no longer in the 230 // incoming call screen 231 if (!newState.isIncoming()) { 232 CallCommandClient.getInstance().setSystemBarNavigationEnabled(true); 233 } 234 235 // Set the new state before announcing it to the world 236 Log.i(this, "Phone switching state: " + mInCallState + " -> " + newState); 237 mInCallState = newState; 238 239 // notify listeners of new state 240 for (InCallStateListener listener : mListeners) { 241 Log.d(this, "Notify " + listener + " of state " + mInCallState.toString()); 242 listener.onStateChange(mInCallState, callList); 243 } 244 } 245 246 /** 247 * Called when there is a new incoming call. 248 * 249 * @param call 250 */ 251 @Override 252 public void onIncomingCall(Call call) { 253 InCallState newState = startOrFinishUi(InCallState.INCOMING); 254 255 Log.i(this, "Phone switching state: " + mInCallState + " -> " + newState); 256 mInCallState = newState; 257 258 // Disable notification shade and soft navigation buttons 259 if (newState.isIncoming()) { 260 CallCommandClient.getInstance().setSystemBarNavigationEnabled(false); 261 } 262 263 for (IncomingCallListener listener : mIncomingCallListeners) { 264 listener.onIncomingCall(mInCallState, call); 265 } 266 } 267 268 /** 269 * Called when a call becomes disconnected. Called everytime an existing call 270 * changes from being connected (incoming/outgoing/active) to disconnected. 271 */ 272 @Override 273 public void onDisconnect(Call call) { 274 hideDialpadForDisconnect(); 275 maybeShowErrorDialogOnDisconnect(call); 276 277 // We need to do the run the same code as onCallListChange. 278 onCallListChange(CallList.getInstance()); 279 } 280 281 /** 282 * Given the call list, return the state in which the in-call screen should be. 283 */ 284 public static InCallState getPotentialStateFromCallList(CallList callList) { 285 286 InCallState newState = InCallState.NO_CALLS; 287 288 if (callList == null) { 289 return newState; 290 } 291 if (callList.getIncomingCall() != null) { 292 newState = InCallState.INCOMING; 293 } else if (callList.getOutgoingCall() != null) { 294 newState = InCallState.OUTGOING; 295 } else if (callList.getActiveCall() != null || 296 callList.getBackgroundCall() != null || 297 callList.getDisconnectedCall() != null || 298 callList.getDisconnectingCall() != null) { 299 newState = InCallState.INCALL; 300 } 301 302 return newState; 303 } 304 305 public void addIncomingCallListener(IncomingCallListener listener) { 306 Preconditions.checkNotNull(listener); 307 mIncomingCallListeners.add(listener); 308 } 309 310 public void removeIncomingCallListener(IncomingCallListener listener) { 311 Preconditions.checkNotNull(listener); 312 mIncomingCallListeners.remove(listener); 313 } 314 315 public void addListener(InCallStateListener listener) { 316 Preconditions.checkNotNull(listener); 317 mListeners.add(listener); 318 } 319 320 public void removeListener(InCallStateListener listener) { 321 Preconditions.checkNotNull(listener); 322 mListeners.remove(listener); 323 } 324 325 public AudioModeProvider getAudioModeProvider() { 326 return mAudioModeProvider; 327 } 328 329 public ContactInfoCache getContactInfoCache() { 330 return mContactInfoCache; 331 } 332 333 public ProximitySensor getProximitySensor() { 334 return mProximitySensor; 335 } 336 337 /** 338 * Hangs up any active or outgoing calls. 339 */ 340 public void hangUpOngoingCall(Context context) { 341 // By the time we receive this intent, we could be shut down and call list 342 // could be null. Bail in those cases. 343 if (mCallList == null) { 344 if (mStatusBarNotifier == null) { 345 // The In Call UI has crashed but the notification still stayed up. We should not 346 // come to this stage. 347 StatusBarNotifier.clearInCallNotification(context); 348 } 349 return; 350 } 351 352 Call call = mCallList.getOutgoingCall(); 353 if (call == null) { 354 call = mCallList.getActiveOrBackgroundCall(); 355 } 356 357 if (call != null) { 358 CallCommandClient.getInstance().disconnectCall(call.getCallId()); 359 } 360 } 361 362 /** 363 * Returns true if the incall app is the foreground application. 364 */ 365 public boolean isShowingInCallUi() { 366 return (isActivityStarted() && mInCallActivity.isForegroundActivity()); 367 } 368 369 /** 370 * Returns true of the activity has been created and is running. 371 * Returns true as long as activity is not destroyed or finishing. This ensures that we return 372 * true even if the activity is paused (not in foreground). 373 */ 374 public boolean isActivityStarted() { 375 return (mInCallActivity != null && 376 !mInCallActivity.isDestroyed() && 377 !mInCallActivity.isFinishing()); 378 } 379 380 public boolean isActivityPreviouslyStarted() { 381 return mIsActivityPreviouslyStarted; 382 } 383 384 /** 385 * Called when the activity goes in/out of the foreground. 386 */ 387 public void onUiShowing(boolean showing) { 388 // We need to update the notification bar when we leave the UI because that 389 // could trigger it to show again. 390 if (mStatusBarNotifier != null) { 391 mStatusBarNotifier.updateNotification(mInCallState, mCallList); 392 } 393 394 if (mProximitySensor != null) { 395 mProximitySensor.onInCallShowing(showing); 396 } 397 398 if (showing) { 399 mIsActivityPreviouslyStarted = true; 400 } 401 } 402 403 /** 404 * Brings the app into the foreground if possible. 405 */ 406 public void bringToForeground(boolean showDialpad) { 407 // Before we bring the incall UI to the foreground, we check to see if: 408 // 1. We've already started the activity once for this session 409 // 2. If it exists, the activity is not already in the foreground 410 // 3. We are in a state where we want to show the incall ui 411 if (mIsActivityPreviouslyStarted && !isShowingInCallUi() && 412 mInCallState != InCallState.NO_CALLS) { 413 showInCall(showDialpad); 414 } 415 } 416 417 public void onPostDialCharWait(int callId, String chars) { 418 mInCallActivity.showPostCharWaitDialog(callId, chars); 419 } 420 421 /** 422 * Handles the green CALL key while in-call. 423 * @return true if we consumed the event. 424 */ 425 public boolean handleCallKey() { 426 Log.v(this, "handleCallKey"); 427 428 // The green CALL button means either "Answer", "Unhold", or 429 // "Swap calls", or can be a no-op, depending on the current state 430 // of the Phone. 431 432 /** 433 * INCOMING CALL 434 */ 435 final CallList calls = CallList.getInstance(); 436 final Call incomingCall = calls.getIncomingCall(); 437 Log.v(this, "incomingCall: " + incomingCall); 438 439 // (1) Attempt to answer a call 440 if (incomingCall != null) { 441 CallCommandClient.getInstance().answerCall(incomingCall.getCallId()); 442 return true; 443 } 444 445 /** 446 * ACTIVE CALL 447 */ 448 final Call activeCall = calls.getActiveCall(); 449 if (activeCall != null) { 450 // TODO: This logic is repeated from CallButtonPresenter.java. We should 451 // consolidate this logic. 452 final boolean isGeneric = activeCall.can(Capabilities.GENERIC_CONFERENCE); 453 final boolean canMerge = activeCall.can(Capabilities.MERGE_CALLS); 454 final boolean canSwap = activeCall.can(Capabilities.SWAP_CALLS); 455 456 Log.v(this, "activeCall: " + activeCall + ", isGeneric: " + isGeneric + ", canMerge: " + 457 canMerge + ", canSwap: " + canSwap); 458 459 // (2) Attempt actions on Generic conference calls 460 if (activeCall.isConferenceCall() && isGeneric) { 461 if (canMerge) { 462 CallCommandClient.getInstance().merge(); 463 return true; 464 } else if (canSwap) { 465 CallCommandClient.getInstance().swap(); 466 return true; 467 } 468 } 469 470 // (3) Swap calls 471 if (canSwap) { 472 CallCommandClient.getInstance().swap(); 473 return true; 474 } 475 } 476 477 /** 478 * BACKGROUND CALL 479 */ 480 final Call heldCall = calls.getBackgroundCall(); 481 if (heldCall != null) { 482 // We have a hold call so presumeable it will always support HOLD...but 483 // there is no harm in double checking. 484 final boolean canHold = heldCall.can(Capabilities.HOLD); 485 486 Log.v(this, "heldCall: " + heldCall + ", canHold: " + canHold); 487 488 // (4) unhold call 489 if (heldCall.getState() == Call.State.ONHOLD && canHold) { 490 CallCommandClient.getInstance().hold(heldCall.getCallId(), false); 491 return true; 492 } 493 } 494 495 // Always consume hard keys 496 return true; 497 } 498 499 /** 500 * A dialog could have prevented in-call screen from being previously finished. 501 * This function checks to see if there should be any UI left and if not attempts 502 * to tear down the UI. 503 */ 504 public void onDismissDialog() { 505 Log.i(this, "Dialog dismissed"); 506 if (mInCallState == InCallState.NO_CALLS) { 507 attemptFinishActivity(); 508 attemptCleanup(); 509 } 510 } 511 512 /** 513 * For some disconnected causes, we show a dialog. This calls into the activity to show 514 * the dialog if appropriate for the call. 515 */ 516 private void maybeShowErrorDialogOnDisconnect(Call call) { 517 // For newly disconnected calls, we may want to show a dialog on specific error conditions 518 if (isActivityStarted() && call.getState() == Call.State.DISCONNECTED) { 519 mInCallActivity.maybeShowErrorDialogOnDisconnect(call.getDisconnectCause()); 520 } 521 } 522 523 /** 524 * Hides the dialpad. Called when a call is disconnected (Requires hiding dialpad). 525 */ 526 private void hideDialpadForDisconnect() { 527 if (isActivityStarted()) { 528 mInCallActivity.hideDialpadForDisconnect(); 529 } 530 } 531 532 /** 533 * When the state of in-call changes, this is the first method to get called. It determines if 534 * the UI needs to be started or finished depending on the new state and does it. 535 */ 536 private InCallState startOrFinishUi(InCallState newState) { 537 Log.d(this, "startOrFinishUi: " + mInCallState + " -> " + newState); 538 539 // TODO: Consider a proper state machine implementation 540 541 // If the state isn't changing, we have already done any starting/stopping of 542 // activities in a previous pass...so lets cut out early 543 if (newState == mInCallState) { 544 return newState; 545 } 546 547 // A new Incoming call means that the user needs to be notified of the the call (since 548 // it wasn't them who initiated it). We do this through full screen notifications and 549 // happens indirectly through {@link StatusBarListener}. 550 // 551 // The process for incoming calls is as follows: 552 // 553 // 1) CallList - Announces existence of new INCOMING call 554 // 2) InCallPresenter - Gets announcement and calculates that the new InCallState 555 // - should be set to INCOMING. 556 // 3) InCallPresenter - This method is called to see if we need to start or finish 557 // the app given the new state. 558 // 4) StatusBarNotifier - Listens to InCallState changes. InCallPresenter calls 559 // StatusBarNotifier explicitly to issue a FullScreen Notification 560 // that will either start the InCallActivity or show the user a 561 // top-level notification dialog if the user is in an immersive app. 562 // That notification can also start the InCallActivity. 563 // 5) InCallActivity - Main activity starts up and at the end of its onCreate will 564 // call InCallPresenter::setActivity() to let the presenter 565 // know that start-up is complete. 566 // 567 // [ AND NOW YOU'RE IN THE CALL. voila! ] 568 // 569 // Our app is started using a fullScreen notification. We need to do this whenever 570 // we get an incoming call. 571 final boolean startStartupSequence = (InCallState.INCOMING == newState); 572 573 // A new outgoing call indicates that the user just now dialed a number and when that 574 // happens we need to display the screen immediateley. 575 // 576 // This is different from the incoming call sequence because we do not need to shock the 577 // user with a top-level notification. Just show the call UI normally. 578 final boolean showCallUi = (InCallState.OUTGOING == newState); 579 580 // TODO: Can we be suddenly in a call without it having been in the outgoing or incoming 581 // state? I havent seen that but if it can happen, the code below should be enabled. 582 // showCallUi |= (InCallState.INCALL && !isActivityStarted()); 583 584 // The only time that we have an instance of mInCallActivity and it isn't started is 585 // when it is being destroyed. In that case, lets avoid bringing up another instance of 586 // the activity. When it is finally destroyed, we double check if we should bring it back 587 // up so we aren't going to lose anything by avoiding a second startup here. 588 boolean activityIsFinishing = mInCallActivity != null && !isActivityStarted(); 589 if (activityIsFinishing) { 590 Log.i(this, "Undo the state change: " + newState + " -> " + mInCallState); 591 return mInCallState; 592 } 593 594 if (showCallUi) { 595 Log.i(this, "Start in call UI"); 596 showInCall(false); 597 } else if (startStartupSequence) { 598 Log.i(this, "Start Full Screen in call UI"); 599 600 // We're about the bring up the in-call UI for an incoming call. If we still have 601 // dialogs up, we need to clear them out before showing incoming screen. 602 if (isActivityStarted()) { 603 mInCallActivity.dismissPendingDialogs(); 604 } 605 startUi(newState); 606 } else if (newState == InCallState.NO_CALLS) { 607 // The new state is the no calls state. Tear everything down. 608 attemptFinishActivity(); 609 attemptCleanup(); 610 } 611 612 return newState; 613 } 614 615 private void startUi(InCallState inCallState) { 616 final Call incomingCall = mCallList.getIncomingCall(); 617 final boolean isCallWaiting = (incomingCall != null && 618 incomingCall.getState() == Call.State.CALL_WAITING); 619 620 // If the screen is off, we need to make sure it gets turned on for incoming calls. 621 // This normally works just fine thanks to FLAG_TURN_SCREEN_ON but that only works 622 // when the activity is first created. Therefore, to ensure the screen is turned on 623 // for the call waiting case, we finish() the current activity and start a new one. 624 // There should be no jank from this since the screen is already off and will remain so 625 // until our new activity is up. 626 if (mProximitySensor.isScreenReallyOff() && isCallWaiting) { 627 if (isActivityStarted()) { 628 mInCallActivity.finish(); 629 } 630 mInCallActivity = null; 631 } 632 633 mStatusBarNotifier.updateNotificationAndLaunchIncomingCallUi(inCallState, mCallList); 634 } 635 636 /** 637 * Checks to see if both the UI is gone and the service is disconnected. If so, tear it all 638 * down. 639 */ 640 private void attemptCleanup() { 641 boolean shouldCleanup = (mInCallActivity == null && !mServiceConnected && 642 mInCallState == InCallState.NO_CALLS); 643 Log.i(this, "attemptCleanup? " + shouldCleanup); 644 645 if (shouldCleanup) { 646 mIsActivityPreviouslyStarted = false; 647 648 // blow away stale contact info so that we get fresh data on 649 // the next set of calls 650 if (mContactInfoCache != null) { 651 mContactInfoCache.clearCache(); 652 } 653 mContactInfoCache = null; 654 655 if (mProximitySensor != null) { 656 removeListener(mProximitySensor); 657 mProximitySensor.tearDown(); 658 } 659 mProximitySensor = null; 660 661 mAudioModeProvider = null; 662 663 if (mStatusBarNotifier != null) { 664 removeListener(mStatusBarNotifier); 665 } 666 mStatusBarNotifier = null; 667 668 if (mCallList != null) { 669 mCallList.removeListener(this); 670 } 671 mCallList = null; 672 673 mContext = null; 674 mInCallActivity = null; 675 676 mListeners.clear(); 677 mIncomingCallListeners.clear(); 678 679 Log.d(this, "Finished InCallPresenter.CleanUp"); 680 } 681 } 682 683 private void showInCall(boolean showDialpad) { 684 mContext.startActivity(getInCallIntent(showDialpad)); 685 } 686 687 public Intent getInCallIntent(boolean showDialpad) { 688 final Intent intent = new Intent(Intent.ACTION_MAIN, null); 689 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 690 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 691 | Intent.FLAG_ACTIVITY_NO_USER_ACTION); 692 intent.setClass(mContext, InCallActivity.class); 693 if (showDialpad) { 694 intent.putExtra(InCallActivity.SHOW_DIALPAD_EXTRA, true); 695 } 696 697 return intent; 698 } 699 700 /** 701 * Private constructor. Must use getInstance() to get this singleton. 702 */ 703 private InCallPresenter() { 704 } 705 706 /** 707 * All the main states of InCallActivity. 708 */ 709 public enum InCallState { 710 // InCall Screen is off and there are no calls 711 NO_CALLS, 712 713 // Incoming-call screen is up 714 INCOMING, 715 716 // In-call experience is showing 717 INCALL, 718 719 // User is dialing out 720 OUTGOING; 721 722 public boolean isIncoming() { 723 return (this == INCOMING); 724 } 725 726 public boolean isConnectingOrConnected() { 727 return (this == INCOMING || 728 this == OUTGOING || 729 this == INCALL); 730 } 731 } 732 733 /** 734 * Interface implemented by classes that need to know about the InCall State. 735 */ 736 public interface InCallStateListener { 737 // TODO: Enhance state to contain the call objects instead of passing CallList 738 public void onStateChange(InCallState state, CallList callList); 739 } 740 741 public interface IncomingCallListener { 742 public void onIncomingCall(InCallState state, Call call); 743 } 744} 745