• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 
17 package com.android.incallui;
18 
19 import com.android.incallui.ConferenceManagerPresenter.ConferenceManagerUi;
20 import com.android.incallui.InCallPresenter.InCallDetailsListener;
21 import com.android.incallui.InCallPresenter.InCallState;
22 import com.android.incallui.InCallPresenter.InCallStateListener;
23 import com.android.incallui.InCallPresenter.IncomingCallListener;
24 import com.android.incallui.baseui.Presenter;
25 import com.android.incallui.baseui.Ui;
26 import com.android.incallui.call.CallList;
27 import com.android.incallui.call.DialerCall;
28 import java.util.ArrayList;
29 import java.util.List;
30 
31 /** Logic for call buttons. */
32 public class ConferenceManagerPresenter extends Presenter<ConferenceManagerUi>
33     implements InCallStateListener, InCallDetailsListener, IncomingCallListener {
34 
35   @Override
onUiReady(ConferenceManagerUi ui)36   public void onUiReady(ConferenceManagerUi ui) {
37     super.onUiReady(ui);
38 
39     // register for call state changes last
40     InCallPresenter.getInstance().addListener(this);
41     InCallPresenter.getInstance().addIncomingCallListener(this);
42   }
43 
44   @Override
onUiUnready(ConferenceManagerUi ui)45   public void onUiUnready(ConferenceManagerUi ui) {
46     super.onUiUnready(ui);
47 
48     InCallPresenter.getInstance().removeListener(this);
49     InCallPresenter.getInstance().removeIncomingCallListener(this);
50   }
51 
52   @Override
onStateChange(InCallState oldState, InCallState newState, CallList callList)53   public void onStateChange(InCallState oldState, InCallState newState, CallList callList) {
54     if (getUi().isFragmentVisible()) {
55       Log.v(this, "onStateChange" + newState);
56       if (newState == InCallState.INCALL) {
57         final DialerCall call = callList.getActiveOrBackgroundCall();
58         if (call != null && call.isConferenceCall()) {
59           Log.v(
60               this, "Number of existing calls is " + String.valueOf(call.getChildCallIds().size()));
61           update(callList);
62         } else {
63           InCallPresenter.getInstance().showConferenceCallManager(false);
64         }
65       } else {
66         InCallPresenter.getInstance().showConferenceCallManager(false);
67       }
68     }
69   }
70 
71   @Override
onDetailsChanged(DialerCall call, android.telecom.Call.Details details)72   public void onDetailsChanged(DialerCall call, android.telecom.Call.Details details) {
73     boolean canDisconnect =
74         details.can(android.telecom.Call.Details.CAPABILITY_DISCONNECT_FROM_CONFERENCE);
75     boolean canSeparate =
76         details.can(android.telecom.Call.Details.CAPABILITY_SEPARATE_FROM_CONFERENCE);
77 
78     if (call.can(android.telecom.Call.Details.CAPABILITY_DISCONNECT_FROM_CONFERENCE)
79             != canDisconnect
80         || call.can(android.telecom.Call.Details.CAPABILITY_SEPARATE_FROM_CONFERENCE)
81             != canSeparate) {
82       getUi().refreshCall(call);
83     }
84 
85     if (!details.can(android.telecom.Call.Details.CAPABILITY_MANAGE_CONFERENCE)) {
86       InCallPresenter.getInstance().showConferenceCallManager(false);
87     }
88   }
89 
90   @Override
onIncomingCall(InCallState oldState, InCallState newState, DialerCall call)91   public void onIncomingCall(InCallState oldState, InCallState newState, DialerCall call) {
92     // When incoming call exists, set conference ui invisible.
93     if (getUi().isFragmentVisible()) {
94       Log.d(this, "onIncomingCall()... Conference ui is showing, hide it.");
95       InCallPresenter.getInstance().showConferenceCallManager(false);
96     }
97   }
98 
init(CallList callList)99   public void init(CallList callList) {
100     update(callList);
101   }
102 
103   /**
104    * Updates the conference participant adapter.
105    *
106    * @param callList The callList.
107    */
update(CallList callList)108   private void update(CallList callList) {
109     // callList is non null, but getActiveOrBackgroundCall() may return null
110     final DialerCall currentCall = callList.getActiveOrBackgroundCall();
111     if (currentCall == null) {
112       return;
113     }
114 
115     ArrayList<DialerCall> calls = new ArrayList<>(currentCall.getChildCallIds().size());
116     for (String callerId : currentCall.getChildCallIds()) {
117       calls.add(callList.getCallById(callerId));
118     }
119 
120     Log.d(this, "Number of calls is " + String.valueOf(calls.size()));
121 
122     // Users can split out a call from the conference call if either the active call or the
123     // holding call is empty. If both are filled, users can not split out another call.
124     final boolean hasActiveCall = (callList.getActiveCall() != null);
125     final boolean hasHoldingCall = (callList.getBackgroundCall() != null);
126     boolean canSeparate = !(hasActiveCall && hasHoldingCall);
127 
128     getUi().update(calls, canSeparate);
129   }
130 
131   public interface ConferenceManagerUi extends Ui {
132 
isFragmentVisible()133     boolean isFragmentVisible();
134 
update(List<DialerCall> participants, boolean parentCanSeparate)135     void update(List<DialerCall> participants, boolean parentCanSeparate);
136 
refreshCall(DialerCall call)137     void refreshCall(DialerCall call);
138   }
139 }
140