From 3570e970a2812b95ed82bf8e232d1e22f71f118e Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Wed, 8 Apr 2015 10:41:57 -0700 Subject: Cleanup of Video Call pause functionality. Whether the paused videoState is available is dependent on the carrier's implementation of the VT spec. The original VT implementation assumed that this was stored in a system property accessed via InCall; these CLs move this to a Call/Connection capability which will ultimately support multisim video capable devices. - Made some general cleanups in VideoPauseController (comments, some minor logic changes, renamed a few methods). - Removed access of system property to see if pause is supported and instead key in on the call capability. - Changed video call presenter to hide incoming video surface when a pause signal is received. Bug: 16680364 Bug: 19820114 Change-Id: I6d1a7789925c69e4022846f8d847b8bb1274c06b --- .../com/android/incallui/VideoCallPresenter.java | 14 +- .../com/android/incallui/VideoPauseController.java | 239 ++++++++++++++------- 2 files changed, 170 insertions(+), 83 deletions(-) diff --git a/InCallUI/src/com/android/incallui/VideoCallPresenter.java b/InCallUI/src/com/android/incallui/VideoCallPresenter.java index 486a38da3..3f8a827c3 100644 --- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java +++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java @@ -412,7 +412,9 @@ public class VideoCallPresenter extends Presenter + * Reject incoming or hangup dialing call: Where the previous call was an incoming call or a + * call in dialing state, resume the new primary call. + * Call swap: Where the new primary call is incoming, pause video on the previous primary call. + * + * @param call The new primary call. + */ private void onPrimaryCallChanged(Call call) { log("onPrimaryCallChanged: New call = " + call); log("onPrimaryCallChanged: Old call = " + mPrimaryCallContext); @@ -200,25 +209,26 @@ class VideoPauseController implements InCallStateListener, IncomingCallListener, Preconditions.checkState(!areSame(call, mPrimaryCallContext)); final boolean canVideoPause = CallUtils.canVideoPause(call); - if (isWaitingCall(mPrimaryCallContext) && canVideoPause && !mIsInBackground) { - // Send resume request for the active call, if user rejects incoming - // call and UI is in foreground. + if ((isIncomingCall(mPrimaryCallContext) || isDialing(mPrimaryCallContext)) + && canVideoPause && !mIsInBackground) { + // Send resume request for the active call, if user rejects incoming call or ends + // dialing call and UI is in the foreground. sendRequest(call, true); - } else if (isWaitingCall(call) && canVideoPause(mPrimaryCallContext)) { + } else if (isIncomingCall(call) && canVideoPause(mPrimaryCallContext)) { // Send pause request if there is an active video call, and we just received a new // incoming call. sendRequest(mPrimaryCallContext.getCall(), false); - } else if (isOutgoing(mPrimaryCallContext) && canVideoPause && !mIsInBackground) { - // Send resume request for the active call, if user ends outgoing call - // and UI is in foreground. - sendRequest(call, true); } updatePrimaryCallContext(call); } /** - * The function gets called when InCallUI receives a new incoming call. + * Handles new incoming calls by triggering a change in the primary call. + * + * @param oldState the old {@link InCallState}. + * @param newState the new {@link InCallState}. + * @param call the incoming call. */ @Override public void onIncomingCall(InCallState oldState, InCallState newState, Call call) { @@ -231,6 +241,11 @@ class VideoPauseController implements InCallStateListener, IncomingCallListener, onPrimaryCallChanged(call); } + /** + * Caches a reference to the primary call and stores its previous state. + * + * @param call The new primary call. + */ private void updatePrimaryCallContext(Call call) { if (call == null) { mPrimaryCallContext = null; @@ -246,43 +261,67 @@ class VideoPauseController implements InCallStateListener, IncomingCallListener, * @param showing true if UI is in the foreground, false otherwise. */ public void onUiShowing(boolean showing) { - if (!isVideoPausedEnabled() || mInCallPresenter == null) { + // Only send pause/unpause requests if we are in the INCALL state. + if (mInCallPresenter == null || mInCallPresenter.getInCallState() != InCallState.INCALL) { return; } - final boolean notify = mInCallPresenter.getInCallState() == InCallState.INCALL; if (showing) { - onResume(notify); + onResume(); } else { - onPause(notify); + onPause(); } } + /** + * Handles requests to upgrade to video. + * + * @param call The call the request was received for. + * @param videoState The video state that the request wants to upgrade to. + */ @Override public void onUpgradeToVideoRequest(Call call, int videoState) { + // Not used. } + /** + * Handles successful upgrades to video. + * @param call The call the request was successful for. + */ @Override public void onUpgradeToVideoSuccess(Call call) { + // Not used. } + /** + * Handles a failure to upgrade a call to video. + * + * @param status The failure status. + * @param call The call the request was successful for. + */ @Override public void onUpgradeToVideoFail(int status, Call call) { // TODO (ims-vt) Automatically bring in call ui to foreground. } + /** + * Handles a downgrade of a call to audio-only. + * + * @param call The call which was downgraded to audio-only. + */ @Override public void onDowngradeToAudio(Call call) { } /** - * Called when UI becomes visible. This will send resume request for current video call, if any. + * Called when UI is brought to the foreground. Sends a session modification request to resume + * the outgoing video. */ - private void onResume(boolean notify) { - log("onResume: notify=" + notify); + private void onResume() { + log("onResume"); mIsInBackground = false; - if (canVideoPause(mPrimaryCallContext) && notify) { + if (canVideoPause(mPrimaryCallContext)) { sendRequest(mPrimaryCallContext.getCall(), true); } else { log("onResume. Ignoring..."); @@ -290,13 +329,14 @@ class VideoPauseController implements InCallStateListener, IncomingCallListener, } /** - * Called when UI becomes invisible. This will send pause request for current video call, if any. + * Called when UI is sent to the background. Sends a session modification request to pause the + * outgoing video. */ - private void onPause(boolean notify) { - log("onPause: notify=" + notify); + private void onPause() { + log("onPause"); mIsInBackground = true; - if (canVideoPause(mPrimaryCallContext) && notify) { + if (canVideoPause(mPrimaryCallContext)) { sendRequest(mPrimaryCallContext.getCall(), false); } else { log("onPause, Ignoring..."); @@ -314,75 +354,118 @@ class VideoPauseController implements InCallStateListener, IncomingCallListener, /** * Sends Pause/Resume request. + * * @param call Call to be paused/resumed. * @param resume If true resume request will be sent, otherwise pause request. */ private void sendRequest(Call call, boolean resume) { + // Check if this call supports pause/un-pause. + if (!call.can(android.telecom.Call.Details.CAPABILITY_CAN_PAUSE_VIDEO)) { + return; + } + if (resume) { log("sending resume request, call=" + call); - call.getVideoCall().sendSessionModifyRequest(CallUtils.makeVideoUnPauseProfile(call)); + call.getVideoCall() + .sendSessionModifyRequest(CallUtils.makeVideoUnPauseProfile(call)); } else { log("sending pause request, call=" + call); call.getVideoCall().sendSessionModifyRequest(CallUtils.makeVideoPauseProfile(call)); } } - private boolean isVideoPausedEnabled() { - return mVideoPauseMode != VIDEO_PAUSE_MODE_DISABLED; - } - + /** + * Determines if a given call is the same one stored in a {@link CallContext}. + * + * @param call The call. + * @param callContext The call context. + * @return {@code true} if the {@link Call} is the same as the one referenced in the + * {@link CallContext}. + */ private static boolean areSame(Call call, CallContext callContext) { if (call == null && callContext == null) { return true; } else if (call == null || callContext == null) { return false; } - return call.getId().equals(callContext.getId()); - } - - private static boolean areSame(CallContext callContext, Call call) { - return areSame(call, callContext); + return call.equals(callContext.getCall()); } + /** + * Determines if a video call can be paused. Only a video call which is active can be paused. + * + * @param callContext The call context to check. + * @return {@code true} if the call is an active video call. + */ private static boolean canVideoPause(CallContext callContext) { return isVideoCall(callContext) && callContext.getState() == Call.State.ACTIVE; } + /** + * Determines if a call referenced by a {@link CallContext} is a video call. + * + * @param callContext The call context. + * @return {@code true} if the call is a video call, {@code false} otherwise. + */ private static boolean isVideoCall(CallContext callContext) { return callContext != null && VideoProfile.VideoState.isVideo(callContext.getVideoState()); } /** - * Returns true if call is in incoming/waiting state, false otherwise. + * Determines if call is in incoming/waiting state. + * + * @param call The call context. + * @return {@code true} if the call is in incoming or waiting state, {@code false} otherwise. */ - private static boolean isWaitingCall(CallContext call) { - return call != null && (call.getState() == Call.State.CALL_WAITING - || call.getState() == Call.State.INCOMING); + private static boolean isIncomingCall(CallContext call) { + return call != null && isIncomingCall(call.getCall()); } - private static boolean isWaitingCall(Call call) { + /** + * Determines if a call is in incoming/waiting state. + * + * @param call The call. + * @return {@code true} if the call is in incoming or waiting state, {@code false} otherwise. + */ + private static boolean isIncomingCall(Call call) { return call != null && (call.getState() == Call.State.CALL_WAITING || call.getState() == Call.State.INCOMING); } /** - * Returns true if the call is outgoing, false otherwise + * Determines if a call is dialing. + * + * @param call The call context. + * @return {@code true} if the call is dialing, {@code false} otherwise. */ - private static boolean isOutgoing(CallContext call) { + private static boolean isDialing(CallContext call) { return call != null && Call.State.isDialing(call.getState()); } /** - * Returns true if the call is on hold, false otherwise + * Determines if a call is holding. + * + * @param call The call context. + * @return {@code true} if the call is holding, {@code false} otherwise. */ private static boolean isHolding(CallContext call) { return call != null && call.getState() == Call.State.ONHOLD; } + /** + * Logs a debug message. + * + * @param msg The message. + */ private void log(String msg) { Log.d(this, TAG + msg); } + /** + * Logs an error message. + * + * @param msg The message. + */ private void loge(String msg) { Log.e(this, TAG + msg); } -- cgit v1.2.3