blob: ca34aa6aa8b1096f62e20700f9dda9b3acabd6ab [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 {
127 activeCall.addListener(new AnswerOnDisconnected(activeCall));
128 activeCall.disconnect();
129 }
130 }
131
132 @Override
Eric Erfanianccca3152017-02-22 16:32:36 -0800133 public void onCannedTextResponsesLoaded(DialerCall call) {
134 if (isSmsResponseAllowed(call)) {
135 answerScreen.setTextResponses(call.getCannedSmsResponses());
136 }
137 }
138
139 @Override
140 public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) {
141 InCallActivity activity = (InCallActivity) answerScreen.getAnswerScreenFragment().getActivity();
142 if (activity != null) {
143 activity.updateWindowBackgroundColor(progress);
144 }
145 }
146
Eric Erfanian90508232017-03-24 09:31:16 -0700147 private class AnswerOnDisconnected implements DialerCallListener {
148
149 private final DialerCall disconnectingCall;
150
151 public AnswerOnDisconnected(DialerCall disconnectingCall) {
152 this.disconnectingCall = disconnectingCall;
153 }
154
155 @Override
156 public void onDialerCallDisconnect() {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700157 LogUtil.i(
158 "AnswerScreenPresenter.AnswerOnDisconnected", "call disconnected, answering new call");
Eric Erfanian90508232017-03-24 09:31:16 -0700159 call.answer();
160 disconnectingCall.removeListener(this);
161 }
162
163 @Override
164 public void onDialerCallUpdate() {}
165
166 @Override
167 public void onDialerCallChildNumberChange() {}
168
169 @Override
170 public void onDialerCallLastForwardedNumberChange() {}
171
172 @Override
173 public void onDialerCallUpgradeToVideo() {}
174
175 @Override
176 public void onDialerCallSessionModificationStateChange() {}
177
178 @Override
179 public void onWiFiToLteHandover() {}
180
181 @Override
182 public void onHandoverToWifiFailure() {}
Eric Erfanianc857f902017-05-15 14:05:33 -0700183
184 @Override
185 public void onInternationalCallOnWifi() {}
Eric Erfanian90508232017-03-24 09:31:16 -0700186 }
187
Eric Erfanianccca3152017-02-22 16:32:36 -0800188 private boolean isSmsResponseAllowed(DialerCall call) {
189 return UserManagerCompat.isUserUnlocked(context)
190 && call.can(android.telecom.Call.Details.CAPABILITY_RESPOND_VIA_TEXT);
191 }
192}