目录

1 系统特性

1.  病毒应用检测率高,权威机构验证:病毒应用检测率99%。

2. 基于行为检测未知威胁的能力。


2 典型场景

开发者可获取恶意应用列表,基于风险(风险应用/病毒应用)评估是否限制APP行为。

3 开发流程

请参考:开发流程

4 应用开发

使用 Safety Detect AppsCheck API 之前,必须确保在用户设备上安装了正确版本的 HMS 服务。如果安装了不正确的版本,则您的应用可能会在调用 API 后停止响应。如果您的应用检测到安装了错误的版本,则应要求用户在其设备上更新 HMS。

要检查已安装的 HMS 版本是否与您使用的Android SDK版本兼容,请调用 isHuaweiMobileServicesAvailable() 方法,如以下代码片段所示:

  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 调用 AppsCheck API

您可直接调用SafetyDetectClient的getMaliciousAppsList()获取恶意应用列表:

  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.    }


说明:
更多信息获取示例代码,请下载SafetyDetect-AppsCheck-Android-Sample.zip。