Android Telephony Framework Code

1. Architecture

App layer: 
           Call, Data, SMS, MMS, STK, Settings
          
Java Framework layer:   
                        android.telephony.*
                                 |
               com.android.internal.telephony
                                 |
                               Ril.java
                              
RIL layer(Native C):
                               rild daemon
                                  |
                              vendor ril.so    
                             
Kernel space:
                     Ril driver (UART, USB, SDIO, SM)
                    
Modem                
 

2. Code path:


frameworks/base/telephony/java/com/android/internal/telephony
frameworks/base/telephony/java/android/telephony
frameworks/base/core/java/android/net
frameworks/base/services/java/com/android/server

2.1 Phone/PhoneBase/GSMPhone
Phone(inteface)
PhoneBase(abstract class) implement of Phone interface
GSMPhone/CDMAPhone extends PhoneBase
Phoneapp choose the right phone (GSMPhone/CDMAPhone) according to phone type.
Relationship:        
          PhoneApp 
        |          | ITelePhony
   PhoneProxy    TelephonyManager
        |
   GSMPhone/CDMAPhone
        |
       RILJ             

2.2 Dataconnection.java (abstract class) extends StateMachine
   addState(mDefaultState);
            addState(mInactiveState, mDefaultState);
            addState(mActivatingState, mDefaultState);
            addState(mActiveState, mDefaultState);
            addState(mDisconnectingState, mDefaultState);
            addState(mDisconnectingErrorCreatingConnection, mDefaultState);
        setInitialState(mInactiveState);
GSMDataConnection and CDMADataConnection extends Dataconnection

2.3 ApnContext

 public enum State {
        IDLE,
        INITING,
        CONNECTING,
        SCANNING,
        CONNECTED,
        DISCONNECTING,
        FAILED
    }

 

2.4 TelephonyManager/PhoneStateListener
Third party application can call member function in TelephonyManager
and can listen some state change by PhoneStateListener
example:
private TelephonyManager mTelephonyManager =  (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
int state = mTelephonyManager.getDataState();

private PhoneStateListener stateListener = new PhoneStateListener() {
@Override
public void onDataConnectionStateChanged(int state) {
   Log.d("data state is "+state);
}

Phone.DataState

 public enum DataState {
       CONNECTED, CONNECTING, DISCONNECTED, SUSPENDED;
   };

2.5 ConnectivityManager handles all data services (WiFi, mobile, MMS, SUPL....)
 
getActiveNetworkInfo() get active network information
getNetworkInfo() get specified network information

public static final int TYPE_MOBILE      = 0
public static final int TYPE_WIFI        = 1
public static final int TYPE_MOBILE_MMS  = 2 

class NetworkInfo

public enum State {
       CONNECTING, CONNECTED, SUSPENDED, DISCONNECTING, DISCONNECTED, UNKNOWN
}

public enum DetailedState {
        /** Ready to start data connection setup. */
        IDLE,
        /** Searching for an available access point. */
        SCANNING,
        /** Currently setting up data connection. */
        CONNECTING,
        /** Network link established, performing authentication. */
        AUTHENTICATING,
       /** Awaiting response from DHCP server in order to assign IP address information. */
        OBTAINING_IPADDR,
        /** IP traffic should be available. */
        CONNECTED,
        /** IP traffic is suspended */
        SUSPENDED,
        /** Currently tearing down data connection. */
        DISCONNECTING,
        /** IP traffic not available. */
        DISCONNECTED,
        /** Attempt to connect failed. */
        FAILED,
        /** Access to this network is blocked. */
        BLOCKED,
        /** Link has poor connectivity. */
        VERIFYING_POOR_LINK,
        /** Checking if network is a captive portal */
        CAPTIVE_PORTAL_CHECK
}

example:
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 
NetworkInfo activeInfo =  mCm.getActiveNetworkInfo();
NetworkInfo wifiInfo = mCm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); 
NetworkInfo mobileInfo = mCm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); 
Log.d("Active network: "+activeInfo.getType());
Log.d("Wifi state: "+wifiInfo.getState());
Log.d("Mobile state: "+mobileInfo.getState()); 

 

2.6 NetworkAttributes configuration

frameworks/base/core/res/res/values/config.xml

Connection name],[ConnectivityManager.TYPE_xxxx], [associated radio-type],[priority],[restoral-timer(ms)],[dependencyMet]

<string-array translatable="false" name="networkAttributes">
        <item>"wifi,1,1,1,-1,true"</item>
        <item>"mobile,0,0,0,-1,true"</item>
        <item>"mobile_mms,2,0,2,60000,true"</item>
        <item>"mobile_supl,3,0,2,60000,true"</item>
        <item>"mobile_hipri,5,0,3,60000,true"</item>
        <item>"mobile_fota,10,0,2,60000,true"</item>
        <item>"mobile_ims,11,0,2,60000,true"</item>
        <item>"mobile_cbs,12,0,2,60000,true"</item>
        <item>"wifi_p2p,13,1,0,-1,true"</item>
</string-array>

 

2.7 NetworkManagementServie route/DNS handling

addRoute, removeRoute, Dns, enableNat/disableNat/modifyNat, attachPppd/detachPppd

 it will call NativeDaemonConnector execute().

 

3. setup Data call flow

onPreferenceTreeClick  (case mButtonDataEnabled)    in MobileNetworkSettings
  setMobileDataEnabled    in ConnectivityService
    handleSetMobileData()
      setUserDataEnable() ->CMD_SET_USER_DATA_ENABLE  in MobileDataStateTracker
        onSetUserDataEnabled   in DataConnectionTracker
          onTrySetupData(Phone.REASON_DATA_ENABLED)
             setupDataOnReadyApns()   in GsmDataConnectionTracker
               trySetupData
                 setupData
                   bringUp   ->EVENT_CONNECT  in DataConnection
                     onConnect
                       setupDataCall()    in Ril

 

你可能感兴趣的:(framework,telephony)