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