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