Last active
December 5, 2021 16:00
-
-
Save ShinJJang/9fac5e779f23d478a234 to your computer and use it in GitHub Desktop.
Test for detect virtual device in android
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
// This is not perfect | |
private boolean isVirtualDeivce() { | |
String msg = "BOARD = " + Build.BOARD + | |
"\nBOOOTLOADER = " + Build.BOOTLOADER + | |
"\nBRAND = " + Build.BRAND + | |
"\nDEVICE = " + Build.DEVICE + | |
"\nDISPLAY = " + Build.DISPLAY + | |
"\nFINGERPRINT = " + Build.FINGERPRINT + | |
"\nHARDWARE = " + Build.HARDWARE + | |
"\nHOST = " + Build.HOST + | |
"\nID = " + Build.ID + | |
"\nMANUFACTURER = " + Build.MANUFACTURER + | |
"\nMODEL = " + Build.MODEL + | |
"\nPRODUCT = " + Build.PRODUCT + | |
"\nRADIO = " + Build.getRadioVersion() + | |
"\nSERIAL = " + Build.SERIAL + | |
"\nTAGS = " + Build.TAGS + | |
"\nTYPE = " + Build.TYPE + | |
"\nUSER = " + Build.USER; | |
Log.i("adb", msg); | |
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); | |
alertDialog.setTitle("info"); | |
alertDialog.setMessage(msg); | |
alertDialog.show(); | |
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); | |
} | |
// Below, forked from https://github.com/oguzhantopgul/Android-Emulator-Detection/blob/master/src/com/ouz/evasion/EvasionMainActivity.java | |
// (IMO) "ro.secure", "ro.kernel.qemu" cann't work with jailbreak. | |
// This properties mean adb shell as root. So not only virtual device, also jailbreak too. | |
public Boolean isEmulator(Context paramContext) | |
{ | |
Boolean isEmulator = false; | |
try { | |
Class SystemProperties = Class.forName("android.os.SystemProperties"); | |
TelephonyManager localTelephonyManager = (TelephonyManager)paramContext.getSystemService(TELEPHONY_SERVICE); | |
if (getProperty(SystemProperties, "ro.secure").equalsIgnoreCase("0")) | |
isEmulator = Boolean.valueOf(true); | |
else if (getProperty(SystemProperties, "ro.kernel.qemu").equalsIgnoreCase("1")) | |
isEmulator = Boolean.valueOf(true); | |
else if (Build.PRODUCT.contains("sdk")) | |
isEmulator = Boolean.valueOf(true); | |
else if (Build.MODEL.contains("sdk")) | |
isEmulator = Boolean.valueOf(true); | |
else if(localTelephonyManager.getSimOperatorName().equals("Android")) | |
isEmulator = Boolean.valueOf(true); | |
else if(localTelephonyManager.getNetworkOperatorName().equals("Android")) | |
isEmulator = Boolean.valueOf(true); | |
else | |
isEmulator = Boolean.valueOf(false); | |
String msg = "ro.secure = " + getProperty(SystemProperties, "ro.secure") + | |
"\nro.kernel.qemu = " + getProperty(SystemProperties, "ro.kernel.qemu") + | |
"\nSimOperatorName = " + localTelephonyManager.getSimOperatorName() + | |
"\nNetworkOperatorName = " + localTelephonyManager.getNetworkOperatorName(); | |
Log.i("adb", msg); | |
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); | |
alertDialog.setTitle("info"); | |
alertDialog.setMessage(msg); | |
alertDialog.show(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return isEmulator; | |
} | |
private static String getProperty(Class myClass, String propertyName) throws Exception { | |
return (String) myClass.getMethod("get", String.class).invoke(myClass, propertyName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment