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