Archive for April, 2011

Have you lost signal?

Posted: April 27, 2011 in Android

In this post I will show you how Android devices interact with the network in order to retrieve network information and registration states.

The main component responsible for service state and information retrieval is the com.android.internal.telephony.ServiceStateTracker class. In case of GSM networks which is our target network technology, there is a GSM specific subclass called  com.android.internal.telephony.gsm.GsmServiceStateTracker.

The BIG picture:

As you can see in the diagram above, the service state pooling is triggered after one of the three asynchronous events that are posted by the com.android.internal.telephony.RIL class:

  • EVENT_SIM_READY
  • EVENT_RADIO_STATE_CHANGED
  • EVENT_NETWORK_STATE_CHANGED

Since the pooling process relies on asynchronous information that is queried to the com.android.internal.telephony.RIL class, Android puts all 4 asynchronous calls into a context in order to be able to ignore late responses that arrive after a new pooling has been triggered.

Its implemented using a pooling context as shown bellow:

private void pollState() {
    pollingContext = new int[1];
…
}

protected void handlePollStateResult (int what, AsyncResult ar) {
    // Ignore stale requests from last poll
    if (ar.userObj != pollingContext) return;
…
}
Once all asynchronous results arrive, it calls the poolStateDone(…) function in order to update the current service state and post the state update to the rest of the system. Now that you have the big picture drawn in your mind, I will show what kind of information the phone retrieves from the network.

EVENT_POLL_STATE_REGISTRATION

The registration state wraps information such as whether the phone is registered in a Home or Roaming network, the registration state and detailed network information such as the Cell Id (CID) and Location Area Code (LAC) as shown bellow:



 EVENT_POLL_STATE_GPRS
The GPRS registration state information is quite similar to the EVENT_POLL_STATE_REGISTRATION, it wraps the service state, the roaming information and the network technology type as shown bellow:


EVENT_POLL_STATE_OPERATOR
The operator state wraps the Network Short and Long names that we see on the notification bar and lock screens and the Network Code (MCC+MNC) as shown bellow:


EVENT_POLL_STATE_NETWORK_SELECTION_MODE
The last piece of information retrieved is the selection mode. Selection mode defines whether the underlying baseband modem should do automatic network search/selection or manual selection based on the latest registered networks. See code flow bellow:


Once all the information queried to the network has arrived, the system switches the current network state information by the new one recently queried. The pollStateDone(…) method does all the comparison between the old and new states and notifies all the registered observers interested in network state changes such as registration, roaming, location changes, etc. It also sets a few important   system properties that are used by the entire system in order to resolve network related information and shown bellow:

I hope you got your signal back now 🙂 

NOTE: All this article information is based on the Android Open Source Project source code. For details see http://source.android.com/.