DashO can inject Emulator checks into Android applications and libraries to detect whether the application is running on an emulator. Configure an immediate built-in response, pass the result to application code, or store the result for one or more separate Emulator responses.
Before you begin
- Inject the check into a class that provides getApplicationContext(). Activities, Application classes, Services, and other Context subclasses inherit this method.
- If the target class does not provide getApplicationContext(), add a method that returns the correct Android Context.
- Decide how emulator detection should affect development, automated testing, and production builds before enabling a disruptive response.
Configure an Emulator check
Configure the check on Checks > Emulator in DashO, or add an EmulatorCheck annotation:
private static boolean emulatorFlag;
@EmulatorCheck(action="@emulatorFlag")
public void onCreate(Bundle check){
}
@EmulatorCheck(response=ResponseType.Hang)
private int computeResult(){
}The first check stores the result in emulatorDetected. The second check performs a Hang response immediately when DashO detects an emulator.
Configure a separate Emulator response
private static boolean emulatorFlag;
@EmulatorCheck(action="@emulatorFlag")
public void onCreate(Bundle state){
}
@EmulatorResponse(source="@emulatorFlag", response=ResponseType.Exit, probability=0.05f)
private int computeResult(){
}
@EmulatorResponse(source="@emulatorFlag", response=ResponseType.Error, probability=0.1f)
private FileInputStream readInput(){
}Both responses read the same check result but run in different methods and use different probabilities.