Fetching Drop Call Event Issue on Android 2.3 above

Drop call event is an event that occurred when an active call is cut. Whether it is cut from caller or recipient or something else that cause the event occurred. Nowadays, there are many programming forums talking about the issue “how to get drop call cause event on android”. But unfortunatelly, they can’t answer the question correctly, even though there are a few people that almost give good answer ( that’s what I tough ). As we know that there are many drop call causes from explanation of android API it self. But in this case, the main problem is Android API that provide drop call cause is no more available on Android 2.3 or above. Because Google has made it to be hidden API from package android.telephony.
A few week ago, I also looking for the solution about this issue. I had done some small research to solve it. Based on my research, I’ve founded 3 solutions for this issue. The first is by accessing radio interface layer on Android ( we can use RIL ) . The second is by reading logcat from the device it self. The third is by using radio command ( AT Command ) to directly communicate through modem device. In this opportunity, I’d like to share you how to get drop call cause with the second idea which is by reading logcat.
1. Giving root access to Android device. We can use Kingo Root application
2. Create android project ( I use Android Studio ) with blank activity. Because we will create the activity.xml later.
MyActivity.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:id="@+id/btReadLog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start Listening"/>

    <Button
        android:id="@+id/btClearLog"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Clear Log"/>  
</LinearLayout>

DropCallCause.java

public class ActDropCallCause extends Activity {

    private List<String> dropCallCauseList;
    private Button btReadLog;
    private Button btClearLog;   
    Calendar now;
    Calendar afterXSecond;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.myactivity);
        btReadLog = (Button) findViewById(R.id.btReadLog);
        btReadLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                readDropCallCauseList();
            }
        });

        btClearLog = (Button) findViewById(R.id.btClearLog);
        btClearLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doClearLog();
            }

        });        
    }
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.drop_call_cause, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void doClearLog() {
        try {
            Runtime.getRuntime().exec("logcat -c");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /*Reading Logcat OnDisconnect Event ( Dropped Call ) for the last 5 minutes*/
    public void readDropCallCauseList(){
        dropCallCauseList = new ArrayList<String>();
        doClearLog();
        try {
            Process process = Runtime.getRuntime().exec("su -c logcat");
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            afterXSecond = Calendar.getInstance();
            afterXSecond.add(Calendar.SECOND, 60);
            now = Calendar.getInstance();

            while ( ( (line = bufferedReader.readLine()) != null ) && ( now.getTime().compareTo(afterXSecond.getTime()) <= 0 ) ) {
                if ( (line.contains("CallNotifier")) && line.contains("onDisconnect: cause")) {
                    Log.d("INCREMENT", String.valueOf(dropCallCauseList.size()));
                    line = new Date().toString()+line;
                    line=line.replace("/", ":").trim();
                    line = line.replaceAll("\\s+", "");
                    dropCallCauseList.add(line+"::");
                    Log.d("DCC", line);
                }
                now = Calendar.getInstance();
            }
            doClearLog();
            Log.d("SCHEDULER DCC", "CLEAR LOG");
            sendDropCallCause();
            Log.d("SCHEDULER DCC", "SENDING DCC");
            dropCallCauseList.clear();
            readDropCallCauseList();
            Log.d("SCHEDULER DCC", "START READING DCC");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

3. Run the project as Android application and do simulation.

Note : all solutions that I said above require root access to the device.

Tagged: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: