• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 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;
18 
19 import java.util.List;
20 
21 /**
22  * {@hide}
23  */
24 public abstract class Call {
25     /* Enums */
26 
27     public enum State {
28         IDLE, ACTIVE, HOLDING, DIALING, ALERTING, INCOMING, WAITING, DISCONNECTED, DISCONNECTING;
29 
isAlive()30         public boolean isAlive() {
31             return !(this == IDLE || this == DISCONNECTED || this == DISCONNECTING);
32         }
33 
isRinging()34         public boolean isRinging() {
35             return this == INCOMING || this == WAITING;
36         }
37 
isDialing()38         public boolean isDialing() {
39             return this == DIALING || this == ALERTING;
40         }
41     }
42 
43 
44     /* Instance Variables */
45 
46     public State state = State.IDLE;
47 
48 
49     // Flag to indicate if the current calling/caller information
50     // is accurate. If false the information is known to be accurate.
51     //
52     // For CDMA, during call waiting/3 way, there is no network response
53     // if call waiting is answered, network timed out, dropped, 3 way
54     // merged, etc.
55     protected boolean isGeneric = false;
56 
57     /* Instance Methods */
58 
59     /** Do not modify the List result!!! This list is not yours to keep
60      *  It will change across event loop iterations            top
61      */
62 
getConnections()63     public abstract List<Connection> getConnections();
getPhone()64     public abstract Phone getPhone();
isMultiparty()65     public abstract boolean isMultiparty();
hangup()66     public abstract void hangup() throws CallStateException;
67 
68 
69     /**
70      * hasConnection
71      *
72      * @param c a Connection object
73      * @return true if the call contains the connection object passed in
74      */
hasConnection(Connection c)75     public boolean hasConnection(Connection c) {
76         return c.getCall() == this;
77     }
78 
79     /**
80      * hasConnections
81      * @return true if the call contains one or more connections
82      */
hasConnections()83     public boolean hasConnections() {
84         List connections = getConnections();
85 
86         if (connections == null) {
87             return false;
88         }
89 
90         return connections.size() > 0;
91     }
92 
93     /**
94      * getState
95      * @return state of class call
96      */
getState()97     public State getState() {
98         return state;
99     }
100 
101     /**
102      * isIdle
103      *
104      * FIXME rename
105      * @return true if the call contains only disconnected connections (if any)
106      */
isIdle()107     public boolean isIdle() {
108         return !getState().isAlive();
109     }
110 
111     /**
112      * Returns the Connection associated with this Call that was created
113      * first, or null if there are no Connections in this Call
114      */
115     public Connection
getEarliestConnection()116     getEarliestConnection() {
117         List l;
118         long time = Long.MAX_VALUE;
119         Connection c;
120         Connection earliest = null;
121 
122         l = getConnections();
123 
124         if (l.size() == 0) {
125             return null;
126         }
127 
128         for (int i = 0, s = l.size() ; i < s ; i++) {
129             c = (Connection) l.get(i);
130             long t;
131 
132             t = c.getCreateTime();
133 
134             if (t < time) {
135                 earliest = c;
136                 time = t;
137             }
138         }
139 
140         return earliest;
141     }
142 
143     public long
getEarliestCreateTime()144     getEarliestCreateTime() {
145         List l;
146         long time = Long.MAX_VALUE;
147 
148         l = getConnections();
149 
150         if (l.size() == 0) {
151             return 0;
152         }
153 
154         for (int i = 0, s = l.size() ; i < s ; i++) {
155             Connection c = (Connection) l.get(i);
156             long t;
157 
158             t = c.getCreateTime();
159 
160             time = t < time ? t : time;
161         }
162 
163         return time;
164     }
165 
166     public long
167     getEarliestConnectTime() {
168         long time = Long.MAX_VALUE;
169         List l = getConnections();
170 
171         if (l.size() == 0) {
172             return 0;
173         }
174 
175         for (int i = 0, s = l.size() ; i < s ; i++) {
176             Connection c = (Connection) l.get(i);
177             long t;
178 
179             t = c.getConnectTime();
180 
181             time = t < time ? t : time;
182         }
183 
184         return time;
185     }
186 
187 
188     public boolean
189     isDialingOrAlerting() {
190         return getState().isDialing();
191     }
192 
193     public boolean
194     isRinging() {
195         return getState().isRinging();
196     }
197 
198     /**
199      * Returns the Connection associated with this Call that was created
200      * last, or null if there are no Connections in this Call
201      */
202     public Connection
203     getLatestConnection() {
204         List l = getConnections();
205         if (l.size() == 0) {
206             return null;
207         }
208 
209         long time = 0;
210         Connection latest = null;
211         for (int i = 0, s = l.size() ; i < s ; i++) {
212             Connection c = (Connection) l.get(i);
213             long t = c.getCreateTime();
214 
215             if (t > time) {
216                 latest = c;
217                 time = t;
218             }
219         }
220 
221         return latest;
222     }
223 
224     /**
225      * To indicate if the connection information is accurate
226      * or not. false means accurate. Only used for CDMA.
227      */
228     public boolean isGeneric() {
229         return isGeneric;
230     }
231 
232     /**
233      * Set the generic instance variable
234      */
235     public void setGeneric(boolean generic) {
236         isGeneric = generic;
237     }
238 }
239