Last active
October 12, 2018 09:13
-
-
Save wanzismail/cc2eb22acf304ec6d7ed2664dfd3927c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static boolean isEmulator() { | |
return Build.FINGERPRINT.startsWith("generic") | |
|| Build.FINGERPRINT.startsWith("unknown") | |
|| Build.MODEL.contains("google_sdk") | |
|| Build.MODEL.contains("Emulator") | |
|| Build.MODEL.contains("Android SDK built for x86") | |
|| Build.MANUFACTURER.contains("Genymotion") | |
|| (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")) | |
|| "google_sdk".equals(Build.PRODUCT); | |
} | |
public static boolean isRooted(Context context) { | |
boolean isEmulator = !isRealDevice(context); | |
String buildTags = Build.TAGS; | |
if (!isEmulator && buildTags != null && buildTags.contains("test-keys")) { | |
return true; | |
} else { | |
File file = new File("/system/app/Superuser.apk"); | |
if (file.exists()) { | |
return true; | |
} else { | |
file = new File("/system/xbin/su"); | |
return !isEmulator && file.exists(); | |
} | |
} | |
} | |
public static boolean isRealDevice(Context context) { | |
String androidId = android.provider.Settings.Secure.getString(context.getContentResolver(), | |
android.provider.Settings.Secure.ANDROID_ID); | |
SensorManager manager = (SensorManager) context.getSystemService(SENSOR_SERVICE); | |
return (!isEmulator() | |
&& (androidId != null | |
|| !androidId.equals("") | |
|| !androidId.equals("null") | |
|| !androidId.equals("NULL")) | |
&& (Build.SERIAL != null | |
|| !Build.SERIAL.equals("") | |
|| !Build.SERIAL.equals(" ") | |
|| !Build.SERIAL.equals("null") | |
|| !Build.SERIAL.equals("NULL") | |
|| !Build.SERIAL.equals("unknown")) | |
&& !manager.getSensorList(Sensor.TYPE_ALL).isEmpty()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment