2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.phone;
19 import android.telephony.PhoneNumberUtils;
20 import android.util.Log;
22 import com.android.internal.telephony.Call;
23 import com.android.internal.telephony.Connection;
24 import com.android.internal.telephony.Phone;
25 import com.android.internal.telephony.CallManager;
29 * Helper class to keep track of enabledness, visibility, and "on/off"
30 * or "checked" state of the various controls available in the in-call
31 * UI, based on the current telephony state.
33 * This class is independent of the exact UI controls used on any given
34 * device. (Some devices use onscreen touchable buttons, for example, and
35 * other devices use menu items.) To avoid cluttering up the InCallMenu
36 * and InCallTouchUi code with logic about which functions are available
37 * right now, we instead have that logic here, and provide simple boolean
38 * flags to indicate the state and/or enabledness of all possible in-call
41 * (In other words, this is the "model" that corresponds to the "view"
42 * implemented by InCallMenu and InCallTouchUi.)
44 public class InCallControlState {
45 private static final String LOG_TAG = "InCallControlState";
46 private static final boolean DBG = (PhoneApp.DBG_LEVEL >= 2);
48 private InCallScreen mInCallScreen;
49 private CallManager mCM;
52 // Our "public API": Boolean flags to indicate the state and/or
53 // enabledness of all possible in-call user operations:
56 public boolean manageConferenceVisible;
57 public boolean manageConferenceEnabled;
59 public boolean canAddCall;
61 public boolean canSwap;
62 public boolean canMerge;
64 public boolean bluetoothEnabled;
65 public boolean bluetoothIndicatorOn;
67 public boolean speakerEnabled;
68 public boolean speakerOn;
70 public boolean canMute;
71 public boolean muteIndicatorOn;
73 public boolean dialpadEnabled;
74 public boolean dialpadVisible;
76 /** True if the "Hold" function is *ever* available on this device */
77 public boolean supportsHold;
78 /** True if the call is currently on hold */
79 public boolean onHold;
80 /** True if the "Hold" or "Unhold" function should be available right now */
81 // TODO: this name is misleading. Let's break this apart into
82 // separate canHold and canUnhold flags, and have the caller look at
83 // "canHold || canUnhold" to decide whether the hold/unhold UI element
85 public boolean canHold;
88 public InCallControlState(InCallScreen inCallScreen, CallManager cm) {
89 if (DBG) log("InCallControlState constructor...");
90 mInCallScreen = inCallScreen;
95 * Updates all our public boolean flags based on the current state of
98 public void update() {
99 final Call fgCall = mCM.getActiveFgCall();
100 final Call.State fgCallState = fgCall.getState();
101 final boolean hasActiveForegroundCall = (fgCallState == Call.State.ACTIVE);
102 final boolean hasHoldingCall = mCM.hasActiveBgCall();
104 // Manage conference:
105 if (TelephonyCapabilities.supportsConferenceCallManagement(fgCall.getPhone())) {
106 // This item is visible only if the foreground call is a
107 // conference call, and it's enabled unless the "Manage
108 // conference" UI is already up.
109 manageConferenceVisible = PhoneUtils.isConferenceCall(fgCall);
110 manageConferenceEnabled =
111 manageConferenceVisible && !mInCallScreen.isManageConferenceMode();
113 // This device has no concept of managing a conference call.
114 manageConferenceVisible = false;
115 manageConferenceEnabled = false;
119 canAddCall = PhoneUtils.okToAddCall(mCM);
121 // Swap / merge calls
122 canSwap = PhoneUtils.okToSwapCalls(mCM);
123 canMerge = PhoneUtils.okToMergeCalls(mCM);
126 if (mInCallScreen.isBluetoothAvailable()) {
127 bluetoothEnabled = true;
128 bluetoothIndicatorOn = mInCallScreen.isBluetoothAudioConnectedOrPending();
130 bluetoothEnabled = false;
131 bluetoothIndicatorOn = false;
134 // "Speaker": always enabled.
135 // The current speaker state comes from the AudioManager.
136 speakerEnabled = true;
137 speakerOn = PhoneUtils.isSpeakerOn(mInCallScreen);
139 // "Mute": only enabled when the foreground call is ACTIVE.
140 // (It's meaningless while on hold, or while DIALING/ALERTING.)
141 // It's also explicitly disabled during emergency calls.
142 Connection c = fgCall.getLatestConnection();
143 boolean isEmergencyCall = false;
144 if (c != null) isEmergencyCall = PhoneNumberUtils.isEmergencyNumber(c.getAddress());
145 if (isEmergencyCall) { // disable "Mute" item
147 muteIndicatorOn = false;
149 canMute = hasActiveForegroundCall;
150 muteIndicatorOn = PhoneUtils.getMute();
153 // "Dialpad": Enabled only when it's OK to use the dialpad in the
155 dialpadEnabled = mInCallScreen.okToShowDialpad();
157 // Also keep track of whether the dialpad is currently "opened"
159 dialpadVisible = mInCallScreen.isDialerOpened();
162 if (TelephonyCapabilities.supportsHoldAndUnhold(fgCall.getPhone())) {
163 // This phone has the concept of explicit "Hold" and "Unhold" actions.
165 // "On hold" means that there's a holding call and
166 // *no* foreground call. (If there *is* a foreground call,
167 // that's "two lines in use".)
168 onHold = hasHoldingCall && (fgCallState == Call.State.IDLE);
169 // The "Hold" control is disabled entirely if there's
170 // no way to either hold or unhold in the current state.
171 boolean okToHold = hasActiveForegroundCall && !hasHoldingCall;
172 boolean okToUnhold = onHold;
173 canHold = okToHold || okToUnhold;
175 // This device has no concept of "putting a call on hold."
176 supportsHold = false;
181 if (DBG) dumpState();
184 public void dumpState() {
185 log("InCallControlState:");
186 log(" manageConferenceVisible: " + manageConferenceVisible);
187 log(" manageConferenceEnabled: " + manageConferenceEnabled);
188 log(" canAddCall: " + canAddCall);
189 log(" canSwap: " + canSwap);
190 log(" canMerge: " + canMerge);
191 log(" bluetoothEnabled: " + bluetoothEnabled);
192 log(" bluetoothIndicatorOn: " + bluetoothIndicatorOn);
193 log(" speakerEnabled: " + speakerEnabled);
194 log(" speakerOn: " + speakerOn);
195 log(" canMute: " + canMute);
196 log(" muteIndicatorOn: " + muteIndicatorOn);
197 log(" dialpadEnabled: " + dialpadEnabled);
198 log(" dialpadVisible: " + dialpadVisible);
199 log(" onHold: " + onHold);
200 log(" canHold: " + canHold);
203 private void log(String msg) {