summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2010-07-25 00:17:12 -0700
committerHung-ying Tyan <tyanh@google.com>2010-07-26 21:40:43 -0700
commit15364d19dd1916677322d51e9a9ec973ef778c27 (patch)
treeda5805387e457094038e1c082e6e3a01a8a382ac
parent6b2fd7f2bac9e0c7e8679c5387a8b54d9e09af9a (diff)
downloadandroid_external_nist-sip-15364d19dd1916677322d51e9a9ec973ef778c27.tar.gz
android_external_nist-sip-15364d19dd1916677322d51e9a9ec973ef778c27.tar.bz2
android_external_nist-sip-15364d19dd1916677322d51e9a9ec973ef778c27.zip
SIP telephony: fix call log and connection stats.
+ get callerInfo from contact for creating correct call logs and displaying caller info on in-call screen. + update connection stats as state changes. Change-Id: I1c882f58b2114f0c096a8062bde991f88cf4b202
-rwxr-xr-xphone/src/com/android/phone2/CallNotifier.java26
-rw-r--r--phone/src/com/android/phone2/OutgoingCallBroadcaster.java51
-rw-r--r--phone/src2/com/android/internal/telephony/sip/SipConnectionBase.java22
-rwxr-xr-xphone/src2/com/android/internal/telephony/sip/SipPhone.java103
4 files changed, 158 insertions, 44 deletions
diff --git a/phone/src/com/android/phone2/CallNotifier.java b/phone/src/com/android/phone2/CallNotifier.java
index 99c8139..46676ab 100755
--- a/phone/src/com/android/phone2/CallNotifier.java
+++ b/phone/src/com/android/phone2/CallNotifier.java
@@ -1842,12 +1842,36 @@ public class CallNotifier extends Handler
// Do final CNAP modifications.
number = PhoneUtils.modifyForSpecialCnapCases(mPhone.getContext(), callerInfo,
number, presentation);
- number = PhoneNumberUtils.stripSeparators(number);
+
+ // TODO: SIP: integrate this to PhoneApp later
+ if (!isUri(number)) {
+ number = PhoneNumberUtils.stripSeparators(number);
+ } else {
+ // See which one is in the contact: entire URL or username only.
+ // Use that one to create the call log.
+ Context context = mPhone.getContext();
+ CallerInfo info = CallerInfo.getCallerInfo(context, number);
+ if ((info == null) || (info.name == null)) {
+ int index = number.indexOf("@");
+ if (index > 0) {
+ String number2 = number.substring(0, index);
+ info = CallerInfo.getCallerInfo(context, number2);
+ if ((info != null) && (info.name != null)) {
+ number = number2;
+ }
+ }
+ }
+ }
if (VDBG) log("getLogNumber: " + number);
return number;
}
}
+ private static boolean isUri(String number) {
+ // TODO: SIP: fix this after moving isUri() to PhoneNumberUtils
+ return OutgoingCallBroadcaster.isUri(number);
+ }
+
/**
* Get the caller info.
*
diff --git a/phone/src/com/android/phone2/OutgoingCallBroadcaster.java b/phone/src/com/android/phone2/OutgoingCallBroadcaster.java
index 524f7b1..0236645 100644
--- a/phone/src/com/android/phone2/OutgoingCallBroadcaster.java
+++ b/phone/src/com/android/phone2/OutgoingCallBroadcaster.java
@@ -199,12 +199,15 @@ public class OutgoingCallBroadcaster extends Activity {
String action = intent.getAction();
String number = PhoneNumberUtils.getNumberFromIntent(intent, this);
Log.w(TAG, "getNumberFromIntent(): " + intent.getData() + " --> " + number);
- /*
if (number != null) {
- number = PhoneNumberUtils.convertKeypadLettersToDigits(number);
- number = PhoneNumberUtils.stripSeparators(number);
+ // TODO: SIP: integrate this to PhoneApp later
+ if (!isUri(number)) {
+ number = PhoneNumberUtils.convertKeypadLettersToDigits(number);
+ number = PhoneNumberUtils.stripSeparators(number);
+ } else {
+ number = stripSeparators(number);
+ }
}
- */
final boolean emergencyNumber =
(number != null) && PhoneNumberUtils.isEmergencyNumber(number);
@@ -318,6 +321,46 @@ public class OutgoingCallBroadcaster extends Activity {
// The receiver will finish our activity when it finally runs.
}
+ private static final char PAUSE = PhoneNumberUtils.PAUSE;
+ private static final char WAIT = PhoneNumberUtils.WAIT;
+ private static final char WILD = PhoneNumberUtils.WILD;
+
+ // TODO: SIP: move isUri() to PhoneNumberUtils later
+ // TODO: SIP: fix the check; how do we tell if it's a regular phone number
+ // or a username in a SIP URI
+ static boolean isUri(String phoneNumber) {
+ if (TextUtils.isEmpty(phoneNumber)) return false;
+ if (phoneNumber.contains("@")) return true;
+ char c = phoneNumber.charAt(0);
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private static String stripSeparators(String phoneNumber) {
+ if (phoneNumber == null) {
+ return null;
+ }
+ int len = phoneNumber.length();
+ StringBuilder ret = new StringBuilder(len);
+
+ for (int i = 0; i < len; i++) {
+ char c = phoneNumber.charAt(i);
+ if (isNonSeparator(c)) {
+ ret.append(c);
+ }
+ }
+
+ return ret.toString();
+ }
+
+ private static boolean isNonSeparator(char c) {
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'
+ || c == '.' || c == '@' || PhoneNumberUtils.isNonSeparator(c);
+ }
+
// Implement onConfigurationChanged() purely for debugging purposes,
// to make sure that the android:configChanges element in our manifest
// is working properly.
diff --git a/phone/src2/com/android/internal/telephony/sip/SipConnectionBase.java b/phone/src2/com/android/internal/telephony/sip/SipConnectionBase.java
index 8ebc3a3..d48f94a 100644
--- a/phone/src2/com/android/internal/telephony/sip/SipConnectionBase.java
+++ b/phone/src2/com/android/internal/telephony/sip/SipConnectionBase.java
@@ -43,7 +43,6 @@ abstract class SipConnectionBase extends Connection {
private SipAudioCall mSipAudioCall;
- private String mAddress = null; // MAY BE NULL!!!
private String dialString; // outgoing calls only
private String postDialString; // outgoing calls only
private int nextPostDialChar; // index into postDialString
@@ -74,8 +73,7 @@ abstract class SipConnectionBase extends Connection {
private DisconnectCause mCause = DisconnectCause.NOT_DISCONNECTED;
private PostDialState postDialState = PostDialState.NOT_STARTED;
- SipConnectionBase(String address, String calleeSipUri) {
- mAddress = address;
+ SipConnectionBase(String calleeSipUri) {
dialString = calleeSipUri;
postDialString = PhoneNumberUtils.extractPostDialPortion(dialString);
@@ -84,6 +82,22 @@ abstract class SipConnectionBase extends Connection {
createTime = System.currentTimeMillis();
}
+ protected void setState(Call.State state) {
+ switch (state) {
+ case ACTIVE:
+ connectTimeReal = SystemClock.elapsedRealtime();
+ connectTime = System.currentTimeMillis();
+ break;
+ case DISCONNECTED:
+ duration = SystemClock.elapsedRealtime() - connectTimeReal;
+ disconnectTime = System.currentTimeMillis();
+ break;
+ case HOLDING:
+ holdingStartTime = SystemClock.elapsedRealtime();
+ break;
+ }
+ }
+
@Override
public long getCreateTime() {
return createTime;
@@ -218,7 +232,7 @@ abstract class SipConnectionBase extends Connection {
@Override
public int getNumberPresentation() {
- // FIXME: what's this for SIP?
+ // TODO: add PRESENTATION_URL
return Connection.PRESENTATION_ALLOWED;
}
diff --git a/phone/src2/com/android/internal/telephony/sip/SipPhone.java b/phone/src2/com/android/internal/telephony/sip/SipPhone.java
index 44452fe..59e0bd1 100755
--- a/phone/src2/com/android/internal/telephony/sip/SipPhone.java
+++ b/phone/src2/com/android/internal/telephony/sip/SipPhone.java
@@ -121,7 +121,7 @@ public class SipPhone extends SipPhoneBase {
String localUri = sipAudioCall.getLocalProfile().getUriString();
if (localUri.equals(mProfile.getUriString())) {
boolean makeCallWait = foregroundCall.getState().isAlive();
- ringingCall.take(sipAudioCall, makeCallWait);
+ ringingCall.initIncomingCall(sipAudioCall, makeCallWait);
return true;
}
return false;
@@ -310,6 +310,21 @@ public class SipPhone extends SipPhoneBase {
return super.getServiceState();
}
+ private String getUriString(SipProfile p) {
+ // SipProfile.getUriString() may contain "SIP:" and port
+ return p.getUserName() + "@" + getSipDomain(p);
+ }
+
+ private String getSipDomain(SipProfile p) {
+ String domain = p.getSipDomain();
+ // TODO: move this to SipProfile
+ if (domain.endsWith(":5060")) {
+ return domain.substring(0, domain.length() - 5);
+ } else {
+ return domain;
+ }
+ }
+
private class SipCall extends SipCallBase {
void switchWith(SipCall that) {
synchronized (SipPhone.class) {
@@ -341,11 +356,26 @@ public class SipPhone extends SipPhoneBase {
}
}
+ private CallerInfo getCallerInfo(String number) {
+ CallerInfo info = CallerInfo.getCallerInfo(mContext, number);
+ if ((info == null) || (info.name == null)) return null;
+ Log.v(LOG_TAG, "++******++ got info from contact:");
+ Log.v(LOG_TAG, " name: " + info.name);
+ Log.v(LOG_TAG, " numb: " + info.phoneNumber);
+ Log.v(LOG_TAG, " pres: " + info.numberPresentation);
+ return info;
+ }
+
Connection dial(String calleeSipUri) throws SipException {
+ CallerInfo info = getCallerInfo(calleeSipUri);
+ if (!calleeSipUri.contains("@")) {
+ calleeSipUri += "@" + getSipDomain(mProfile);
+ if (info != null) info.phoneNumber = calleeSipUri;
+ }
try {
SipProfile callee =
new SipProfile.Builder(calleeSipUri).build();
- SipConnection c = new SipConnection(this, callee);
+ SipConnection c = new SipConnection(this, callee, info);
connections.add(c);
c.dial();
setState(Call.State.DIALING);
@@ -372,13 +402,16 @@ public class SipPhone extends SipPhoneBase {
setState(State.DISCONNECTING);
}
- void take(SipAudioCall sipAudioCall, boolean makeCallWait) {
+ void initIncomingCall(SipAudioCall sipAudioCall, boolean makeCallWait) {
SipProfile callee = sipAudioCall.getPeerProfile();
- SipConnection c = new SipConnection(this, callee);
+ CallerInfo info = getCallerInfo(getUriString(callee));
+ if (info == null) info = getCallerInfo(callee.getUserName());
+ if (info == null) info = getCallerInfo(callee.getDisplayName());
+ SipConnection c = new SipConnection(this, callee, info);
connections.add(c);
Call.State newState = makeCallWait ? State.WAITING : State.INCOMING;
- c.take(sipAudioCall, newState);
+ c.initIncomingCall(sipAudioCall, newState);
setState(newState);
notifyNewRingingConnectionP(c);
@@ -512,7 +545,7 @@ public class SipPhone extends SipPhoneBase {
setDisconnectCause(cause);
}
synchronized (SipPhone.class) {
- mState = Call.State.DISCONNECTED;
+ setState(Call.State.DISCONNECTED);
mOwner.onConnectionEnded(SipConnection.this);
Log.v(LOG_TAG, "-------- connection ended: "
+ mPeer.getUriString() + ": "
@@ -528,9 +561,9 @@ public class SipPhone extends SipPhoneBase {
Call.State newState = getCallStateFrom(call);
if (mState == newState) return;
if (newState == Call.State.INCOMING) {
- mState = mOwner.getState(); // INCOMING or WAITING
+ setState(mOwner.getState()); // INCOMING or WAITING
} else {
- mState = newState;
+ setState(newState);
}
mOwner.onConnectionStateChanged(SipConnection.this);
Log.v(LOG_TAG, "++******++ connection state changed: "
@@ -553,14 +586,27 @@ public class SipPhone extends SipPhoneBase {
}
};
- public SipConnection(SipCall owner, SipProfile callee) {
- super(callee.getSipDomain(), callee.getUriString());
+ public SipConnection(SipCall owner, SipProfile callee,
+ CallerInfo info) {
+ super(getUriString(callee));
mOwner = owner;
mPeer = callee;
+ if (info == null) info = createCallerInfo();
+ setUserData(info);
+ }
+
+ private CallerInfo createCallerInfo() {
+ SipProfile p = mPeer;
+ String name = p.getDisplayName();
+ if (TextUtils.isEmpty(name)) name = p.getUserName();
+ CallerInfo info = new CallerInfo();
+ info.name = name;
+ info.phoneNumber = getUriString(p);
+ return info;
}
- void take(SipAudioCall sipAudioCall, Call.State newState) {
- mState = newState;
+ void initIncomingCall(SipAudioCall sipAudioCall, Call.State newState) {
+ setState(newState);
mSipAudioCall = sipAudioCall;
sipAudioCall.setListener(mAdapter); // call back to set state
mIncoming = true;
@@ -584,7 +630,7 @@ public class SipPhone extends SipPhoneBase {
}
void dial() throws SipException {
- mState = Call.State.DIALING;
+ setState(Call.State.DIALING);
mSipAudioCall = mSipManager.makeAudioCall(mContext, mProfile,
mPeer, null);
mSipAudioCall.setRingbackToneEnabled(false);
@@ -608,6 +654,13 @@ public class SipPhone extends SipPhoneBase {
}
@Override
+ protected void setState(Call.State state) {
+ if (state == mState) return;
+ super.setState(state);
+ mState = state;
+ }
+
+ @Override
public Call.State getState() {
return mState;
}
@@ -619,7 +672,7 @@ public class SipPhone extends SipPhoneBase {
@Override
public String getAddress() {
- return mPeer.getUriString();
+ return getUriString(mPeer);
}
@Override
@@ -633,32 +686,12 @@ public class SipPhone extends SipPhoneBase {
}
@Override
- public Object getUserData() {
- Object o = super.getUserData();
- if (o == null) {
- // FIXME: lookup contact with SIP URI?
- CallerInfo info = CallerInfo.getCallerInfo(
- mContext, mPeer.getUserName());
- if (info == null) {
- info = new CallerInfo();
- String name = mPeer.getDisplayName();
- if (TextUtils.isEmpty(name)) name = mPeer.getUserName();
- info.name = name;
- info.phoneNumber = getAddress();
- }
- setUserData(info);
- o = info;
- }
- return o;
- }
-
- @Override
public void hangup() throws CallStateException {
Log.v(LOG_TAG, "hangup conn: " + mPeer.getUriString() + ": "
+ ": on phone " + getPhone());
try {
mSipAudioCall.endCall();
- mState = Call.State.DISCONNECTING;
+ setState(Call.State.DISCONNECTING);
setDisconnectCause(DisconnectCause.LOCAL);
} catch (SipException e) {
throw new CallStateException("hangup(): " + e);