Tamper protection by detecting the installer, emulator, and debug flag
In this recipe, we will look at three additional checks that may indicate a tampered, compromised, or hostile environment. These are designed to be activated once you are ready for release.
How to do it...
These tamper checks can be located anywhere in your app, but it makes the most sense to allow them to be called from multiple places at a separate class or parent class.
Detect if Google Play store was the installer:
public static boolean checkGooglePlayStore(Context context) { String installerPackageName = context.getPackageManager() .getInstallerPackageName(context.getPackageName()); return installerPackageName != null && installerPackageName.startsWith("com.google.android"); }
Detect if it runs on an emulator:
public static boolean isEmulator() { try { Class systemPropertyClazz = Class .forName("android.os.SystemProperties"); boolean kernelQemu = getProperty(systemPropertyClazz...