DashO can inject Root checks into Android applications and libraries to detect whether the application is running on a rooted device. Configure an immediate response, pass the result to application code, or store the result for one or more separate Root responses.
Before you begin
- Inject the check into a class that provides getApplicationContext(). Classes extending
android.context.Context, likeandroid.app.Activity,android.app.Application,android.app.Service, etc. will inheritgetApplicationContext(), and require no additional changes. - Otherwise, you will need to add a
getApplicationContext()method and make sure it returns a properContext. - Enabling the QUERY_ALL_PACKAGES permission improves Root Check detection.
- You may also need to suppress the
QueryAllPackagesPermissionlint check. - Root Checks may also trigger when running on an emulator or unsecured custom ROM.
Configure a Root check
Configure the check on Checks > Root in DashO, or add a RootCheck annotation:
private static boolean rootedFlag;
@RootCheck(action="@rootedFlag")
public void onCreate(Bundle check){
}
@RootCheck(response=ResponseType.Hang)
private int computeResult(){
}Configure a separate Root response
private static boolean rootedFlag;
@RootCheck(action="@rootedFlag")
public void onCreate(Bundle state){
}
@RootResponse(source="@rootedFlag", response=ResponseType.Exit, probability=0.05f)
private int computeResult(){
}
@RootResponse(source="@rootedFlag", response=ResponseType.Error, probability=0.1f)
private FileInputStream readInput(){
}Improve package-based detection
If the application is eligible to use QUERY_ALL_PACKAGES, add the permission to the Android manifest and suppress the QueryAllPackagesPermission lint check only when your development policy allows it. Review the current Google Play policy before distributing the application.