-
-
Save antslava/0edbd1cecf7c04013948 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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