summaryrefslogtreecommitdiff
path: root/InCallUI/src/com/android/incallui/AnswerPresenter.java
diff options
context:
space:
mode:
Diffstat (limited to 'InCallUI/src/com/android/incallui/AnswerPresenter.java')
-rw-r--r--InCallUI/src/com/android/incallui/AnswerPresenter.java116
1 files changed, 101 insertions, 15 deletions
diff --git a/InCallUI/src/com/android/incallui/AnswerPresenter.java b/InCallUI/src/com/android/incallui/AnswerPresenter.java
index e579d643a..208532572 100644
--- a/InCallUI/src/com/android/incallui/AnswerPresenter.java
+++ b/InCallUI/src/com/android/incallui/AnswerPresenter.java
@@ -18,6 +18,7 @@ package com.android.incallui;
import android.content.Context;
import android.telecom.TelecomManager;
+import android.telecom.VideoProfile;
import java.util.List;
@@ -35,6 +36,7 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi>
@Override
public void onUiReady(AnswerUi ui) {
+ Log.d(this, "onUiReady ui=" + ui);
super.onUiReady(ui);
final CallList calls = CallList.getInstance();
@@ -43,9 +45,12 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi>
if (call != null) {
processIncomingCall(call);
}
- call = calls.getVideoUpgradeRequestCall();
- if (call != null) {
- processVideoUpgradeRequestCall(call);
+
+ Call videoCall = calls.getVideoUpgradeRequestCall();
+ Log.d(this, "getVideoUpgradeRequestCall call =" + call);
+
+ if (videoCall != null && call == null) {
+ processVideoUpgradeRequestCall(videoCall);
}
// Listen for incoming calls.
@@ -67,6 +72,7 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi>
@Override
public void onCallListChange(CallList callList) {
+ Log.d(this, "onCallListChange callList=" + callList);
// no-op
}
@@ -81,6 +87,13 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi>
// getting updates here.
Log.d(this, "onIncomingCall: " + this);
if (getUi() != null) {
+ Call modifyCall = CallList.getInstance().getVideoUpgradeRequestCall();
+ if (modifyCall != null) {
+ getUi().showAnswerUi(false);
+ Log.d(this, "declining upgrade request id: ");
+ CallList.getInstance().removeCallUpdateListener(mCallId, this);
+ InCallPresenter.getInstance().declineUpgradeRequest(getUi().getContext());
+ }
if (!call.getId().equals(mCallId)) {
// A new call is coming in.
processIncomingCall(call);
@@ -88,6 +101,31 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi>
}
}
+ private boolean isVideoUpgradePending(Call call) {
+ return call.getSessionModificationState()
+ == Call.SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST;
+ }
+
+ @Override
+ public void onUpgradeToVideo(Call call) {
+ Log.d(this, "onUpgradeToVideo: " + this + " call=" + call);
+ if (getUi() == null) {
+ Log.d(this, "onUpgradeToVideo ui is null");
+ return;
+ }
+ boolean isUpgradePending = isVideoUpgradePending(call);
+ InCallPresenter inCallPresenter = InCallPresenter.getInstance();
+ if (isUpgradePending
+ && inCallPresenter.getInCallState() == InCallPresenter.InCallState.INCOMING) {
+ Log.d(this, "declining upgrade request");
+ //If there is incoming call reject upgrade request
+ inCallPresenter.declineUpgradeRequest(getUi().getContext());
+ } else if (isUpgradePending) {
+ Log.d(this, "process upgrade request as no MT call");
+ processVideoUpgradeRequestCall(call);
+ }
+ }
+
private void processIncomingCall(Call call) {
mCallId = call.getId();
mCall = call;
@@ -102,28 +140,71 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi>
}
private void processVideoUpgradeRequestCall(Call call) {
+ Log.d(this, " processVideoUpgradeRequestCall call=" + call);
mCallId = call.getId();
mCall = call;
// Listen for call updates for the current call.
CallList.getInstance().addCallUpdateListener(mCallId, this);
- getUi().showAnswerUi(true);
- getUi().showTargets(AnswerFragment.TARGET_SET_FOR_VIDEO_UPGRADE_REQUEST);
+ final int currentVideoState = call.getVideoState();
+ final int modifyToVideoState = call.getModifyToVideoState();
+
+ if (currentVideoState == modifyToVideoState) {
+ Log.w(this, "processVideoUpgradeRequestCall: Video states are same. Return.");
+ return;
+ }
+
+ AnswerUi ui = getUi();
+
+ if (ui == null) {
+ Log.e(this, "Ui is null. Can't process upgrade request");
+ return;
+ }
+ ui.showAnswerUi(true);
+ ui.showTargets(getUiTarget(currentVideoState, modifyToVideoState));
+
+ }
+
+ private int getUiTarget(int currentVideoState, int modifyToVideoState) {
+ if (showVideoUpgradeOptions(currentVideoState, modifyToVideoState)) {
+ return AnswerFragment.TARGET_SET_FOR_VIDEO_UPGRADE_REQUEST;
+ } else if (isEnabled(modifyToVideoState, VideoProfile.VideoState.BIDIRECTIONAL)) {
+ return AnswerFragment.TARGET_SET_FOR_BIDIRECTIONAL_VIDEO_ACCEPT_REJECT_REQUEST;
+ } else if (isEnabled(modifyToVideoState, VideoProfile.VideoState.TX_ENABLED)) {
+ return AnswerFragment.TARGET_SET_FOR_VIDEO_TRANSMIT_ACCEPT_REJECT_REQUEST;
+ } else if (isEnabled(modifyToVideoState, VideoProfile.VideoState.RX_ENABLED)) {
+ return AnswerFragment.TARGET_SET_FOR_VIDEO_RECEIVE_ACCEPT_REJECT_REQUEST;
+ }
+ return AnswerFragment.TARGET_SET_FOR_VIDEO_UPGRADE_REQUEST;
+ }
+
+ private boolean showVideoUpgradeOptions(int currentVideoState, int modifyToVideoState) {
+ return currentVideoState == VideoProfile.VideoState.AUDIO_ONLY &&
+ isEnabled(modifyToVideoState, VideoProfile.VideoState.BIDIRECTIONAL);
+ }
+
+ private boolean isEnabled(int videoState, int mask) {
+ return (videoState & mask) == mask;
}
@Override
public void onCallChanged(Call call) {
Log.d(this, "onCallStateChange() " + call + " " + this);
if (call.getState() != Call.State.INCOMING) {
- // Stop listening for updates.
- CallList.getInstance().removeCallUpdateListener(mCallId, this);
+ boolean isUpgradePending = isVideoUpgradePending(call);
+ if (!isUpgradePending) {
+ // Stop listening for updates.
+ CallList.getInstance().removeCallUpdateListener(mCallId, this);
+ }
- getUi().showAnswerUi(false);
+ final Call incall = CallList.getInstance().getIncomingCall();
+ if (incall != null || isUpgradePending) {
+ getUi().showAnswerUi(true);
+ } else {
+ getUi().showAnswerUi(false);
+ }
- // mCallId will hold the state of the call. We don't clear the mCall variable here as
- // it may be useful for sending text messages after phone disconnects.
- mCallId = null;
mHasTextMessages = false;
} else if (!mHasTextMessages) {
final List<String> textMsgs = CallList.getInstance().getTextResponses(call.getId());
@@ -134,14 +215,14 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi>
}
public void onAnswer(int videoState, Context context) {
+ Log.d(this, "onAnswer mCallId=" + mCallId + " videoState=" + videoState);
if (mCallId == null) {
return;
}
- Log.d(this, "onAnswer " + mCallId);
if (mCall.getSessionModificationState()
== Call.SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) {
- InCallPresenter.getInstance().acceptUpgradeRequest(context);
+ InCallPresenter.getInstance().acceptUpgradeRequest(videoState, context);
} else {
TelecomAdapter.getInstance().answerCall(mCall.getId(), videoState);
}
@@ -151,9 +232,14 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi>
* TODO: We are using reject and decline interchangeably. We should settle on
* reject since it seems to be more prevalent.
*/
- public void onDecline() {
+ public void onDecline(Context context) {
Log.d(this, "onDecline " + mCallId);
- TelecomAdapter.getInstance().rejectCall(mCall.getId(), false, null);
+ if (mCall.getSessionModificationState()
+ == Call.SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) {
+ InCallPresenter.getInstance().declineUpgradeRequest(context);
+ } else {
+ TelecomAdapter.getInstance().rejectCall(mCall.getId(), false, null);
+ }
}
public void onText() {