2 * Copyright (C) 2010 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.internal.telephony.sip;
19 import com.android.internal.telephony.Call;
20 import com.android.internal.telephony.Connection;
21 import com.android.internal.telephony.Phone;
23 import android.net.sip.SipAudioCall;
24 import android.os.SystemClock;
25 import android.util.Log;
26 import android.telephony.PhoneNumberUtils;
28 abstract class SipConnectionBase extends Connection {
29 private static final String LOG_TAG = "SIP_CONN";
31 private SipAudioCall mSipAudioCall;
33 private String dialString; // outgoing calls only
34 private String postDialString; // outgoing calls only
35 private int nextPostDialChar; // index into postDialString
36 private boolean isIncoming;
39 * These time/timespan values are based on System.currentTimeMillis(),
40 * i.e., "wall clock" time.
42 private long createTime;
43 private long connectTime;
44 private long disconnectTime;
47 * These time/timespan values are based on SystemClock.elapsedRealTime(),
48 * i.e., time since boot. They are appropriate for comparison and
51 private long connectTimeReal;
52 private long duration = -1L;
53 private long holdingStartTime; // The time when the Connection last transitioned
56 private DisconnectCause mCause = DisconnectCause.NOT_DISCONNECTED;
57 private PostDialState postDialState = PostDialState.NOT_STARTED;
59 SipConnectionBase(String dialString) {
60 this.dialString = dialString;
62 postDialString = PhoneNumberUtils.extractPostDialPortion(dialString);
65 createTime = System.currentTimeMillis();
68 protected void setState(Call.State state) {
71 if (connectTime == 0) {
72 connectTimeReal = SystemClock.elapsedRealtime();
73 connectTime = System.currentTimeMillis();
77 duration = getDurationMillis();
78 disconnectTime = System.currentTimeMillis();
81 holdingStartTime = SystemClock.elapsedRealtime();
87 public long getCreateTime() {
92 public long getConnectTime() {
97 public long getDisconnectTime() {
98 return disconnectTime;
102 public long getDurationMillis() {
103 if (connectTimeReal == 0) {
105 } else if (duration < 0) {
106 return SystemClock.elapsedRealtime() - connectTimeReal;
113 public long getHoldDurationMillis() {
114 if (getState() != Call.State.HOLDING) {
115 // If not holding, return 0
118 return SystemClock.elapsedRealtime() - holdingStartTime;
123 public DisconnectCause getDisconnectCause() {
127 void setDisconnectCause(DisconnectCause cause) {
132 public PostDialState getPostDialState() {
133 return postDialState;
137 public void proceedAfterWaitChar() {
142 public void proceedAfterWildChar(String str) {
147 public void cancelPostDial() {
151 protected abstract Phone getPhone();
154 public String getRemainingPostDialString() {
155 if (postDialState == PostDialState.CANCELLED
156 || postDialState == PostDialState.COMPLETE
157 || postDialString == null
158 || postDialString.length() <= nextPostDialChar) {
162 return postDialString.substring(nextPostDialChar);
165 private void log(String msg) {
166 Log.d(LOG_TAG, "[SipConn] " + msg);
170 public int getNumberPresentation() {
171 // TODO: add PRESENTATION_URL
172 return Connection.PRESENTATION_ALLOWED;