diff options
author | Santos Cordon <santoscordon@google.com> | 2013-09-19 03:23:03 -0700 |
---|---|---|
committer | Santos Cordon <santoscordon@google.com> | 2013-09-19 03:23:03 -0700 |
commit | 2acdea2c70d7fc470509b8d6ac3c5e7273544bea (patch) | |
tree | a0a03072be5c21771fe0d4e2cb41b54d000b8bec | |
parent | c45651f66d67ad0ff33c302ae2c350bfdd4fe7d1 (diff) |
Add support for hardware CALL button.
bug:10809304
Change-Id: I8b6c5e27a37624f38df965e2ad001703cf558708
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallActivity.java | 13 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallPresenter.java | 72 |
2 files changed, 80 insertions, 5 deletions
diff --git a/InCallUI/src/com/android/incallui/InCallActivity.java b/InCallUI/src/com/android/incallui/InCallActivity.java index feb3ec137..17b4c31fd 100644 --- a/InCallUI/src/com/android/incallui/InCallActivity.java +++ b/InCallUI/src/com/android/incallui/InCallActivity.java @@ -190,7 +190,10 @@ public class InCallActivity extends Activity { public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_CALL: - // TODO(klp): handle call key + boolean handled = InCallPresenter.getInstance().handleCallKey(); + if (!handled) { + Log.w(this, "InCallActivity should always handle KEYCODE_CALL in onKeyDown"); + } // Always consume CALL to be sure the PhoneWindow won't do anything with it return true; @@ -209,11 +212,12 @@ public class InCallActivity extends Activity { case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_MUTE: - // Not sure if needed. If so, silence ringer. + // Ringer silencing handled by PhoneWindowManager. break; case KeyEvent.KEYCODE_MUTE: - toast("mute"); + // toggle mute + CallCommandClient.getInstance().mute(!AudioModeProvider.getInstance().getMute()); return true; // Various testing/debugging features, enabled ONLY when VERBOSE == true. @@ -228,11 +232,10 @@ public class InCallActivity extends Activity { } break; case KeyEvent.KEYCODE_EQUALS: - // TODO(klp): Dump phone state? + // TODO: Dump phone state? break; } - // TODO(klp) Adds hardware keyboard support return super.onKeyDown(keyCode, event); } diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index bfff83fe5..327f3be07 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -23,6 +23,7 @@ import android.content.Context; import android.content.Intent; import com.android.services.telephony.common.Call; +import com.android.services.telephony.common.Call.Capabilities; import com.google.common.collect.Lists; import java.util.ArrayList; @@ -337,6 +338,77 @@ public class InCallPresenter implements CallList.Listener { } /** + * 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. + + 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()); + return true; + } + + 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; + } + } + + 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; + } + + /** * When the state of in-call changes, this is the first method to get called. It determines if * the UI needs to be started or finished depending on the new state and does it. */ |