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     boolean
    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                 return true;
    133             }
    134         }
    135 
    136         return false;
    137     }
    138 
    139 
    140     /*package*/ void
    141     detach(CdmaConnection conn) {
    142         mConnections.remove(conn);
    143 
    144         if (mConnections.size() == 0) {
    145             mState = State.IDLE;
    146         }
    147     }
    148 
    149     /*package*/ boolean
    150     update (CdmaConnection 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() == CdmaCallTracker.MAX_CONNECTIONS_PER_CALL;
    171     }
    172 
    173     //***** Called from CdmaCallTracker
    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(); i < s; i++) {
    184             CdmaConnection cn = (CdmaConnection)mConnections.get(i);
    185 
    186             cn.onHangupLocal();
    187         }
    188         mState = State.DISCONNECTING;
    189     }
    190 
    191     /**
    192      * Called when it's time to clean up disconnected Connection objects
    193      */
    194    void clearDisconnected() {
    195         for (int i = mConnections.size() - 1 ; i >= 0 ; i--) {
    196         CdmaConnection cn = (CdmaConnection)mConnections.get(i);
    197 
    198             if (cn.getState() == State.DISCONNECTED) {
    199                 mConnections.remove(i);
    200             }
    201         }
    202 
    203         if (mConnections.size() == 0) {
    204             mState = State.IDLE;
    205         }
    206     }
    207 }
    208