Jijith J
Jijith J

Reputation: 173

Check custom rom in android programmatically

I want to check in my app that the device has custom ROM or not. With this I have enable and disable some features in my app. Please help me.

Upvotes: 1

Views: 3146

Answers (3)

user15254501
user15254501

Reputation:

Try using Googles Saftynet service (it detects if bootloader is unlocked, to install a custom Rom bootloader must be unlocked)... It can be spoofed but not a lot users know how to do that. If you only detect root the app also doesn't run on stock Rom, when stock is rooted.

Upvotes: 0

Abdul Waheed
Abdul Waheed

Reputation: 4678

System.getProperty("os.version"); // OS version
android.os.Build.VERSION.SDK      // API Level
android.os.Build.DEVICE           // Device
android.os.Build.MODEL            // Model 
android.os.Build.PRODUCT          // Product

Use this and then compare it with the Google stock images.One more thing, almost 99% of all the custom ROMs are rooted so you could check whether the device is rooted or not. The RootTools library offers simple methods to check for root:

RootTools.isRootAvailable()

You may refer below links for further details How to find out who the ROM provider is? And for RootTools use below link

https://github.com/Stericson/RootTools

Upvotes: 1

Rahul Ahuja
Rahul Ahuja

Reputation: 812

Check these properties in your code and then compare it with the Google stock images.

System.getProperty("os.version"); // OS version
android.os.Build.VERSION.SDK      // API Level
android.os.Build.DEVICE           // Device
android.os.Build.MODEL            // Model 
android.os.Build.PRODUCT          // Product

almost of all the custom ROMs are rooted so you can also check whether the device is rooted or not. Below is the code to check root.

    public static boolean isRooted() {

    // get from build info
    String buildTags = android.os.Build.TAGS;
    if (buildTags != null && buildTags.contains("test-keys")) {
      return true;
    }

    // check if /system/app/Superuser.apk is present
    try {
      File file = new File("/system/app/Superuser.apk");
      if (file.exists()) {
        return true;
      }
    } catch (Exception e1) {
      // ignore
    }

    // try executing commands
    return canExecuteCommand("/system/xbin/which su")
        || canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
  }

  // executes a command on the system
  private static boolean canExecuteCommand(String command) {
    boolean executedSuccesfully;
    try {
      Runtime.getRuntime().exec(command);
      executedSuccesfully = true;
    } catch (Exception e) {
      executedSuccesfully = false;
    }

    return executedSuccesfully;
  }

PS - emulator is a rooted devices. Test on actual device

Upvotes: 1

Related Questions