blob: 77b472b391c6f3d85b7afc99c3eb2041fe1547e4 [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;
26import com.android.incallui.answer.protocol.AnswerScreen;
27import com.android.incallui.answer.protocol.AnswerScreenDelegate;
28import com.android.incallui.answerproximitysensor.AnswerProximitySensor;
29import com.android.incallui.answerproximitysensor.PseudoScreenState;
Eric Erfanian90508232017-03-24 09:31:16 -070030import com.android.incallui.call.CallList;
Eric Erfanianccca3152017-02-22 16:32:36 -080031import com.android.incallui.call.DialerCall;
Eric Erfanian90508232017-03-24 09:31:16 -070032import com.android.incallui.call.DialerCallListener;
Eric Erfanianccca3152017-02-22 16:32:36 -080033
34/** Manages changes for an incoming call screen. */
35public class AnswerScreenPresenter
36 implements AnswerScreenDelegate, DialerCall.CannedTextResponsesLoadedListener {
37 @NonNull private final Context context;
38 @NonNull private final AnswerScreen answerScreen;
39 @NonNull private final DialerCall call;
40
41 public AnswerScreenPresenter(
42 @NonNull Context context, @NonNull AnswerScreen answerScreen, @NonNull DialerCall call) {
43 LogUtil.i("AnswerScreenPresenter.constructor", null);
44 this.context = Assert.isNotNull(context);
45 this.answerScreen = Assert.isNotNull(answerScreen);
46 this.call = Assert.isNotNull(call);
47 if (isSmsResponseAllowed(call)) {
48 answerScreen.setTextResponses(call.getCannedSmsResponses());
49 }
50 call.addCannedTextResponsesLoadedListener(this);
51
52 PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState();
53 if (AnswerProximitySensor.shouldUse(context, call)) {
54 new AnswerProximitySensor(context, call, pseudoScreenState);
55 } else {
56 pseudoScreenState.setOn(true);
57 }
58 }
59
60 @Override
61 public void onAnswerScreenUnready() {
62 call.removeCannedTextResponsesLoadedListener(this);
63 }
64
65 @Override
66 public void onDismissDialog() {
67 InCallPresenter.getInstance().onDismissDialog();
68 }
69
70 @Override
71 public void onRejectCallWithMessage(String message) {
72 call.reject(true /* rejectWithMessage */, message);
73 onDismissDialog();
74 }
75
76 @Override
Eric Erfaniand5e47f62017-03-15 14:41:07 -070077 public void onAnswer(boolean answerVideoAsAudio) {
Eric Erfanianccca3152017-02-22 16:32:36 -080078 if (answerScreen.isVideoUpgradeRequest()) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -070079 if (answerVideoAsAudio) {
80 call.getVideoTech().acceptVideoRequestAsAudio();
81 } else {
82 call.getVideoTech().acceptVideoRequest();
83 }
Eric Erfanianccca3152017-02-22 16:32:36 -080084 } else {
Eric Erfaniand5e47f62017-03-15 14:41:07 -070085 if (answerVideoAsAudio) {
86 call.answer(VideoProfile.STATE_AUDIO_ONLY);
87 } else {
88 call.answer();
89 }
Eric Erfanianccca3152017-02-22 16:32:36 -080090 }
91 }
92
93 @Override
94 public void onReject() {
95 if (answerScreen.isVideoUpgradeRequest()) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -070096 call.getVideoTech().declineVideoRequest();
Eric Erfanianccca3152017-02-22 16:32:36 -080097 } else {
98 call.reject(false /* rejectWithMessage */, null);
99 }
100 }
101
102 @Override
Eric Erfanian90508232017-03-24 09:31:16 -0700103 public void onAnswerAndReleaseCall() {
104 Log.i("AnswerScreenPresenter.onAnswerAndReleaseCall", "enterBlock");
105 DialerCall activeCall = CallList.getInstance().getActiveCall();
106 if (activeCall == null) {
107 Log.i("AnswerScreenPresenter.onAnswerAndReleaseCall", "activeCall == null");
108 onAnswer(false);
109 } else {
110 activeCall.addListener(new AnswerOnDisconnected(activeCall));
111 activeCall.disconnect();
112 }
113 }
114
115 @Override
Eric Erfanianccca3152017-02-22 16:32:36 -0800116 public void onCannedTextResponsesLoaded(DialerCall call) {
117 if (isSmsResponseAllowed(call)) {
118 answerScreen.setTextResponses(call.getCannedSmsResponses());
119 }
120 }
121
122 @Override
123 public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) {
124 InCallActivity activity = (InCallActivity) answerScreen.getAnswerScreenFragment().getActivity();
125 if (activity != null) {
126 activity.updateWindowBackgroundColor(progress);
127 }
128 }
129
Eric Erfanian90508232017-03-24 09:31:16 -0700130 private class AnswerOnDisconnected implements DialerCallListener {
131
132 private final DialerCall disconnectingCall;
133
134 public AnswerOnDisconnected(DialerCall disconnectingCall) {
135 this.disconnectingCall = disconnectingCall;
136 }
137
138 @Override
139 public void onDialerCallDisconnect() {
140 Log.i("AnswerScreenPresenter.AnswerOnDisconnected", "Call disconnected, answering new call");
141 call.answer();
142 disconnectingCall.removeListener(this);
143 }
144
145 @Override
146 public void onDialerCallUpdate() {}
147
148 @Override
149 public void onDialerCallChildNumberChange() {}
150
151 @Override
152 public void onDialerCallLastForwardedNumberChange() {}
153
154 @Override
155 public void onDialerCallUpgradeToVideo() {}
156
157 @Override
158 public void onDialerCallSessionModificationStateChange() {}
159
160 @Override
161 public void onWiFiToLteHandover() {}
162
163 @Override
164 public void onHandoverToWifiFailure() {}
165 }
166
Eric Erfanianccca3152017-02-22 16:32:36 -0800167 private boolean isSmsResponseAllowed(DialerCall call) {
168 return UserManagerCompat.isUserUnlocked(context)
169 && call.can(android.telecom.Call.Details.CAPABILITY_RESPOND_VIA_TEXT);
170 }
171}