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