AppsCheck API provide developer apps with a list of malicious apps on HUAWEI mobile phones.
1. The accuracy rate of malicious app checks reaches 99%.
2. Unknown threats can be detected based on behavior.
You can obtain a list of malicious apps and evaluate whether to restrict your app’s behavior based on risk.
For details, please refer to Development Procedure.
Before using the AppsCheck API of Safety Detect, you must ensure that Huawei Mobile Services (APK) of the required version has been installed on the user device. If the installed version is not the required one, your app may stop responding after calling the API. If your app detects that the Huawei Mobile Services (APK) version installed on user devices is not the required one, it should ask the user to update Huawei Mobile Services (APK).
To check whether the installed Huawei Mobile Services (APK) version is compatible with your Android SDK version, call the isHuaweiMobileServicesAvailable() method. The sample code is as follows:
- if (HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context) == ConnectionResult.SUCCESS){
- // The SafetyDetect SysIntegrity API is available.
- } else {
- // Prompt user to update HMS.
- }
You can directly call getMaliciousAppsList() of the SafetyDetectClient to obtain a list of malicious apps.
- private void invokeGetMaliciousApps() {
- SafetyDetectClient appsCheckClient = SafetyDetect.getClient(MainActivity.this);
- Task task = appsCheckClient.getMaliciousAppsList();
- task.addOnSuccessListener(new OnSuccessListener<MaliciousAppsListResp>() {
- @Override
- public void onSuccess(MaliciousAppsListResp maliciousAppsListResp) {
- // Indicates communication with the service was successful.
- // Use resp.getMaliciousApps() to get malicious apps data.
- List<MaliciousAppsData> appsDataList = maliciousAppsListResp.getMaliciousAppsList();
- // Indicates get malicious apps was successful.
- if(maliciousAppsListResp.getRtnCode() == CommonCode.OK) {
- if (appsDataList.isEmpty()) {
- // Indicates there are no known malicious apps.
- Log.i(TAG, "There are no known potentially malicious apps installed.");
- } else {
- Log.i(TAG, "Potentially malicious apps are installed!");
- for (MaliciousAppsData maliciousApp : appsDataList) {
- Log.i(TAG, "Information about a malicious app:");
- // Use getApkPackageName() to get APK name of malicious app.
- Log.i(TAG, "APK: " + maliciousApp.getApkPackageName());
- // Use getApkSha256() to get APK sha256 of malicious app.
- Log.i(TAG, "SHA-256: " + maliciousApp.getApkSha256());
- // Use getApkCategory() to get category of malicious app.
- // Categories are defined in AppsCheckConstants
- Log.i(TAG, "Category: " + maliciousApp.getApkCategory());
- }
- }
- }else{
- Log.e(TAG,"getMaliciousAppsList fialed: "+maliciousAppsListResp.getErrorReason());
- }
- }
- }).addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(Exception e) {
- // An error occurred while communicating with the service.
- if (e instanceof ApiException) {
- // An error with the HMS API contains some
- // additional details.
- ApiException apiException = (ApiException) e;
- // You can retrieve the status code using the apiException.getStatusCode() method.
- Log.e(TAG, "Error: " + SafetyDetectStatusCodes.getStatusCodeString(apiException.getStatusCode()) + ": " + apiException.getStatusMessage());
- } else {
- // A different, unknown type of error occurred.
- Log.e(TAG, "ERROR: " + e.getMessage());
- }
- }
- });
- }