blob: 442ad260f86d4e80f68edd2c2f060e2f4280bebf [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;
30import com.android.incallui.call.DialerCall;
31
32/** Manages changes for an incoming call screen. */
33public class AnswerScreenPresenter
34 implements AnswerScreenDelegate, DialerCall.CannedTextResponsesLoadedListener {
35 @NonNull private final Context context;
36 @NonNull private final AnswerScreen answerScreen;
37 @NonNull private final DialerCall call;
38
39 public AnswerScreenPresenter(
40 @NonNull Context context, @NonNull AnswerScreen answerScreen, @NonNull DialerCall call) {
41 LogUtil.i("AnswerScreenPresenter.constructor", null);
42 this.context = Assert.isNotNull(context);
43 this.answerScreen = Assert.isNotNull(answerScreen);
44 this.call = Assert.isNotNull(call);
45 if (isSmsResponseAllowed(call)) {
46 answerScreen.setTextResponses(call.getCannedSmsResponses());
47 }
48 call.addCannedTextResponsesLoadedListener(this);
49
50 PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState();
51 if (AnswerProximitySensor.shouldUse(context, call)) {
52 new AnswerProximitySensor(context, call, pseudoScreenState);
53 } else {
54 pseudoScreenState.setOn(true);
55 }
56 }
57
58 @Override
59 public void onAnswerScreenUnready() {
60 call.removeCannedTextResponsesLoadedListener(this);
61 }
62
63 @Override
64 public void onDismissDialog() {
65 InCallPresenter.getInstance().onDismissDialog();
66 }
67
68 @Override
69 public void onRejectCallWithMessage(String message) {
70 call.reject(true /* rejectWithMessage */, message);
71 onDismissDialog();
72 }
73
74 @Override
Eric Erfaniand5e47f62017-03-15 14:41:07 -070075 public void onAnswer(boolean answerVideoAsAudio) {
Eric Erfanianccca3152017-02-22 16:32:36 -080076 if (answerScreen.isVideoUpgradeRequest()) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -070077 if (answerVideoAsAudio) {
78 call.getVideoTech().acceptVideoRequestAsAudio();
79 } else {
80 call.getVideoTech().acceptVideoRequest();
81 }
Eric Erfanianccca3152017-02-22 16:32:36 -080082 } else {
Eric Erfaniand5e47f62017-03-15 14:41:07 -070083 if (answerVideoAsAudio) {
84 call.answer(VideoProfile.STATE_AUDIO_ONLY);
85 } else {
86 call.answer();
87 }
Eric Erfanianccca3152017-02-22 16:32:36 -080088 }
89 }
90
91 @Override
92 public void onReject() {
93 if (answerScreen.isVideoUpgradeRequest()) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -070094 call.getVideoTech().declineVideoRequest();
Eric Erfanianccca3152017-02-22 16:32:36 -080095 } else {
96 call.reject(false /* rejectWithMessage */, null);
97 }
98 }
99
100 @Override
101 public void onCannedTextResponsesLoaded(DialerCall call) {
102 if (isSmsResponseAllowed(call)) {
103 answerScreen.setTextResponses(call.getCannedSmsResponses());
104 }
105 }
106
107 @Override
108 public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) {
109 InCallActivity activity = (InCallActivity) answerScreen.getAnswerScreenFragment().getActivity();
110 if (activity != null) {
111 activity.updateWindowBackgroundColor(progress);
112 }
113 }
114
115 private boolean isSmsResponseAllowed(DialerCall call) {
116 return UserManagerCompat.isUserUnlocked(context)
117 && call.can(android.telecom.Call.Details.CAPABILITY_RESPOND_VIA_TEXT);
118 }
119}