Code Painters The Art of Coding

28Jan/130

Embedded Android from O’Reilly – finally!

I've just received an e-mail about a new update of "Embedded Android" e-book available. Finally! It took 15 months to write all the chapters (the first early preview from October 2011 contained only 4 chapters), browsing the PDF confirmed however that it was worth waiting. If you're serious about Android development, this book is a must!

3May/120

Embedded Android from O’Reilly is coming!

Note: Code Painters site is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com.

There are dozens of books about Android application development published already, adding little value to what can be found in the official Android developer's guide. On the other hand, no single book has been published until now (as far as I know) about porting and customizing the platform itself, making AOSP site and mailing lists the only sources of information. This situation is going to change with Embedded Android: Porting, Extending, and Customizing by Karim Yaghmour coming from O'Reilly in June.

The first four chapters of the book are already available directly from O'Reilly (digital Early Release). What's available now is already worth looking at, let me describe the contents briefly. Continue reading…

17Feb/120

Why java.nio is a better idea for Android

In my recent Android project I've encountered totally unexpected, low-level problems with TCP sockets. The problem occurs when you try to interrupt a blocking socket I/O by closing the socket. It is expected for the blocked operation to throw a SocketError exception immediately when the socket is closed from another thread (that's the only way to interrupt blocking socket operation, actually - Thread.interrupt() doesn't abort blocked I/O). Continue reading…

17Jan/120

How to obtain GTalk Android ID

While googling around, I've stumbled upon an interesting project - Android Market API. This project is clearly a result of some Android reverse engineering work, still it's hosted on Google Code site. Funny, isn't it? Oh, by the way - the Android Market protocol uses Google's Protocol Buffers with HTTP as a transport layer.

Anyway, to play with the API you need a Google account (obviously), but also a sort of device identifier referred to as "Android ID". Funny enough, this is not the Android ID which can be obtained using android.provider.Settings.Secure class etc., the right ID can be obtained by "dialing" *#*#8255#*#* - look for Device ID, remove `android-` prefix.

But is there a way to retrieve this ID programmatically? It required a bit of hacking to reveal, but here's the recipe:

	private static final Uri URI = Uri
			.parse("content://com.google.android.gsf.gservices");
	private static final String ID_KEY = "android_id";

	String getAndroidId(Context ctx) {
		String[] params = { ID_KEY };
		Cursor c = ctx.getContentResolver()
				.query(URI, null, null, params, null);

		if (!c.moveToFirst() || c.getColumnCount() < 2)
			return null;

		try {
			return Long.toHexString(Long.parseLong(c.getString(1)));
		} catch (NumberFormatException e) {
			return null;
		}
	}

This code requires extra com.google.android.providers.gsf.permission.READ_GSERVICES permission, be sure to add the following line to your AndroidManifest.xml:

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

That's it!

13Feb/115

Reverse engineering Android applications – part I

Have you ever wondered how difficult or easy is it to reverse engineer an Android application? The task is surprisingly easy with all the tools available these days. Let's try to reverse engineer a sample open-source application available for download from Android Market - Barcode Scanner. For all the experiments I've used my HTC Desire. Continue reading…

15Jan/110

Android MediaPlayer and short WAV files

I've recently observed an interesting issue with MediaPlayer on HTC Desire and Legend (I had no chance yet to check other phones) - it refuses to play a short, otherwise perfectly valid 22050Hz linear PCM 16-bit WAV file. Strictly speaking, there's no error reported or any exception visible in logs, but also there is no sound played.

The only exceptional thing about the WAV files we used is the length, the files are about 80ms each - short beeps to play as a button press feedback. To solve the problem it was necessary to append a period of silence to each file, to make it at least 200ms long.

I can guess the reason - perhaps the media player implementation disables the decoder right after injecting the last chunk of data, not waiting for this very last chunk to decode?

20Nov/1054

Android emulator patch for configurable IMEI, IMSI and SIM card serial number

My post about hacking the emulator's IMEI number gained a lot of interest, hence I've decided to prepare a patch which makes IMEI, IMSI and SIM card serial configurable on a per-AVD basis. It's necessary to recompile the emulator with the patch applied, so setup your build environment as a first step. I suggest using Ubuntu 10.10 and following the Android compilation hints. Continue reading…

Tagged as: , 54 Comments
27Oct/104

Compiling Android SDK on Ubuntu 10.10 (Maverick Meerkat)

A lot of time passed since my previous post about Android platform compilation, and the build process has improved a bit since then (for sure it's a less frustrating experience now). Below is the up-to-date recipe for the SDK (master and froyo branches) build on Ubuntu 10.10. Please note, that although the sdk target is my focus (that is, the whole SDK package, including the platform, emulator and all the other tools like adb, ddms, etc.), the recipe is also perfectly useful if you want to build any part of the SDK alone, it's just necessary to use a different make target. Continue reading…

Tagged as: 4 Comments
6Sep/102

Android emulator and the SIM card serial number

Update: Please see my latest post about this topic.

After publishing the post about changing the IMEI number, I was asked about modifying the SIM card serial number. Yes, it is perfectly possible, but requires a bit more investigation. In general, the mechanism used is the same (i.e. AT commands sent to the emulated GSM modem). Continue reading…

Tagged as: , 2 Comments
23Jan/100

Android’s HTTPS implementation slow under debugger

Update: I've just discovered that the problem described below only affects Android 1.5 (which is the target platform for my project). Thus another solution is to use AVD configured with Android 1.6 or higher for debugging, and use version 1.5 otherwise to ensure compatibility.

The project I'm working on now communicates with server via custom protocol on top of HTTP and HTTPS (using org.apache.http.client.HttpClient as a HTTP/HTTPS implementation provider). Recently I've observed interesting problem of HTTPS requests taking ages to complete if application is executing under debugger control. It makes debugging the code quite frustrating. Continue reading…