目录

1. Service Features

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.


2. Use Cases

You can obtain a list of malicious apps and evaluate whether to restrict your app’s  behavior based on risk.

3. Development Procedure 

For details, please refer to Development Procedure.

4. Developing an App

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:

  1. if (HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context) == ConnectionResult.SUCCESS){
  2.    // The SafetyDetect SysIntegrity API is available.
  3. } else {
  4.    // Prompt user to update HMS.
  5. }

4.1 Calling the AppsCheck API

You can directly call  getMaliciousAppsList() of the SafetyDetectClient  to obtain a list of malicious apps.

  1. private void invokeGetMaliciousApps() {
  2.        SafetyDetectClient appsCheckClient = SafetyDetect.getClient(MainActivity.this);
  3.        Task task = appsCheckClient.getMaliciousAppsList();
  4.        task.addOnSuccessListener(new OnSuccessListener<MaliciousAppsListResp>() {
  5.            @Override
  6.            public void onSuccess(MaliciousAppsListResp maliciousAppsListResp) {
  7.                // Indicates communication with the service was successful.
  8.                // Use resp.getMaliciousApps() to get malicious apps data.
  9.                List<MaliciousAppsData> appsDataList = maliciousAppsListResp.getMaliciousAppsList();
  10.                // Indicates get malicious apps was successful.
  11.                if(maliciousAppsListResp.getRtnCode() == CommonCode.OK) {
  12.                    if (appsDataList.isEmpty()) {
  13.                        // Indicates there are no known malicious apps.
  14.                        Log.i(TAG, "There are no known potentially malicious apps installed.");
  15.                    } else {
  16.                        Log.i(TAG, "Potentially malicious apps are installed!");
  17.                        for (MaliciousAppsData maliciousApp : appsDataList) {
  18.                            Log.i(TAG, "Information about a malicious app:");
  19.                            // Use getApkPackageName() to get APK name of malicious app.
  20.                            Log.i(TAG, "APK: " + maliciousApp.getApkPackageName());
  21.                            // Use getApkSha256() to get APK sha256 of malicious app.
  22.                            Log.i(TAG, "SHA-256: " + maliciousApp.getApkSha256());
  23.                            // Use getApkCategory() to get category of malicious app.
  24.                            // Categories are defined in AppsCheckConstants
  25.                            Log.i(TAG, "Category: " + maliciousApp.getApkCategory());
  26.                        }
  27.                    }
  28.                }else{
  29.                    Log.e(TAG,"getMaliciousAppsList fialed: "+maliciousAppsListResp.getErrorReason());
  30.                }
  31.            }
  32.        }).addOnFailureListener(new OnFailureListener() {
  33.            @Override
  34.            public void onFailure(Exception e) {
  35.                // An error occurred while communicating with the service.
  36.                if (e instanceof ApiException) {
  37.                    // An error with the HMS API contains some
  38.                    // additional details.
  39.                    ApiException apiException = (ApiException) e;
  40.                    // You can retrieve the status code using the apiException.getStatusCode() method.
  41.                    Log.e(TAG, "Error: " +  SafetyDetectStatusCodes.getStatusCodeString(apiException.getStatusCode()) + ": " + apiException.getStatusMessage());
  42.                } else {
  43.                    // A different, unknown type of error occurred.
  44.                    Log.e(TAG, "ERROR: " + e.getMessage());
  45.                }
  46.            }
  47.        });
  48.    }
NOTE:
For more information, click SafetyDetect-AppsCheck-Android-Sample.zip to download the sample code.