Fixing Google Voice to work with new incallui
We were not previously storing and sending the gateway information to
the UI. This change consolidates Call gateway functionality from
InCallUiState and PhoneUtils into a new class CallGatewayManager. It is
responsible for storing a mapping from the call's connection to the
gateway used to make that connection. It also adds gateway packagename
and number to the Call object sent to the UI so that it can show UI
appropriately.
bug: 10393622
Change-Id: Ic5a0b068475bcab60e8cc96470273e36005ccc2e
diff --git a/src/com/android/phone/CallModeler.java b/src/com/android/phone/CallModeler.java
index 89dcb21..a5e2044 100644
--- a/src/com/android/phone/CallModeler.java
+++ b/src/com/android/phone/CallModeler.java
@@ -35,6 +35,7 @@
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyCapabilities;
+import com.android.phone.CallGatewayManager.RawGatewayInfo;
import com.android.services.telephony.common.Call;
import com.android.services.telephony.common.Call.Capabilities;
import com.android.services.telephony.common.Call.State;
@@ -84,6 +85,7 @@
private final CallStateMonitor mCallStateMonitor;
private final CallManager mCallManager;
+ private final CallGatewayManager mCallGatewayManager;
private final HashMap<Connection, Call> mCallMap = Maps.newHashMap();
private final HashMap<Connection, Call> mConfCallMap = Maps.newHashMap();
private final AtomicInteger mNextCallId = new AtomicInteger(CALL_ID_START_VALUE);
@@ -91,10 +93,12 @@
private RejectWithTextMessageManager mRejectWithTextMessageManager;
public CallModeler(CallStateMonitor callStateMonitor, CallManager callManager,
- RejectWithTextMessageManager rejectWithTextMessageManager) {
+ RejectWithTextMessageManager rejectWithTextMessageManager,
+ CallGatewayManager callGatewayManager) {
mCallStateMonitor = callStateMonitor;
mCallManager = callManager;
mRejectWithTextMessageManager = rejectWithTextMessageManager;
+ mCallGatewayManager = callGatewayManager;
mCallStateMonitor.addListener(this);
}
@@ -330,6 +334,29 @@
}
/**
+ * Sets the new call state onto the call and performs some additional logic
+ * associated with setting the state.
+ */
+ private void setNewState(Call call, int newState, Connection connection) {
+ Preconditions.checkState(call.getState() != newState);
+
+ // When starting an outgoing call, we need to grab gateway information
+ // for the call, if available, and set it.
+ final RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
+
+ if (newState == Call.State.DIALING) {
+ if (!info.isEmpty()) {
+ call.setGatewayNumber(info.getFormattedGatewayNumber());
+ call.setGatewayPackage(info.packageName);
+ }
+ } else if (!Call.State.isConnected(newState)) {
+ mCallGatewayManager.clearGatewayData(connection);
+ }
+
+ call.setState(newState);
+ }
+
+ /**
* Updates the Call properties to match the state of the connection object
* that it represents.
* @param call The call object to update.
@@ -344,7 +371,7 @@
final int newState = translateStateFromTelephony(connection, isForConference);
if (call.getState() != newState) {
- call.setState(newState);
+ setNewState(call, newState, connection);
changed = true;
}
@@ -362,29 +389,38 @@
}
if (!isForConference) {
+ // Number
final String oldNumber = call.getNumber();
- if (TextUtils.isEmpty(oldNumber) || !oldNumber.equals(connection.getAddress())) {
- call.setNumber(connection.getAddress());
+ String newNumber = connection.getAddress();
+ RawGatewayInfo info = mCallGatewayManager.getGatewayInfo(connection);
+ if (!info.isEmpty()) {
+ newNumber = info.trueNumber;
+ }
+ if (TextUtils.isEmpty(oldNumber) || !oldNumber.equals(newNumber)) {
+ call.setNumber(newNumber);
changed = true;
}
+ // Number presentation
final int newNumberPresentation = connection.getNumberPresentation();
if (call.getNumberPresentation() != newNumberPresentation) {
call.setNumberPresentation(newNumberPresentation);
changed = true;
}
- final int newCnapNamePresentation = connection.getCnapNamePresentation();
- if (call.getCnapNamePresentation() != newCnapNamePresentation) {
- call.setCnapNamePresentation(newCnapNamePresentation);
- changed = true;
- }
-
+ // Name
final String oldCnapName = call.getCnapName();
if (TextUtils.isEmpty(oldCnapName) || !oldCnapName.equals(connection.getCnapName())) {
call.setCnapName(connection.getCnapName());
changed = true;
}
+
+ // Name Presentation
+ final int newCnapNamePresentation = connection.getCnapNamePresentation();
+ if (call.getCnapNamePresentation() != newCnapNamePresentation) {
+ call.setCnapNamePresentation(newCnapNamePresentation);
+ changed = true;
+ }
} else {
// update the list of children by: