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