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