tags:

views:

92

answers:

2

I have an automatic bug reporting facility in my app that includes useful information for debugging.

One thing that I would like to include is the ROM provider. In particular I would like to know if the user is running a custom ROM and which, preferably even with the version number.

Any idea how to retrieve this information programmatically?

--- Taken from the Quintin (see below)

http://code.google.com/p/cyanogen-updater/source/browse/trunk/src/cmupdaterapp/utils/SysUtils.java#19:

public static String getReadableModVersion() { 
  String modVer = getSystemProperty(Constants.SYS_PROP_MOD_VERSION); 
  return (modVer == null || modVer.length() == 0 ? "Unknown" : modVer); 
}

Whereby the constant is this:

public static final String SYS_PROP_MOD_VERSION = "ro.modversion";

And here is the getSystemProperty();

public static String getSystemProperty(String propName){
            String line;
            BufferedReader input = null;
    try
    {
            Process p = Runtime.getRuntime().exec("getprop " + propName);
        input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
        line = input.readLine();
        input.close();
    }
    catch (IOException ex)
    {
            Log.e(TAG, "Unable to read sysprop " + propName, ex);
            return null;
    }
    finally
    {
            if(input != null)
            {
                            try
                            {
                                    input.close();
                            }
                            catch (IOException e)
                            {
                                    Log.e(TAG, "Exception while closing InputStream", e);
                            }
            }
    }
    return line;
}

Could anybody with a CM ROM can run this for me?

Btw. Careful, this is GPL code. I for one can not use it. Any easier or non-GPL way?

+1  A: 

There is code in the Cyanogen-Updater project that has this functionality, although I think the rom information is provided by a prop file provided by the rom developer so i'm not sure if it will work universally. I haven't investigated this thoroughly, but you can take a look at the source and figure it out.

Quintin Robinson
I had a look. http://code.google.com/p/cyanogen-updater/source/browse/trunk/src/cmupdaterapp/utils/SysUtils.java#19 public static String getReadableModVersion() { String modVer = getSystemProperty(Constants.SYS_PROP_MOD_VERSION); return (modVer == null || modVer.length() == 0 ? "Unknown" : modVer);}Whereby the constant is this:public static final String SYS_PROP_MOD_VERSION = "ro.modversion";Do you run Cyanogen? Could you execute that for me and tell me the result?
Mariano Kamp
No formatting in the comments? Whatever I put it also on the top then.
Mariano Kamp
Yes I do have a version of his rom running, and the result of mine is "CyanogenMod-4.0.4", however when run on an official SDK build via the emulator I do get "Unknown". The `ro.modversion` is set in the build.prop file at /system/build.prop
Quintin Robinson
Thanks, very helpful!
Mariano Kamp
+2  A: 

I don't know if there's a clear indicator of the provider, but you could inspect the contents of /proc/version. Here's the output for CyanogenMod 4.0.4:

Linux version 2.6.29.6-cm4 (shade@toxygen) (gcc version 4.4.0 (GCC) ) #8 PREEMPT Fri Aug 28 20:30:25 EDT 2009

The hint here is the "cm4" suffix, which (I believe) stands for CyanogenMod 4 (plus the distinctive user@host bit, albeit less clear). For comparison, here's the version for the emulator running 1.6:

Linux version 2.6.27-00110-g132305e ([email protected]) (gcc version 4.2.1) #6 Mon Feb 2 12:47:38 PST 2009

You could also check the values for android.os.Build. There isn't much info on Build.TYPE, but I'm assuming type "eng" stands for official build, and type "user" stands for home-made build, so that could be useful too.

mernen
I think I will go for the other approach with the system property. But thanks anyway.Btw. I believe that the current, official, HTC hero rom runs an ENG build.
Mariano Kamp