diff options
author | Santos Cordon <santoscordon@google.com> | 2013-09-19 21:30:46 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-19 21:30:47 +0000 |
commit | 7b35331be8f517a072e2d38603f82caba49d9d91 (patch) | |
tree | 1bd73fb000030b89c2fb888f739b12ca02473a34 | |
parent | e568ea229963a5d6ca11b768c6464b3e96e932cd (diff) | |
parent | 2acdea2c70d7fc470509b8d6ac3c5e7273544bea (diff) |
Merge "Add support for hardware CALL button." into klp-dev
-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 15e48c54a..8a5ba6b5e 100644 --- a/InCallUI/src/com/android/incallui/InCallActivity.java +++ b/InCallUI/src/com/android/incallui/InCallActivity.java @@ -193,7 +193,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; @@ -212,11 +215,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. @@ -231,11 +235,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 33b910cef..bdbdf6d91 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; @@ -348,6 +349,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. */ |