blob: ddbe6ccef514371b4103e54be8ab775996016e31 [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.incallui;
18
19import android.content.Context;
20import android.support.annotation.FloatRange;
21import android.support.annotation.NonNull;
22import android.support.v4.os.UserManagerCompat;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070023import android.telecom.VideoProfile;
Eric Erfanianccca3152017-02-22 16:32:36 -080024import com.android.dialer.common.Assert;
25import com.android.dialer.common.LogUtil;
Eric Erfanian8369df02017-05-03 10:27:13 -070026import com.android.dialer.logging.DialerImpression;
27import com.android.dialer.logging.Logger;
Eric Erfanianccca3152017-02-22 16:32:36 -080028import com.android.incallui.answer.protocol.AnswerScreen;
29import com.android.incallui.answer.protocol.AnswerScreenDelegate;
30import com.android.incallui.answerproximitysensor.AnswerProximitySensor;
31import com.android.incallui.answerproximitysensor.PseudoScreenState;
Eric Erfanian90508232017-03-24 09:31:16 -070032import com.android.incallui.call.CallList;
Eric Erfanianccca3152017-02-22 16:32:36 -080033import com.android.incallui.call.DialerCall;
Eric Erfanian90508232017-03-24 09:31:16 -070034import com.android.incallui.call.DialerCallListener;
Eric Erfanianccca3152017-02-22 16:32:36 -080035
36/** Manages changes for an incoming call screen. */
37public class AnswerScreenPresenter
38 implements AnswerScreenDelegate, DialerCall.CannedTextResponsesLoadedListener {
39 @NonNull private final Context context;
40 @NonNull private final AnswerScreen answerScreen;
41 @NonNull private final DialerCall call;
42
43 public AnswerScreenPresenter(
44 @NonNull Context context, @NonNull AnswerScreen answerScreen, @NonNull DialerCall call) {
45 LogUtil.i("AnswerScreenPresenter.constructor", null);
46 this.context = Assert.isNotNull(context);
47 this.answerScreen = Assert.isNotNull(answerScreen);
48 this.call = Assert.isNotNull(call);
49 if (isSmsResponseAllowed(call)) {
50 answerScreen.setTextResponses(call.getCannedSmsResponses());
51 }
52 call.addCannedTextResponsesLoadedListener(this);
53
54 PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState();
55 if (AnswerProximitySensor.shouldUse(context, call)) {
56 new AnswerProximitySensor(context, call, pseudoScreenState);
57 } else {
58 pseudoScreenState.setOn(true);
59 }
60 }
61
62 @Override
63 public void onAnswerScreenUnready() {
64 call.removeCannedTextResponsesLoadedListener(this);
65 }
66
67 @Override
68 public void onDismissDialog() {
69 InCallPresenter.getInstance().onDismissDialog();
70 }
71
72 @Override
73 public void onRejectCallWithMessage(String message) {
74 call.reject(true /* rejectWithMessage */, message);
75 onDismissDialog();
76 }
77
78 @Override
Eric Erfaniand5e47f62017-03-15 14:41:07 -070079 public void onAnswer(boolean answerVideoAsAudio) {
Eric Erfanianccca3152017-02-22 16:32:36 -080080 if (answerScreen.isVideoUpgradeRequest()) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -070081 if (answerVideoAsAudio) {
Eric Erfanian8369df02017-05-03 10:27:13 -070082 Logger.get(context)
83 .logCallImpression(
84 DialerImpression.Type.VIDEO_CALL_REQUEST_ACCEPTED_AS_AUDIO,
85 call.getUniqueCallId(),
86 call.getTimeAddedMs());
Eric Erfaniand5e47f62017-03-15 14:41:07 -070087 call.getVideoTech().acceptVideoRequestAsAudio();
88 } else {
Eric Erfanian8369df02017-05-03 10:27:13 -070089 Logger.get(context)
90 .logCallImpression(
91 DialerImpression.Type.VIDEO_CALL_REQUEST_ACCEPTED,
92 call.getUniqueCallId(),
93 call.getTimeAddedMs());
Eric Erfaniand5e47f62017-03-15 14:41:07 -070094 call.getVideoTech().acceptVideoRequest();
95 }
Eric Erfanianccca3152017-02-22 16:32:36 -080096 } else {
Eric Erfaniand5e47f62017-03-15 14:41:07 -070097 if (answerVideoAsAudio) {
98 call.answer(VideoProfile.STATE_AUDIO_ONLY);
99 } else {
100 call.answer();
101 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800102 }
103 }
104
105 @Override
106 public void onReject() {
107 if (answerScreen.isVideoUpgradeRequest()) {
Eric Erfanian8369df02017-05-03 10:27:13 -0700108 Logger.get(context)
109 .logCallImpression(
110 DialerImpression.Type.VIDEO_CALL_REQUEST_DECLINED,
111 call.getUniqueCallId(),
112 call.getTimeAddedMs());
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700113 call.getVideoTech().declineVideoRequest();
Eric Erfanianccca3152017-02-22 16:32:36 -0800114 } else {
115 call.reject(false /* rejectWithMessage */, null);
116 }
117 }
118
119 @Override
Eric Erfanian90508232017-03-24 09:31:16 -0700120 public void onAnswerAndReleaseCall() {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700121 LogUtil.enterBlock("AnswerScreenPresenter.onAnswerAndReleaseCall");
Eric Erfanian90508232017-03-24 09:31:16 -0700122 DialerCall activeCall = CallList.getInstance().getActiveCall();
123 if (activeCall == null) {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700124 LogUtil.i("AnswerScreenPresenter.onAnswerAndReleaseCall", "activeCall == null");
Eric Erfanian90508232017-03-24 09:31:16 -0700125 onAnswer(false);
126 } else {
Eric Erfanian91ce7d22017-06-05 13:35:02 -0700127 activeCall.setReleasedByAnsweringSecondCall(true);
Eric Erfanian90508232017-03-24 09:31:16 -0700128 activeCall.addListener(new AnswerOnDisconnected(activeCall));
129 activeCall.disconnect();
130 }
131 }
132
133 @Override
Eric Erfanian91ce7d22017-06-05 13:35:02 -0700134 public void onAnswerAndReleaseButtonDisabled() {
135 DialerCall activeCall = CallList.getInstance().getActiveCall();
136 if (activeCall != null) {
137 activeCall.increaseSecondCallWithoutAnswerAndReleasedButtonTimes();
138 }
139 }
140
141 @Override
142 public void onAnswerAndReleaseButtonEnabled() {
143 DialerCall activeCall = CallList.getInstance().getActiveCall();
144 if (activeCall != null) {
145 activeCall.increaseAnswerAndReleaseButtonDisplayedTimes();
146 }
147 }
148
149 @Override
Eric Erfanianccca3152017-02-22 16:32:36 -0800150 public void onCannedTextResponsesLoaded(DialerCall call) {
151 if (isSmsResponseAllowed(call)) {
152 answerScreen.setTextResponses(call.getCannedSmsResponses());
153 }
154 }
155
156 @Override
157 public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) {
158 InCallActivity activity = (InCallActivity) answerScreen.getAnswerScreenFragment().getActivity();
159 if (activity != null) {
160 activity.updateWindowBackgroundColor(progress);
161 }
162 }
163
Eric Erfanian90508232017-03-24 09:31:16 -0700164 private class AnswerOnDisconnected implements DialerCallListener {
165
166 private final DialerCall disconnectingCall;
167
168 public AnswerOnDisconnected(DialerCall disconnectingCall) {
169 this.disconnectingCall = disconnectingCall;
170 }
171
172 @Override
173 public void onDialerCallDisconnect() {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700174 LogUtil.i(
175 "AnswerScreenPresenter.AnswerOnDisconnected", "call disconnected, answering new call");
Eric Erfanian90508232017-03-24 09:31:16 -0700176 call.answer();
177 disconnectingCall.removeListener(this);
178 }
179
180 @Override
181 public void onDialerCallUpdate() {}
182
183 @Override
184 public void onDialerCallChildNumberChange() {}
185
186 @Override
187 public void onDialerCallLastForwardedNumberChange() {}
188
189 @Override
190 public void onDialerCallUpgradeToVideo() {}
191
192 @Override
193 public void onDialerCallSessionModificationStateChange() {}
194
195 @Override
196 public void onWiFiToLteHandover() {}
197
198 @Override
199 public void onHandoverToWifiFailure() {}
Eric Erfanianc857f902017-05-15 14:05:33 -0700200
201 @Override
202 public void onInternationalCallOnWifi() {}
Eric Erfanian91ce7d22017-06-05 13:35:02 -0700203
204 @Override
205 public void onEnrichedCallSessionUpdate() {}
Eric Erfanian90508232017-03-24 09:31:16 -0700206 }
207
Eric Erfanianccca3152017-02-22 16:32:36 -0800208 private boolean isSmsResponseAllowed(DialerCall call) {
209 return UserManagerCompat.isUserUnlocked(context)
210 && call.can(android.telecom.Call.Details.CAPABILITY_RESPOND_VIA_TEXT);
211 }
212}