Skip to content

Instantly share code, notes, and snippets.

@antslava
Forked from stefanhoth/RootStatus.java
Last active August 29, 2015 14:16
Show Gist options
  • Save antslava/0edbd1cecf7c04013948 to your computer and use it in GitHub Desktop.
Save antslava/0edbd1cecf7c04013948 to your computer and use it in GitHub Desktop.
package com.yourapp;
import java.io.File;
public final class RootStatus {
private static RootStatus instance;
private final boolean rooted;
private RootStatus(final boolean rooted) {
this.rooted = rooted;
}
private static synchronized RootStatus getInstance() {
if (instance == null) {
final boolean rooted = hasSuExecutable();
instance = new RootStatus(rooted);
}
return instance;
}
private static boolean hasSuExecutable() {
return binaryExists("su");
}
private static boolean binaryExists(final String binaryName) {
final String[] places = {"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/",
"/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"};
for (final String where : places) {
if (new File(where, binaryName).exists()) {
return true;
}
}
return false;
}
public static boolean isRooted() {
return getInstance().rooted;
}
}
package com.yourapp;
// imports
public class YourActivity extends Activity {
public void onCreate(Bundle savedInstance) {
if(Rootstatus.isRooted() ){
// OH NO!
} else {
// All good.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment