PDA

View Full Version : نحوه چک کردن Root بودن یا نبودن دستگاه



saeed_g21
یک شنبه 20 بهمن 1392, 21:03 عصر
سلام دوستان من یک کد پیدا کردم نمی دونم کد درست واجب میده یا نه
چطوری می تونم چد کنم دستگاه رووت است یا نه ؟
ایا کد زیر جواب گو است ؟
اخه دستگاه واقعی من رووت شدس و تو VMware هم که چک می کنم انگار اونم رووت است نمیدونم


try {

// Perform SU to get root privledges
p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("remount rw");
os.writeBytes("echo Root Test > /system/rootcheck.txt");
os.writeBytes("exit\n");
os.flush();
try {
p.waitFor();
if (p.exitValue() != 255){
//Phone is rooted
Log.d(tag, "Phone is Rooted");
}
else {
//Phone is not rooted
Log.d(tag, "Phone Not Rooted");
}
} catch (InterruptedException e) {
}
} catch (IOException e) {
}

rubiks.kde
یک شنبه 20 بهمن 1392, 21:49 عصر
از این تابع استفاده کنید در این تابع تمام روش ها بررسی شده.

/**
* Checks if the device is rooted.
*
* @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
*/
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;
}