2 * Copyright (C) 2006 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;
18 import android.util.Log;
23 public abstract class Connection {
25 // Number presentation type for caller id display
26 public static int PRESENTATION_ALLOWED = 1; // normal
27 public static int PRESENTATION_RESTRICTED = 2; // block by user
28 public static int PRESENTATION_UNKNOWN = 3; // no specified or unknown by network
29 public static int PRESENTATION_PAYPHONE = 4; // show pay phone info
31 private static String LOG_TAG = "TelephonyConnection";
33 public enum DisconnectCause {
34 NOT_DISCONNECTED, /* has not yet disconnected */
35 INCOMING_MISSED, /* an incoming call that was missed and never answered */
36 NORMAL, /* normal; remote */
37 LOCAL, /* normal; local hangup */
38 BUSY, /* outgoing call to busy line */
39 CONGESTION, /* outgoing call to congested network */
40 MMI, /* not presently used; dial() returns null */
41 INVALID_NUMBER, /* invalid dial string */
42 NUMBER_UNREACHABLE, /* cannot reach the peer */
43 SERVER_UNREACHABLE, /* cannot reach the server */
44 INVALID_CREDENTIALS, /* invalid credentials */
45 OUT_OF_NETWORK, /* calling from out of network is not allowed */
46 SERVER_ERROR, /* server error */
47 TIMED_OUT, /* client timed out */
49 LIMIT_EXCEEDED, /* eg GSM ACM limit exceeded */
50 INCOMING_REJECTED, /* an incoming call that was rejected */
51 POWER_OFF, /* radio is turned off explicitly */
52 OUT_OF_SERVICE, /* out of service */
53 ICC_ERROR, /* No ICC, ICC locked, or other ICC error */
54 CALL_BARRED, /* call was blocked by call barring */
55 FDN_BLOCKED, /* call was blocked by fixed dial number */
56 CS_RESTRICTED, /* call was blocked by restricted all voice access */
57 CS_RESTRICTED_NORMAL, /* call was blocked by restricted normal voice access */
58 CS_RESTRICTED_EMERGENCY, /* call was blocked by restricted emergency voice access */
59 UNOBTAINABLE_NUMBER, /* Unassigned number (3GPP TS 24.008 table 10.5.123) */
60 CDMA_LOCKED_UNTIL_POWER_CYCLE, /* MS is locked until next power cycle */
62 CDMA_INTERCEPT, /* INTERCEPT order received, MS state idle entered */
63 CDMA_REORDER, /* MS has been redirected, call is cancelled */
64 CDMA_SO_REJECT, /* service option rejection */
65 CDMA_RETRY_ORDER, /* requested service is rejected, retry delay is set */
68 CDMA_NOT_EMERGENCY, /* not an emergency call */
69 CDMA_ACCESS_BLOCKED, /* Access Blocked by CDMA network */
75 /* Instance Methods */
78 * Gets address (e.g. phone number) associated with connection.
79 * TODO: distinguish reasons for unavailability
81 * @return address or null if unavailable
84 public abstract String getAddress();
87 * Gets CDMA CNAP name associated with connection.
88 * @return cnap name or null if unavailable
90 public String getCnapName() {
95 * Get original dial string.
96 * @return original dial string or null if unavailable
98 public String getOrigDialString(){
103 * Gets CDMA CNAP presentation associated with connection.
104 * @return cnap name or null if unavailable
107 public int getCnapNamePresentation() {
112 * @return Call that owns this Connection, or null if none
114 public abstract Call getCall();
117 * Connection create time in currentTimeMillis() format
118 * Basically, set when object is created.
119 * Effectively, when an incoming call starts ringing or an
120 * outgoing call starts dialing
122 public abstract long getCreateTime();
125 * Connection connect time in currentTimeMillis() format.
126 * For outgoing calls: Begins at (DIALING|ALERTING) -> ACTIVE transition.
127 * For incoming calls: Begins at (INCOMING|WAITING) -> ACTIVE transition.
128 * Returns 0 before then.
130 public abstract long getConnectTime();
133 * Disconnect time in currentTimeMillis() format.
134 * The time when this Connection makes a transition into ENDED or FAIL.
135 * Returns 0 before then.
137 public abstract long getDisconnectTime();
140 * Returns the number of milliseconds the call has been connected,
141 * or 0 if the call has never connected.
142 * If the call is still connected, then returns the elapsed
143 * time since connect.
145 public abstract long getDurationMillis();
148 * If this connection is HOLDING, return the number of milliseconds
149 * that it has been on hold for (approximately).
150 * If this connection is in any other state, return 0.
153 public abstract long getHoldDurationMillis();
156 * Returns "NOT_DISCONNECTED" if not yet disconnected.
158 public abstract DisconnectCause getDisconnectCause();
161 * Returns true of this connection originated elsewhere
162 * ("MT" or mobile terminated; another party called this terminal)
163 * or false if this call originated here (MO or mobile originated).
165 public abstract boolean isIncoming();
168 * If this Connection is connected, then it is associated with
171 * Returns getCall().getState() or Call.State.IDLE if not
174 public Call.State getState() {
180 return Call.State.IDLE;
189 * @return true if the connection isn't disconnected
190 * (could be active, holding, ringing, dialing, etc)
194 return getState().isAlive();
198 * Returns true if Connection is connected and is INCOMING or WAITING
202 return getState().isRinging();
207 * @return the userdata set in setUserData()
209 public Object getUserData() {
215 * @param userdata user can store an any userdata in the Connection object.
217 public void setUserData(Object userdata) {
218 this.userData = userdata;
222 * Hangup individual Connection
224 public abstract void hangup() throws CallStateException;
227 * Separate this call from its owner Call and assigns it to a new Call
228 * (eg if it is currently part of a Conference call
229 * TODO: Throw exception? Does GSM require error display on failure here?
231 public abstract void separate() throws CallStateException;
233 public enum PostDialState {
234 NOT_STARTED, /* The post dial string playback hasn't
235 been started, or this call is not yet
236 connected, or this is an incoming call */
237 STARTED, /* The post dial string playback has begun */
238 WAIT, /* The post dial string playback is waiting for a
239 call to proceedAfterWaitChar() */
240 WILD, /* The post dial string playback is waiting for a
241 call to proceedAfterWildChar() */
242 COMPLETE, /* The post dial string playback is complete */
243 CANCELLED, /* The post dial string playback was cancelled
244 with cancelPostDial() */
245 PAUSE /* The post dial string playback is pausing for a
246 call to processNextPostDialChar*/
249 public void clearUserData(){
253 public abstract PostDialState getPostDialState();
256 * Returns the portion of the post dial string that has not
257 * yet been dialed, or "" if none
259 public abstract String getRemainingPostDialString();
262 * See Phone.setOnPostDialWaitCharacter()
265 public abstract void proceedAfterWaitChar();
268 * See Phone.setOnPostDialWildCharacter()
270 public abstract void proceedAfterWildChar(String str);
274 public abstract void cancelPostDial();
277 * Returns the caller id presentation type for incoming and waiting calls
278 * @return one of PRESENTATION_*
280 public abstract int getNumberPresentation();
283 * Returns the User to User Signaling (UUS) information associated with
284 * incoming and waiting calls
285 * @return UUSInfo containing the UUS userdata.
287 public abstract UUSInfo getUUSInfo();
290 * Build a human representation of a connection instance, suitable for debugging.
291 * Don't log personal stuff unless in debug mode.
292 * @return a string representing the internal state of this connection.
294 public String toString() {
295 StringBuilder str = new StringBuilder(128);
297 if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
298 str.append("addr: " + getAddress())
299 .append(" pres.: " + getNumberPresentation())
300 .append(" dial: " + getOrigDialString())
301 .append(" postdial: " + getRemainingPostDialString())
302 .append(" cnap name: " + getCnapName())
303 .append("(" + getCnapNamePresentation() + ")");
305 str.append(" incoming: " + isIncoming())
306 .append(" state: " + getState())
307 .append(" post dial state: " + getPostDialState());
308 return str.toString();