Hello Everyone! Today i'll share an amazing fix for all the Dev's/Porters for their custom projects. As we all know now a days Mediatek had lots of custom rom available for their devices. Many of them are awesome and few of them are buggy because of some issues. Due to this issue the device is unable to detect radio networks. It makes the Dev's/Porter feel awkword and i can understand how it feels when your rom is best but it has a bug named "Ril Bug". 

Lets Start Now


Today i'll tell how to fix one of the major issue while porting any Rom like :
  • CyanogenMod/Lineage OS
  • AOSP
  • AOKP
  • AOSPA 
While porting any rom,sometime we encounter no "No Network" after booting the rom successfully.

But before this we will discuss on Ril. Let us read some fact about "Ril".

What is Ril? 

A RIL Stands for Radio Interface Layer, is a layer in an operating system which provides an interface to the hardware's radio and modem. For example a Mobile Phone or a Tablet.

Android Ril

The Android Open Source Project provides a Radio Interface Layer (RIL) between Android telephony services (android.telephony) and the radio hardware.
It consists of a stack of two components: a RIL Daemon and a Vendor RIL. The RIL Daemon talks to the telephony services and dispatches "solicited commands" to the Vendor RIL. The Vendor RIL is specific to a particular radio implementation, and dispatches "unsolicited commands" up to the RIL Daemon.

Windows Ril

A RIL is a key component of Microsoft's Windows Mobile OS. The RIL enables wireless voice or data applications to communicate with a GSM/GPRS or CDMA2000 1X modem on a Windows Mobile device. The RIL provides the system interface between the CellCore layer within the Windows Mobile OS and the radio protocol stack used by the wireless modem hardware. The RIL, therefore, also allows OEMs to integrate a variety of modems into their equipment by providing this interface.
The RIL comprises two separate components: a RIL driver, which processes AT commands and events; and a RIL proxy, which manages requests from the multiple clients to the single RIL driver. Except for PPP connections, all interaction between the Windows Mobile OS and the device radio stack is via the RIL. (PPP connections initially use the RIL to establish the connection, but then bypass the RIL to connect directly to the virtual serial port assigned to the modem.) In essence, the RIL accepts and converts all direct service requests from the upper layers (i.e., TAPI) into commands supported and understood by the modem.
Note that the RIL does not communicate directly with the modem, however. Instead, the final link to the modem is typically the standard serial driver provided by the OEM’s platform.

For More Detail Read This Section

Android's Radio Interface Layer (RIL) provides an abstraction layer between Android telephony services (android.telephony) and radio hardware. The RIL is radio agnostic, and includes support for Global System for Mobile communication (GSM)-based radios.

The diagram below illustrates the RIL in the context of Android's Telephony system architecture.
Solid elements represent Android blocks and dashed elements represent partner-specific proprietary blocks.

The RIL consists of two primary components:
RIL Daemon: The RIL daemon initializes the Vendor RIL, processes all communication from Android telephony services, and dispatches calls to the Vendor RIL as solicited commands.
Vendor RIL: The radio-specific Vendor RIL of ril.h that processes all communication with radio hardware and dispatches calls to the RIL Daemon (rild) through unsolicited commands.

RIL Initialization

Android initializes the telephony stack and the Vendor RIL at startup as described in the sequence below:
  1. RIL daemon reads rild.lib path and rild.libargs system properties to determine the Vendor RIL library to use and any initialization arguments to provide to the Vendor RIL
  2. RIL daemon loads the Vendor RIL library and calls RIL_Init to initialize the RIL and obtain a reference to RIL functions
  3. RIL daemon calls RIL_register on the Android telephony stack, providing a reference to the Vendor RIL functions
See the RIL Daemon source code at //device/commands/rild/rild.c for details.

RIL Interaction

There are two forms of communication that the RIL handles:
  • Solicited commands: Solicited commands originated by RIL lib, such as DIAL and HANGUP.
  • Unsolicited responses: Unsolicited responses that originate from the baseband, such as CALL_STATE_CHANGED and NEW_SMS.

Solicited

The following snippet illustrates the interface for solicited commands:
void OnRequest (int request_id, void *data, size_t datalen, RIL_Token t);

void OnRequestComplete (RIL_Token t, RIL_Error e, void *response, size_t responselen);
There are over sixty solicited commands grouped by the following families:
  • SIM PIN, IO, and IMSI/IMEI (11)
  • Call status and handling (dial, answer, mute…) (16)
  • Network status query (4)
  • Network setting (barring, forwarding, selection…) (12)
  • SMS (3)
  • PDP connection (4)
  • Power and reset (2)
  • Supplementary Services (5)
  • Vendor defined and support (4)
The following diagram illustrates a solicited call in Android.

Unsolicited

The following snippet illustrates the interface for unsolicited commands:
void OnUnsolicitedResponse (int unsolResponse, void *data, size_t datalen);
There are over ten unsolicited commands grouped by the following families:
  • Network status changed (4)
  • New SMS notify (3)
  • New USSD notify (2)
  • Signal strength or time changed (2)
The following diagram illustrates an unsolicited call in Android.

Implementing the RIL

To implement a radio-specific RIL, create a shared library that implements a set of functions required by Android to process radio requests. The required functions are defined in the RIL header (/include/telephony/ril.h).
The Android radio interface is radio-agnostic and the Vendor RIL can use any protocol to communicate with the radio. Android provides a reference Vendor RIL, using the Hayes AT command set, that you can use as a quick start for telephony testing and a guide for commercial vendor RILs. The source code for the reference RIL is found at
 /commands/reference-ril/
Compile your Vendor RIL as a shared library using the convention
libril--.so
for example, libril-acme-124.so, where:
  • libril: all vendor RIL implementations start with 'libril'
  • : a company-specific abbreviation
  • : RIL version number
  • so: file extension

RIL_Init

Your Vendor RIL must define a RIL_Init function that provides a handle to the functions which will process all radio requests. RIL_Init will be called by the Android RIL Daemon at boot time to initialize the RIL.
RIL_RadioFunctions *RIL_Init (RIL_Env* env, int argc, char **argv);
RIL_Init should return a RIL_RadioFunctions structure containing the handles to the radio functions:
type structure {
 int RIL_version;
 RIL_RequestFunc onRequest;
 RIL_RadioStateRequest onStateRequest;     
 RIL_Supports supports;
 RIL_Cancel onCancel;
 RIL_GetVersion getVersion;
}
RIL_RadioFunctions; 

RIL Functions

ril.h defines RIL states and variables, such as RIL_UNSOL_STK_CALL_SETUP, RIL_SIM_READY, RIL_SIM_NOT_READY, as well as the functions described in the tables below. Skim the header file (/device/include/telephony/ril.h) for details.

RIL Solicited Command Requests

The vendor RIL must provide the functions described in the table below to handle solicited commands. The RIL solicited command request types are defined in ril.h with the RIL_REQUEST_ prefix. Check the header file for details.

Name  & Description

1. Void (*RIL_RequestFunc) (int request, void *data, size_t datalen, RIL_Token t);
This is the RIL entry point for solicited commands and must be able to handle the various RIL solicited request types defined in ril.h with the RIL_REQUEST_ prefix
request is one of RIL_REQUEST_*
data is pointer to data defined for that RIL_REQUEST_*
t should be used in subsequent call to RIL_onResponse
datalen is owned by caller, and should not be modified or freed by callee
Must be completed with a call to RIL_onRequestComplete()RIL_onRequestComplete() may be called from any thread before or after this function returns. This will  always be called from the same thread, so returning here implies that the radio is ready to process another command (whether or not the previous command has completed).

2. RIL_RadioState (*RIL_RadioStateRequest)();
This function should return the current radio state synchronously.

3. int (*RIL_Supports)(int requestCode);
This function returns "1" if the specified RIL_REQUEST code is supported and 0 if it is not.

4. void (*RIL_Cancel)(RIL_Token t);
This function is used to indicate that a pending request should be canceled. This function is called from a separate thread--not the thread that calls RIL_RequestFunc.

On cancel, the callee should do its best to abandon the request and call RIL_onRequestComplete with RIL_Errno CANCELLED at some later point.

Subsequent calls to RIL_onRequestComplete for this request with other results will be tolerated but ignored (that is, it is valid to ignore the cancellation request).
RIL_Cancel calls should return immediately and not wait for cancellation.

5. const char * (*RIL_GetVersion) (void);
Return a version string for your Vendor RIL

The vendor RIL uses the following callback methods to communicate back to the Android RIL daemon.

1. void RIL_onRequestComplete(RIL_Token t,RIL_Errno e,void *response,size_t responselen);
      t is parameter passed in on previous call to RIL_Notification routine.
      If e != SUCCESS, then response can be null and is ignored
      response is owned by caller, and should not be modified or freed by callee
      RIL_onRequestComplete will return as soon as possible
      2. void RIL_requestTimedCallback (RIL_TimedCallback callback, void *param, const struct timeval *relativeTime);Call user-specified callback function on the same thread that RIL_RequestFunc is called. If relativeTime is specified, then it specifies a relative time value at which the callback is invoked. If relativeTime is NULL or points to a 0-filled structure, the callback will be invoked as soon as possible.

      RIL Unsolicited Commands

      The functions listed in the table below are call-back functions used by the Vendor RIL to invoke unsolicited commands on the Android platform. See ril.h for details.
        unsolResponse is one of RIL_UNSOL_RESPONSE_*
        data is pointer to data defined for that RIL_UNSOL_RESPONSE_*
        data is owned by caller, and should not be modified or freed by caller

        I Think Now You've Learned Many Things About RIL. You're Ready To Have The Fix.

        Here is your fixing file to fix Ril. This is only generic fix for Ril, Telephony.jar fix coming soon.

        Mediatek only

        Note: Replace the file given it the patch with yours and flash via Recovery. 

        Sources: Wikipedia, Google

        Thats it! If you like this particle please let me know by commenting your review/feedback below. Thankyou
        Sunmughan Swamy

        Sunmughan Swamy

        I am a Pro Blogger cum Android Developer. I am desperately passionate about developing Android Apps and Roms for Android Devices. I used to listen music during my work, meanwhile play video games,outdoor sports and much more. I have only 4 passion :-
        Design | Code | Compile | Debug

        Post A Comment:

        0 comments: