Tuesday, September 27, 2011

How to brick your android device?

Today, While I was digging into android source code, I found this. Never tried it. Drop me a message here if you do.

package com.android.server;

import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;
import android.os.SystemService;
import android.util.Log;

public class BrickReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.w("BrickReceiver", "!!! BRICKING DEVICE !!!");
SystemService.start("brick");
}
}



Friday, September 23, 2011

How to debug Android source code in Eclipse?

Today, I wanted to know what's going on inside Android because it was keep throwing an exception . So i wanted to check how to debug an Android application right from Eclipse IDE. When I googled I found this link,

http://android.opensourceror.org/2010/01/18/android-source/

but it says how to debug a single version of android eg. Cupcake. Now problem is how to debug multiple versions of Android ?

it's easy.

all you have to do is open the .project in notepad
\workspace\.metadata\.plugins\org.eclipse.jdt.core\.org.eclipse.jdt.core.external.folders

and another element to the section.



         .link0
         2
         C:/Aruna/Android/android-sdk_r08-windows/android-sdk-windows/Cupcake
  
     
         .link1
         2
         C:/Aruna/Android/android-sdk_r08-windows/android-sdk-windows/Donut
  


IllegalStateException: Couldn't init cursor window

Today one of our application started getting this exception.
java.lang.IllegalStateException: Couldn't init cursor window at android.database.CursorWindow.native_init(Native Method) at android.database.CursorWindow.(CursorWindow.java:41) at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:277) at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:269)
After few hours of googling, I found the solution to this problem. Solution is to close the Cursor after after you are done!This exception is thrown here
if (!window->initBuffer(localOnly)) { jniThrowException(env, "java/lang/IllegalStateException", "Couldn't init cursor window"); delete window; return; }
localOnly is defined in
CursorWindow.h
as
#define MAX_WINDOW_SIZE (1024 * 1024)
So, There are two possible causes to throw this exception. 1. Your mobile phone is out of memory.2. You are fetching something out of the database more than 1M. If there is a logical way to divide your queries into discrete chunks, you could do incremental queries and use CursorJoiner to stitch them together that might help you if you are dealing with big chuck of data.

So lesson learned, Close the cursor in a try finally block

Cursor cursor;
try {
cursor.open();
}
finally{
if(cursor.isOpen()) {
cursor.close();
}

Wednesday, September 7, 2011

Error retrieving parent for item: No resource found that matches the given name 'android:WindowTitleBackground'.

Today while trying to compile a project I got for github I got this error.

Error retrieving parent for item: No resource found that matches the given name 'android:WindowTitleBackground'.

It's so annoying because it worked perfectly in one machine and on my laptop it did not. When I was almost given up I thought of replacing the platform tools with old platform tools and it worked!!

Download the revision 11 tools from here

http://dl.google.com/android/repository/tools_r11-windows.zip

and rename your platform-tools folder in android-sdk-windows and paste this there. That should work!