public boolean checkRootMethod1() {
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
returntrue;
}
returnfalse;
}
public boolean checkRootMethod2() {
try {
File file =new File("/system/app/Superuser.apk");
if (file.exists()) {
returntrue;
}
} catch (Exception e) {
}
returnfalse;
}
public boolean checkRootMethod3() {
int kSystemRootStateUnknow = -1;
int kSystemRootStateDisable = 0;
int kSystemRootStateEnable = 1;
int systemRootState = kSystemRootStateUnknow;
if (systemRootState == kSystemRootStateEnable) {
returntrue;
} else if (systemRootState == kSystemRootStateDisable) {
returnfalse;
}
File f = null;
final String kSuSearchPaths[] = {"/system/bin/", "/system/xbin/", "/system/sbin/",
"/sbin/","/vendor/bin/" };
try {
for (int i = 0; i < kSuSearchPaths.length; i++) {
f = new File(kSuSearchPaths[i] + "su");
if (f !=null && f.exists()) {
systemRootState = kSystemRootStateEnable;
returntrue;
}
}
} catch (Exception e) {
}
systemRootState = kSystemRootStateDisable;
returnfalse;
}
public boolean checkRootMethod4() {
if (new ExecShell().executeCommand(SHELL_CMD.check_su_binary) !=null) {
returntrue;
} else {
returnfalse;
}
}
package com.example.test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import android.util.Log;
public class ExecShell {
private static final String LOG_TAG = ExecShell.class.getName();
public static enum SHELL_CMD {
check_su_binary(new String[] { "/system/xbin/which", "su" }), ;
String[] command;
SHELL_CMD(String[] command) {
this.command = command;
}
}
public ArrayList executeCommand(SHELL_CMD shellCmd) {
String line = null;
ArrayList fullResponse = new ArrayList();
Process localProcess = null;
try {
localProcess = Runtime.getRuntime().exec(shellCmd.command);
} catch (Exception e) {
return null;
// e.printStackTrace();
}
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
localProcess.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(localProcess.getInputStream()));
try {
while ((line = in.readLine()) != null) {
Log.d(LOG_TAG, "--> Line received: " + line);
fullResponse.add(line);
}
} catch (Exception e) {
e.printStackTrace();
}
Log.d(LOG_TAG, "--> Full response was: " + fullResponse);
return fullResponse;
}
}
android判断手机是否root
最新推荐文章于 2024-05-24 21:30:00 发布