content: package org.privacymatters.safespace.utils;
  
  import java.io.File;
  
  // Credits: https://stackoverflow.com/questions/57588643/how-to-detect-whether-the-device-is-rooted-or-not
  
  public class RootCheck {
      public static boolean isRooted() {
  
          // 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
          if (!(canExecuteCommand("su") ||
                  canExecuteCommand("/system/xbin/which su") ||
                  canExecuteCommand("/system/bin/which su") ||
                  canExecuteCommand("which su")))
              return findBinary();
          return false;
      }
  
      private static boolean findBinary() {
          String binaryName = "su";
          boolean found = false;
          String[] places = {"/sbin/", "/system/bin/", "/system/xbin/",
                  "/data/local/xbin/", "/data/local/bin/",
                  "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"};
          for (String where : places) {
              if (new File(where + binaryName).exists()) {
                  found = true;
                  break;
              }
          }
          return found;
      }
  
      // 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;
      }
  }
  