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.gsm; 18 19 import com.android.internal.telephony.Call; 20 import com.android.internal.telephony.CallStateException; 21 import com.android.internal.telephony.Connection; 22 import com.android.internal.telephony.DriverCall; 23 import com.android.internal.telephony.Phone; 24 25 import java.util.List; 26 27 /** 28 * {@hide} 29 */ 30 class GsmCall extends Call { 31 /*************************** Instance Variables **************************/ 32 33 /*package*/ GsmCallTracker mOwner; 34 35 36 /***************************** Class Methods *****************************/ 37 38 static State 39 stateFromDCState (DriverCall.State dcState) { 40 switch (dcState) { 41 case ACTIVE: return State.ACTIVE; 42 case HOLDING: return State.HOLDING; 43 case DIALING: return State.DIALING; 44 case ALERTING: return State.ALERTING; 45 case INCOMING: return State.INCOMING; 46 case WAITING: return State.WAITING; 47 default: throw new RuntimeException ("illegal call state:" + dcState); 48 } 49 } 50 51 52 /****************************** Constructors *****************************/ 53 /*package*/ 54 GsmCall (GsmCallTracker owner) { 55 mOwner = owner; 56 } 57 58 public void dispose() { 59 } 60 61 /************************** Overridden from Call *************************/ 62 63 @Override 64 public List<Connection> 65 getConnections() { 66 // FIXME should return Collections.unmodifiableList(); 67 return mConnections; 68 } 69 70 @Override 71 public Phone 72 getPhone() { 73 return mOwner.mPhone; 74 } 75 76 @Override 77 public boolean 78 isMultiparty() { 79 return mConnections.size() > 1; 80 } 81 82 /** Please note: if this is the foreground call and a 83 * background call exists, the background call will be resumed 84 * because an AT+CHLD=1 will be sent 85 */ 86 @Override 87 public void 88 hangup() throws CallStateException { 89 mOwner.hangup(this); 90 } 91 92 @Override 93 public String 94 toString() { 95 return mState.toString(); 96 } 97 98 //***** Called from GsmConnection 99 100 /*package*/ void 101 attach(Connection conn, DriverCall dc) { 102 mConnections.add(conn); 103 104 mState = stateFromDCState (dc.state); 105 } 106 107 /*package*/ void 108 attachFake(Connection conn, State state) { 109 mConnections.add(conn); 110 111 mState = state; 112 } 113 114 /** 115 * Called by GsmConnection when it has disconnected 116 */ 117 void 118 connectionDisconnected(GsmConnection conn) { 119 if (mState != State.DISCONNECTED) { 120 /* If only disconnected connections remain, we are disconnected*/ 121 122 boolean hasOnlyDisconnectedConnections = true; 123 124 for (int i = 0, s = mConnections.size() ; i < s; i ++) { 125 if (mConnections.get(i).getState() 126 != State.DISCONNECTED 127 ) { 128 hasOnlyDisconnectedConnections = false; 129 break; 130 } 131 } 132 133 if (hasOnlyDisconnectedConnections) { 134 mState = State.DISCONNECTED; 135 } 136 } 137 } 138 139 140 /*package*/ void 141 detach(GsmConnection conn) { 142 mConnections.remove(conn); 143 144 if (mConnections.size() == 0) { 145 mState = State.IDLE; 146 } 147 } 148 149 /*package*/ boolean 150 update (GsmConnection conn, DriverCall dc) { 151 State newState; 152 boolean changed = false; 153 154 newState = stateFromDCState(dc.state); 155 156 if (newState != mState) { 157 mState = newState; 158 changed = true; 159 } 160 161 return changed; 162 } 163 164 /** 165 * @return true if there's no space in this call for additional 166 * connections to be added via "conference" 167 */ 168 /*package*/ boolean 169 isFull() { 170 return mConnections.size() == GsmCallTracker.MAX_CONNECTIONS_PER_CALL; 171 } 172 173 //***** Called from GsmCallTracker 174 175 176 /** 177 * Called when this Call is being hung up locally (eg, user pressed "end") 178 * Note that at this point, the hangup request has been dispatched to the radio 179 * but no response has yet been received so update() has not yet been called 180 */ 181 void 182 onHangupLocal() { 183 for (int i = 0, s = mConnections.size() 184 ; i < s; i++ 185 ) { 186 GsmConnection cn = (GsmConnection)mConnections.get(i); 187 188 cn.onHangupLocal(); 189 } 190 mState = State.DISCONNECTING; 191 } 192 193 /** 194 * Called when it's time to clean up disconnected Connection objects 195 */ 196 void 197 clearDisconnected() { 198 for (int i = mConnections.size() - 1 ; i >= 0 ; i--) { 199 GsmConnection cn = (GsmConnection)mConnections.get(i); 200 201 if (cn.getState() == State.DISCONNECTED) { 202 mConnections.remove(i); 203 } 204 } 205 206 if (mConnections.size() == 0) { 207 mState = State.IDLE; 208 } 209 } 210 } 211 212