Remove duplicate call disconnect codes.
The Android code base defines call disconnect codes in three places:
- android.telephony.DisconnectCause
- android.internal.telephony.Connection.DisconnectCause
- com.android.services.telephony.common.Call.DisconnectCause
This CL consolidates the code to use the integer codes from
android.telephony.DisconnectCause everywhere.
Change-Id: I84a3fd5182a51d07fc7d81076e4b2c15ff26c61c
diff --git a/common/src/com/android/services/telephony/common/Call.java b/common/src/com/android/services/telephony/common/Call.java
index 4a74114..9bcf127 100644
--- a/common/src/com/android/services/telephony/common/Call.java
+++ b/common/src/com/android/services/telephony/common/Call.java
@@ -18,6 +18,7 @@
import android.os.Parcel;
import android.os.Parcelable;
+import android.telephony.DisconnectCause;
import com.android.internal.telephony.PhoneConstants;
import com.google.android.collect.Sets;
@@ -93,56 +94,6 @@
| RESPOND_VIA_TEXT | MUTE | GENERIC_CONFERENCE;
}
- /**
- * Copy of states found in Connection object since Connection object is not available to the UI
- * code.
- * TODO: Consider cutting this down to only the types used by the UI.
- * TODO: Consider adding a CUSTOM cause type and a customDisconnect member variable to
- * the Call object. This would allow OEMs to extend the cause list without
- * needing to alter our implementation.
- */
- public enum DisconnectCause {
- NOT_DISCONNECTED, /* has not yet disconnected */
- INCOMING_MISSED, /* an incoming call that was missed and never answered */
- NORMAL, /* normal; remote */
- LOCAL, /* normal; local hangup */
- BUSY, /* outgoing call to busy line */
- CONGESTION, /* outgoing call to congested network */
- MMI, /* not presently used; dial() returns null */
- INVALID_NUMBER, /* invalid dial string */
- NUMBER_UNREACHABLE, /* cannot reach the peer */
- SERVER_UNREACHABLE, /* cannot reach the server */
- INVALID_CREDENTIALS, /* invalid credentials */
- OUT_OF_NETWORK, /* calling from out of network is not allowed */
- SERVER_ERROR, /* server error */
- TIMED_OUT, /* client timed out */
- LOST_SIGNAL,
- LIMIT_EXCEEDED, /* eg GSM ACM limit exceeded */
- INCOMING_REJECTED, /* an incoming call that was rejected */
- POWER_OFF, /* radio is turned off explicitly */
- OUT_OF_SERVICE, /* out of service */
- ICC_ERROR, /* No ICC, ICC locked, or other ICC error */
- CALL_BARRED, /* call was blocked by call barring */
- FDN_BLOCKED, /* call was blocked by fixed dial number */
- CS_RESTRICTED, /* call was blocked by restricted all voice access */
- CS_RESTRICTED_NORMAL, /* call was blocked by restricted normal voice access */
- CS_RESTRICTED_EMERGENCY, /* call was blocked by restricted emergency voice access */
- UNOBTAINABLE_NUMBER, /* Unassigned number (3GPP TS 24.008 table 10.5.123) */
- CDMA_LOCKED_UNTIL_POWER_CYCLE, /* MS is locked until next power cycle */
- CDMA_DROP,
- CDMA_INTERCEPT, /* INTERCEPT order received, MS state idle entered */
- CDMA_REORDER, /* MS has been redirected, call is cancelled */
- CDMA_SO_REJECT, /* service option rejection */
- CDMA_RETRY_ORDER, /* requested service is rejected, retry delay is set */
- CDMA_ACCESS_FAILURE,
- CDMA_PREEMPTED,
- CDMA_NOT_EMERGENCY, /* not an emergency call */
- CDMA_ACCESS_BLOCKED, /* Access Blocked by CDMA network */
- ERROR_UNSPECIFIED,
-
- UNKNOWN /* Disconnect cause doesn't map to any above */
- }
-
private static final Map<Integer, String> STATE_MAP = ImmutableMap.<Integer, String>builder()
.put(Call.State.ACTIVE, "ACTIVE")
.put(Call.State.CALL_WAITING, "CALL_WAITING")
@@ -176,7 +127,8 @@
private int mState = State.INVALID;
// Reason for disconnect. Valid when the call state is DISCONNECTED.
- private DisconnectCause mDisconnectCause = DisconnectCause.UNKNOWN;
+ // Valid values are defined in {@link DisconnectCause}.
+ private int mDisconnectCause = DisconnectCause.NOT_VALID;
// Bit mask of capabilities unique to this call.
private int mCapabilities;
@@ -258,7 +210,8 @@
mIdentification.setCnapName(cnapName);
}
- public DisconnectCause getDisconnectCause() {
+ /** Returns call disconnect cause; values are defined in {@link DisconnectCause}. */
+ public int getDisconnectCause() {
if (mState == State.DISCONNECTED || mState == State.IDLE) {
return mDisconnectCause;
}
@@ -266,7 +219,8 @@
return DisconnectCause.NOT_DISCONNECTED;
}
- public void setDisconnectCause(DisconnectCause cause) {
+ /** Sets the call disconnect cause; values are defined in {@link DisconnectCause}. */
+ public void setDisconnectCause(int cause) {
mDisconnectCause = cause;
}
@@ -338,7 +292,7 @@
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mCallId);
dest.writeInt(mState);
- dest.writeString(getDisconnectCause().toString());
+ dest.writeInt(getDisconnectCause());
dest.writeInt(getCapabilities());
dest.writeLong(getConnectTime());
dest.writeIntArray(Ints.toArray(mChildCallIds));
@@ -353,7 +307,7 @@
private Call(Parcel in) {
mCallId = in.readInt();
mState = in.readInt();
- mDisconnectCause = DisconnectCause.valueOf(in.readString());
+ mDisconnectCause = in.readInt();
mCapabilities = in.readInt();
mConnectTime = in.readLong();
mChildCallIds.addAll(Ints.asList(in.createIntArray()));
diff --git a/src/com/android/phone/CallLogger.java b/src/com/android/phone/CallLogger.java
index 644812f..9e76db4 100644
--- a/src/com/android/phone/CallLogger.java
+++ b/src/com/android/phone/CallLogger.java
@@ -26,6 +26,7 @@
import android.net.Uri;
import android.os.SystemProperties;
import android.provider.CallLog.Calls;
+import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.util.Log;
@@ -87,13 +88,13 @@
* Came as logCall(Connection,int) but calculates the call type from the connection object.
*/
public void logCall(Connection c) {
- final Connection.DisconnectCause cause = c.getDisconnectCause();
+ final int cause = c.getDisconnectCause();
// Set the "type" to be displayed in the call log (see constants in CallLog.Calls)
final int callLogType;
if (c.isIncoming()) {
- callLogType = (cause == Connection.DisconnectCause.INCOMING_MISSED ?
+ callLogType = (cause == DisconnectCause.INCOMING_MISSED ?
Calls.MISSED_TYPE : Calls.INCOMING_TYPE);
} else {
callLogType = Calls.OUTGOING_TYPE;
diff --git a/src/com/android/phone/CallModeler.java b/src/com/android/phone/CallModeler.java
index e4ed147..72eaed0 100644
--- a/src/com/android/phone/CallModeler.java
+++ b/src/com/android/phone/CallModeler.java
@@ -20,6 +20,7 @@
import android.os.Handler;
import android.os.Message;
import android.os.SystemProperties;
+import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.util.Log;
@@ -38,7 +39,6 @@
import com.google.android.collect.Maps;
import com.google.android.collect.Sets;
import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Lists;
@@ -555,8 +555,7 @@
changed = true;
}
- final Call.DisconnectCause newDisconnectCause =
- translateDisconnectCauseFromTelephony(connection.getDisconnectCause());
+ final int newDisconnectCause = connection.getDisconnectCause();
if (call.getDisconnectCause() != newDisconnectCause) {
call.setDisconnectCause(newDisconnectCause);
changed = true;
@@ -789,73 +788,6 @@
return retval;
}
- private final ImmutableMap<Connection.DisconnectCause, Call.DisconnectCause> CAUSE_MAP =
- ImmutableMap.<Connection.DisconnectCause, Call.DisconnectCause>builder()
- .put(Connection.DisconnectCause.BUSY, Call.DisconnectCause.BUSY)
- .put(Connection.DisconnectCause.CALL_BARRED, Call.DisconnectCause.CALL_BARRED)
- .put(Connection.DisconnectCause.CDMA_ACCESS_BLOCKED,
- Call.DisconnectCause.CDMA_ACCESS_BLOCKED)
- .put(Connection.DisconnectCause.CDMA_ACCESS_FAILURE,
- Call.DisconnectCause.CDMA_ACCESS_FAILURE)
- .put(Connection.DisconnectCause.CDMA_DROP, Call.DisconnectCause.CDMA_DROP)
- .put(Connection.DisconnectCause.CDMA_INTERCEPT, Call.DisconnectCause.CDMA_INTERCEPT)
- .put(Connection.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE,
- Call.DisconnectCause.CDMA_LOCKED_UNTIL_POWER_CYCLE)
- .put(Connection.DisconnectCause.CDMA_NOT_EMERGENCY,
- Call.DisconnectCause.CDMA_NOT_EMERGENCY)
- .put(Connection.DisconnectCause.CDMA_PREEMPTED, Call.DisconnectCause.CDMA_PREEMPTED)
- .put(Connection.DisconnectCause.CDMA_REORDER, Call.DisconnectCause.CDMA_REORDER)
- .put(Connection.DisconnectCause.CDMA_RETRY_ORDER,
- Call.DisconnectCause.CDMA_RETRY_ORDER)
- .put(Connection.DisconnectCause.CDMA_SO_REJECT, Call.DisconnectCause.CDMA_SO_REJECT)
- .put(Connection.DisconnectCause.CONGESTION, Call.DisconnectCause.CONGESTION)
- .put(Connection.DisconnectCause.CS_RESTRICTED, Call.DisconnectCause.CS_RESTRICTED)
- .put(Connection.DisconnectCause.CS_RESTRICTED_EMERGENCY,
- Call.DisconnectCause.CS_RESTRICTED_EMERGENCY)
- .put(Connection.DisconnectCause.CS_RESTRICTED_NORMAL,
- Call.DisconnectCause.CS_RESTRICTED_NORMAL)
- .put(Connection.DisconnectCause.ERROR_UNSPECIFIED,
- Call.DisconnectCause.ERROR_UNSPECIFIED)
- .put(Connection.DisconnectCause.FDN_BLOCKED, Call.DisconnectCause.FDN_BLOCKED)
- .put(Connection.DisconnectCause.ICC_ERROR, Call.DisconnectCause.ICC_ERROR)
- .put(Connection.DisconnectCause.INCOMING_MISSED,
- Call.DisconnectCause.INCOMING_MISSED)
- .put(Connection.DisconnectCause.INCOMING_REJECTED,
- Call.DisconnectCause.INCOMING_REJECTED)
- .put(Connection.DisconnectCause.INVALID_CREDENTIALS,
- Call.DisconnectCause.INVALID_CREDENTIALS)
- .put(Connection.DisconnectCause.INVALID_NUMBER,
- Call.DisconnectCause.INVALID_NUMBER)
- .put(Connection.DisconnectCause.LIMIT_EXCEEDED, Call.DisconnectCause.LIMIT_EXCEEDED)
- .put(Connection.DisconnectCause.LOCAL, Call.DisconnectCause.LOCAL)
- .put(Connection.DisconnectCause.LOST_SIGNAL, Call.DisconnectCause.LOST_SIGNAL)
- .put(Connection.DisconnectCause.MMI, Call.DisconnectCause.MMI)
- .put(Connection.DisconnectCause.NORMAL, Call.DisconnectCause.NORMAL)
- .put(Connection.DisconnectCause.NOT_DISCONNECTED,
- Call.DisconnectCause.NOT_DISCONNECTED)
- .put(Connection.DisconnectCause.NUMBER_UNREACHABLE,
- Call.DisconnectCause.NUMBER_UNREACHABLE)
- .put(Connection.DisconnectCause.OUT_OF_NETWORK, Call.DisconnectCause.OUT_OF_NETWORK)
- .put(Connection.DisconnectCause.OUT_OF_SERVICE, Call.DisconnectCause.OUT_OF_SERVICE)
- .put(Connection.DisconnectCause.POWER_OFF, Call.DisconnectCause.POWER_OFF)
- .put(Connection.DisconnectCause.SERVER_ERROR, Call.DisconnectCause.SERVER_ERROR)
- .put(Connection.DisconnectCause.SERVER_UNREACHABLE,
- Call.DisconnectCause.SERVER_UNREACHABLE)
- .put(Connection.DisconnectCause.TIMED_OUT, Call.DisconnectCause.TIMED_OUT)
- .put(Connection.DisconnectCause.UNOBTAINABLE_NUMBER,
- Call.DisconnectCause.UNOBTAINABLE_NUMBER)
- .build();
-
- private Call.DisconnectCause translateDisconnectCauseFromTelephony(
- Connection.DisconnectCause causeSource) {
-
- if (CAUSE_MAP.containsKey(causeSource)) {
- return CAUSE_MAP.get(causeSource);
- }
-
- return Call.DisconnectCause.UNKNOWN;
- }
-
/**
* Gets an existing callId for a connection, or creates one if none exists.
* This function does NOT set any of the Connection data onto the Call class.
diff --git a/src/com/android/phone/CallNotifier.java b/src/com/android/phone/CallNotifier.java
index 80807a2..aa4270e 100644
--- a/src/com/android/phone/CallNotifier.java
+++ b/src/com/android/phone/CallNotifier.java
@@ -46,6 +46,7 @@
import android.os.Vibrator;
import android.provider.CallLog.Calls;
import android.provider.Settings;
+import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
@@ -899,7 +900,7 @@
mVoicePrivacyState = false;
Connection c = (Connection) r.result;
if (c != null) {
- log("onDisconnect: cause = " + c.getDisconnectCause()
+ log("onDisconnect: cause = " + DisconnectCause.toString(c.getDisconnectCause())
+ ", incoming = " + c.isIncoming()
+ ", date = " + c.getCreateTime());
} else {
@@ -974,34 +975,34 @@
// The "Busy" or "Congestion" tone is the highest priority:
if (c != null) {
- Connection.DisconnectCause cause = c.getDisconnectCause();
- if (cause == Connection.DisconnectCause.BUSY) {
+ int cause = c.getDisconnectCause();
+ if (cause == DisconnectCause.BUSY) {
if (DBG) log("- need to play BUSY tone!");
toneToPlay = InCallTonePlayer.TONE_BUSY;
- } else if (cause == Connection.DisconnectCause.CONGESTION) {
+ } else if (cause == DisconnectCause.CONGESTION) {
if (DBG) log("- need to play CONGESTION tone!");
toneToPlay = InCallTonePlayer.TONE_CONGESTION;
- } else if (((cause == Connection.DisconnectCause.NORMAL)
- || (cause == Connection.DisconnectCause.LOCAL))
+ } else if (((cause == DisconnectCause.NORMAL)
+ || (cause == DisconnectCause.LOCAL))
&& (mApplication.isOtaCallInActiveState())) {
if (DBG) log("- need to play OTA_CALL_END tone!");
toneToPlay = InCallTonePlayer.TONE_OTA_CALL_END;
- } else if (cause == Connection.DisconnectCause.CDMA_REORDER) {
+ } else if (cause == DisconnectCause.CDMA_REORDER) {
if (DBG) log("- need to play CDMA_REORDER tone!");
toneToPlay = InCallTonePlayer.TONE_REORDER;
- } else if (cause == Connection.DisconnectCause.CDMA_INTERCEPT) {
+ } else if (cause == DisconnectCause.CDMA_INTERCEPT) {
if (DBG) log("- need to play CDMA_INTERCEPT tone!");
toneToPlay = InCallTonePlayer.TONE_INTERCEPT;
- } else if (cause == Connection.DisconnectCause.CDMA_DROP) {
+ } else if (cause == DisconnectCause.CDMA_DROP) {
if (DBG) log("- need to play CDMA_DROP tone!");
toneToPlay = InCallTonePlayer.TONE_CDMA_DROP;
- } else if (cause == Connection.DisconnectCause.OUT_OF_SERVICE) {
+ } else if (cause == DisconnectCause.OUT_OF_SERVICE) {
if (DBG) log("- need to play OUT OF SERVICE tone!");
toneToPlay = InCallTonePlayer.TONE_OUT_OF_SERVICE;
- } else if (cause == Connection.DisconnectCause.UNOBTAINABLE_NUMBER) {
+ } else if (cause == DisconnectCause.UNOBTAINABLE_NUMBER) {
if (DBG) log("- need to play TONE_UNOBTAINABLE_NUMBER tone!");
toneToPlay = InCallTonePlayer.TONE_UNOBTAINABLE_NUMBER;
- } else if (cause == Connection.DisconnectCause.ERROR_UNSPECIFIED) {
+ } else if (cause == DisconnectCause.ERROR_UNSPECIFIED) {
if (DBG) log("- DisconnectCause is ERROR_UNSPECIFIED: play TONE_CALL_ENDED!");
toneToPlay = InCallTonePlayer.TONE_CALL_ENDED;
}
@@ -1017,9 +1018,9 @@
if ((toneToPlay == InCallTonePlayer.TONE_NONE)
&& (mCM.getState() == PhoneConstants.State.IDLE)
&& (c != null)) {
- Connection.DisconnectCause cause = c.getDisconnectCause();
- if ((cause == Connection.DisconnectCause.NORMAL) // remote hangup
- || (cause == Connection.DisconnectCause.LOCAL)) { // local hangup
+ int cause = c.getDisconnectCause();
+ if ((cause == DisconnectCause.NORMAL) // remote hangup
+ || (cause == DisconnectCause.LOCAL)) { // local hangup
if (VDBG) log("- need to play CALL_ENDED tone!");
toneToPlay = InCallTonePlayer.TONE_CALL_ENDED;
mIsCdmaRedialCall = false;
@@ -1055,9 +1056,9 @@
}
final long date = c.getCreateTime();
- final Connection.DisconnectCause cause = c.getDisconnectCause();
+ final int cause = c.getDisconnectCause();
final boolean missedCall = c.isIncoming() &&
- (cause == Connection.DisconnectCause.INCOMING_MISSED);
+ (cause == DisconnectCause.INCOMING_MISSED);
if (missedCall) {
// Show the "Missed call" notification.
// (Note we *don't* do this if this was an incoming call that
@@ -1086,10 +1087,10 @@
if (((mPreviousCdmaCallState == Call.State.DIALING)
|| (mPreviousCdmaCallState == Call.State.ALERTING))
&& (!isEmergencyNumber)
- && (cause != Connection.DisconnectCause.INCOMING_MISSED )
- && (cause != Connection.DisconnectCause.NORMAL)
- && (cause != Connection.DisconnectCause.LOCAL)
- && (cause != Connection.DisconnectCause.INCOMING_REJECTED)) {
+ && (cause != DisconnectCause.INCOMING_MISSED )
+ && (cause != DisconnectCause.NORMAL)
+ && (cause != DisconnectCause.LOCAL)
+ && (cause != DisconnectCause.INCOMING_REJECTED)) {
if (!mIsCdmaRedialCall) {
if (autoretrySetting == InCallScreen.AUTO_RETRY_ON) {
// TODO: (Moto): The contact reference data may need to be stored and use
diff --git a/src/com/android/phone/EmergencyCallHelper.java b/src/com/android/phone/EmergencyCallHelper.java
index 47f0e54..74ce088 100644
--- a/src/com/android/phone/EmergencyCallHelper.java
+++ b/src/com/android/phone/EmergencyCallHelper.java
@@ -29,6 +29,7 @@
import android.os.PowerManager;
import android.os.UserHandle;
import android.provider.Settings;
+import android.telephony.DisconnectCause;
import android.telephony.ServiceState;
import android.util.Log;
@@ -234,11 +235,12 @@
*/
private void onDisconnect(Message msg) {
Connection conn = (Connection) ((AsyncResult) msg.obj).result;
- Connection.DisconnectCause cause = conn.getDisconnectCause();
+ int cause = conn.getDisconnectCause();
if (DBG) log("onDisconnect: connection '" + conn
- + "', addr '" + conn.getAddress() + "', cause = " + cause);
+ + "', addr '" + conn.getAddress()
+ + "', cause = " + DisconnectCause.toString(cause));
- if (cause == Connection.DisconnectCause.OUT_OF_SERVICE) {
+ if (cause == DisconnectCause.OUT_OF_SERVICE) {
// Wait a bit more and try again (or just bail out totally if
// we've had too many failures.)
if (DBG) log("- onDisconnect: OUT_OF_SERVICE, need to retry...");