SipConnectionBase.java revision cbaa45bbf2cab852b6c9c3a887e9f803d4e857ea
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17package com.android.internal.telephony.sip; 18 19import com.android.internal.telephony.Call; 20import com.android.internal.telephony.Connection; 21import com.android.internal.telephony.Phone; 22import com.android.internal.telephony.PhoneConstants; 23import com.android.internal.telephony.UUSInfo; 24 25import android.os.SystemClock; 26import android.telephony.Rlog; 27import android.telephony.PhoneNumberUtils; 28 29abstract class SipConnectionBase extends Connection { 30 private static final String LOG_TAG = "SipConnBase"; 31 private static final boolean DBG = true; 32 private static final boolean VDBG = true; // STOPSHIP if true 33 34 private String postDialString; // outgoing calls only 35 private int nextPostDialChar; // index into postDialString 36 /* 37 * These time/timespan values are based on System.currentTimeMillis(), 38 * i.e., "wall clock" time. 39 */ 40 private long createTime; 41 private long connectTime; 42 private long disconnectTime; 43 44 /* 45 * These time/timespan values are based on SystemClock.elapsedRealTime(), 46 * i.e., time since boot. They are appropriate for comparison and 47 * calculating deltas. 48 */ 49 private long connectTimeReal; 50 private long duration = -1L; 51 private long holdingStartTime; // The time when the Connection last transitioned 52 // into HOLDING 53 54 private DisconnectCause mCause = DisconnectCause.NOT_DISCONNECTED; 55 private PostDialState postDialState = PostDialState.NOT_STARTED; 56 57 SipConnectionBase(String dialString) { 58 if (DBG) log("SipConnectionBase: ctor dialString=" + dialString); 59 postDialString = PhoneNumberUtils.extractPostDialPortion(dialString); 60 61 createTime = System.currentTimeMillis(); 62 } 63 64 protected void setState(Call.State state) { 65 if (DBG) log("setState: state=" + state); 66 switch (state) { 67 case ACTIVE: 68 if (connectTime == 0) { 69 connectTimeReal = SystemClock.elapsedRealtime(); 70 connectTime = System.currentTimeMillis(); 71 } 72 break; 73 case DISCONNECTED: 74 duration = getDurationMillis(); 75 disconnectTime = System.currentTimeMillis(); 76 break; 77 case HOLDING: 78 holdingStartTime = SystemClock.elapsedRealtime(); 79 break; 80 default: 81 // Ignore 82 break; 83 } 84 } 85 86 @Override 87 public long getCreateTime() { 88 if (VDBG) log("getCreateTime: ret=" + createTime); 89 return createTime; 90 } 91 92 @Override 93 public long getConnectTime() { 94 if (VDBG) log("getConnectTime: ret=" + connectTime); 95 return connectTime; 96 } 97 98 @Override 99 public long getDisconnectTime() { 100 if (VDBG) log("getDisconnectTime: ret=" + disconnectTime); 101 return disconnectTime; 102 } 103 104 @Override 105 public long getDurationMillis() { 106 long dur; 107 if (connectTimeReal == 0) { 108 dur = 0; 109 } else if (duration < 0) { 110 dur = SystemClock.elapsedRealtime() - connectTimeReal; 111 } else { 112 dur = duration; 113 } 114 if (VDBG) log("getDurationMillis: ret=" + dur); 115 return dur; 116 } 117 118 @Override 119 public long getHoldDurationMillis() { 120 long dur; 121 if (getState() != Call.State.HOLDING) { 122 // If not holding, return 0 123 dur = 0; 124 } else { 125 dur = SystemClock.elapsedRealtime() - holdingStartTime; 126 } 127 if (VDBG) log("getHoldDurationMillis: ret=" + dur); 128 return dur; 129 } 130 131 @Override 132 public DisconnectCause getDisconnectCause() { 133 if (VDBG) log("getDisconnectCause: ret=" + mCause); 134 return mCause; 135 } 136 137 void setDisconnectCause(DisconnectCause cause) { 138 if (DBG) log("setDisconnectCause: prev=" + mCause + " new=" + cause); 139 mCause = cause; 140 } 141 142 @Override 143 public PostDialState getPostDialState() { 144 if (VDBG) log("getPostDialState: ret=" + postDialState); 145 return postDialState; 146 } 147 148 @Override 149 public void proceedAfterWaitChar() { 150 if (DBG) log("proceedAfterWaitChar: ignore"); 151 } 152 153 @Override 154 public void proceedAfterWildChar(String str) { 155 if (DBG) log("proceedAfterWildChar: ignore"); 156 } 157 158 @Override 159 public void cancelPostDial() { 160 if (DBG) log("cancelPostDial: ignore"); 161 } 162 163 protected abstract Phone getPhone(); 164 165 @Override 166 public String getRemainingPostDialString() { 167 if (postDialState == PostDialState.CANCELLED 168 || postDialState == PostDialState.COMPLETE 169 || postDialString == null 170 || postDialString.length() <= nextPostDialChar) { 171 if (DBG) log("getRemaingPostDialString: ret empty string"); 172 return ""; 173 } 174 175 return postDialString.substring(nextPostDialChar); 176 } 177 178 private void log(String msg) { 179 Rlog.d(LOG_TAG, msg); 180 } 181 182 @Override 183 public int getNumberPresentation() { 184 // TODO: add PRESENTATION_URL 185 if (VDBG) log("getNumberPresentation: ret=PRESENTATION_ALLOWED"); 186 return PhoneConstants.PRESENTATION_ALLOWED; 187 } 188 189 @Override 190 public UUSInfo getUUSInfo() { 191 // FIXME: what's this for SIP? 192 if (VDBG) log("getUUSInfo: ? ret=null"); 193 return null; 194 } 195} 196