/** Given the call list, return the state in which the in-call screen should be. */ public static InCallState getPotentialStateFromCallList(CallList callList) { InCallState newState = InCallState.NO_CALLS; if (callList == null) { return newState; } if (callList.getIncomingCall() != null) { newState = InCallState.INCOMING; } else if (callList.getOutgoingCall() != null) { newState = InCallState.OUTGOING; } else if (callList.getActiveCall() != null || callList.getBackgroundCall() != null || callList.getDisconnectedCall() != null || callList.getDisconnectingCall() != null) { newState = InCallState.INCALL; } return newState; }
/** * Handles the green CALL key while in-call. * * @return true if we consumed the event. */ public boolean handleCallKey() { Log.v(this, "handleCallKey"); // The green CALL button means either "Answer", "Unhold", or // "Swap calls", or can be a no-op, depending on the current state // of the Phone. /** INCOMING CALL */ final CallList calls = CallList.getInstance(); final Call incomingCall = calls.getIncomingCall(); Log.v(this, "incomingCall: " + incomingCall); // (1) Attempt to answer a call if (incomingCall != null) { CallCommandClient.getInstance().answerCall(incomingCall.getCallId()); if (mAccelerometerListener != null) { mAccelerometerListener.enableSensor(false); } return true; } /** ACTIVE CALL */ final Call activeCall = calls.getActiveCall(); if (activeCall != null) { // TODO: This logic is repeated from CallButtonPresenter.java. We should // consolidate this logic. final boolean isGeneric = activeCall.can(Capabilities.GENERIC_CONFERENCE); final boolean canMerge = activeCall.can(Capabilities.MERGE_CALLS); final boolean canSwap = activeCall.can(Capabilities.SWAP_CALLS); Log.v( this, "activeCall: " + activeCall + ", isGeneric: " + isGeneric + ", canMerge: " + canMerge + ", canSwap: " + canSwap); // (2) Attempt actions on Generic conference calls if (activeCall.isConferenceCall() && isGeneric) { if (canMerge) { CallCommandClient.getInstance().merge(); return true; } else if (canSwap) { CallCommandClient.getInstance().swap(); return true; } } // (3) Swap calls if (canSwap) { CallCommandClient.getInstance().swap(); return true; } } /** BACKGROUND CALL */ final Call heldCall = calls.getBackgroundCall(); if (heldCall != null) { // We have a hold call so presumeable it will always support HOLD...but // there is no harm in double checking. final boolean canHold = heldCall.can(Capabilities.HOLD); Log.v(this, "heldCall: " + heldCall + ", canHold: " + canHold); // (4) unhold call if (heldCall.getState() == Call.State.ONHOLD && canHold) { CallCommandClient.getInstance().hold(heldCall.getCallId(), false); return true; } } // Always consume hard keys return true; }