tags:

views:

3794

answers:

6

My app has a certain piece of functionality that will only work on a device where root is available. Rather than having this feature fail when it is used (and then show an appropriate error message to the user), I'd prefer an ability to silently check if root is available first, and if not,hide the respective options in the first place.

Is there a way to do this?

+2  A: 

Some modified builds used to set the system property ro.modversion for this purpose. Things seem to have moved on; my build from TheDude a few months ago has this:

cmb@apollo:~$ adb -d shell getprop |grep build
[ro.build.id]: [CUPCAKE]
[ro.build.display.id]: [htc_dream-eng 1.5 CUPCAKE eng.TheDudeAbides.20090427.235325 test-keys]
[ro.build.version.incremental]: [eng.TheDude.2009027.235325]
[ro.build.version.sdk]: [3]
[ro.build.version.release]: [1.5]
[ro.build.date]: [Mon Apr 20 01:42:32 CDT 2009]
[ro.build.date.utc]: [1240209752]
[ro.build.type]: [eng]
[ro.build.user]: [TheDude]
[ro.build.host]: [ender]
[ro.build.tags]: [test-keys]
[ro.build.product]: [dream]
[ro.build.description]: [kila-user 1.1 PLAT-RC33 126986 ota-rel-keys,release-keys]
[ro.build.fingerprint]: [tmobile/kila/dream/trout:1.1/PLAT-RC33/126986:user/ota-rel-keys,release-keys]
[ro.build.changelist]: [17615# end build properties]

The emulator from the 1.5 SDK on the other hand, running the 1.5 image, also has root, is probably similar to the Android Dev Phone 1 (which you presumably want to allow) and has this:

cmb@apollo:~$ adb -e shell getprop |grep build
[ro.build.id]: [CUPCAKE]
[ro.build.display.id]: [sdk-eng 1.5 CUPCAKE 148875 test-keys]
[ro.build.version.incremental]: [148875]
[ro.build.version.sdk]: [3]
[ro.build.version.release]: [1.5]
[ro.build.date]: [Thu May 14 18:09:10 PDT 2009]
[ro.build.date.utc]: [1242349750]
[ro.build.type]: [eng]
[ro.build.user]: [android-build]
[ro.build.host]: [undroid16.mtv.corp.google.com]
[ro.build.tags]: [test-keys]
[ro.build.product]: [generic]
[ro.build.description]: [sdk-eng 1.5 CUPCAKE 148875 test-keys]
[ro.build.fingerprint]: [generic/sdk/generic/:1.5/CUPCAKE/148875:eng/test-keys]

As for the retail builds, I don't have one to hand, but various searches under site:xda-developers.com are informative. Here is a G1 in the Netherlands, you can see that ro.build.tags does not have test-keys, and I think that's probably the most reliable property to use.

Chris Boyle
That looks interesting, but: While the emulator (and ADP) do allow root per se, they don't allow applications to use it, i.e.:$ su app_29$ su su: uid 10029 not allowed to su
miracle2k
Ah, I suppose they wouldn't... you could combine it with a check for ro.build.host (not) ending in google.com then, if they're the only ones that have test-keys but block su without asking the user. Depends what the build host is for newer devices, things that aren't phones... not easy.
Chris Boyle
A: 
Christopher
A: 

This may not work, as even on rooted devices the app cannot access /data location, whereas with su we can access all the filesystem

rupender
A: 

You can try and send file to the data directory: adb push myfile.txt /data

Guy
A: 

To see is you are "rooted" download or use terminal app

At the $ prompt type su should return a prompt now of #

now enter cd /data/app-private if you can do all that then you are rooted

tfranzman
A: 

I think most rooting procedures should contain copying files named "su" and "Superuser.apk" to your phone.

After rebooting the phone, plug in USB and type in terminal:

adb shell

You should see a dollar sign ($). Then type

su

The Superuser app should ask for permission on phone. Click "allow always" and then you'll see the little rooted # sign.

This means you have the root permissions.

Papuass