get Custom ROM name

Recently we had serious problems with testing some code at one client’s device that was running custom Android ROM. App was crashing due to missing libraries that didn’t come with custom ROM and both client and us didn’t know which ROM was on a device.

All that you can get from reading android.os.Build properties isn’t enough to determine which ROM device has, as it’s not guaranteed that ROM entered its description/name into any of its fields.

Here’s Java code snippet that you can use to grab custom ROM name. It worked nice with all sorts of CyanogenMod.

private String getCustomRomVersion()
{
	String modVer = 
		getSystemProperty("ro.modversion");
	return 
	(modVer == null || modVer.length() == 0 ? "Unknown" : modVer);
}
	
private String getSystemProperty(String propName)
{
	String line;
	BufferedReader input = null;
	try
	{
		Process proc = Runtime.getRuntime()
				.exec("getprop " + propName);

		input = new BufferedReader
		(new InputStreamReader(proc.getInputStream()), 1024);

		line = input.readLine();
		input.close();
	}
	catch (IOException ex)
	{
		return null;
	}
	finally
	{
		if (input != null)
		{
			try
			{
			   input.close();
			}
			catch (IOException e)
			{
			   //
			}
		}
	}
	return line;
}

Just call getCustomRomVersion() and read String output. If it’s Unknown, it should be non-rooted non-custom ROM, so you can read version name and other info from android.os.Build. Otherwise, it should return custom ROM name.

Advertisements
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: