Since 6.0.0(20), after a third-party Endpoint Detection and Response (EDR) app is registered with Device Security Kit, it can call the registration, update, and uninstallation (data deletion) APIs to submit its app information to the HarmonyOS VirusProtectionService for unified management. After a zero trust app is registered with Device Security Kit, it can query the list of all registered EDR apps (including the package name, current version number, last update time, antivirus switch status, and user ID). After a Mobile Device Management (MDM) app is registered with Device Security Kit, the enterprise administrator can enable or disable the HarmonyOS VirusProtectionService through the MDM app.
Currently, this capability is supported only on PCs/2-in-1 devices.
Concurrent calls are not supported. Only one third-party EDR app or MDM app can call the API of this module at a time.



Process description:
A third-party EDR app calls the API of this module to synchronize its information to the HarmonyOS VirusProtectionService during registration, update, or uninstallation.
A zero trust app calls the API of this module to query information about all registered third-party EDR apps.
An MDM app calls the API of this module to enable or disable the HarmonyOS VirusProtectionService.
The following table lists the APIs of the VirusProtectionServiceManager service. For details about the APIs, please refer to API Reference.
| API | Description |
|---|---|
| SecurityAntivirus_ErrCode HMS_SecurityAntivirus_RegisterAntivirus(const char* bundleName) | Called by a third-party EDR app to register with the HarmonyOS VirusProtectionService. |
| SecurityAntivirus_ErrCode HMS_SecurityAntivirus_UnregisterAntivirus(const char* bundleName) | Called by a third-party EDR app to unregister from the HarmonyOS VirusProtectionService. |
| SecurityAntivirus_ErrCode HMS_SecurityAntivirus_UpdateAntivirus(const SecurityAntivirus_Antivirus* antivirus) | Called by a third-party EDR app to update its information, including the package name, current version number, last update time, antivirus switch status, and user ID, to the HarmonyOS VirusProtectionService. |
| SecurityAntivirus_ErrCode HMS_SecurityAntivirus_QueryAntivirus(SecurityAntivirus_Antivirus** list, uint32_t* length) | Called by a zero trust app to query the HarmonyOS VirusProtectionService for the registration information of all third-party EDR apps. |
| SecurityAntivirus_ErrCode HMS_SecurityAntivirus_QueryPreinstalledAntivirus (SecurityAntivirus_Antivirus** list, uint32_t* length) | Called by an MDM app to query the HarmonyOS VirusProtectionService for the antivirus function status of all users. |
| SecurityAntivirus_ErrCode HMS_SecurityAntivirus_EnablePreinstalledAntivirus(void) | Called by an MDM app to enable the antivirus function of the HarmonyOS VirusProtectionService for all users. |
| SecurityAntivirus_ErrCode HMS_SecurityAntivirus_DisablePreinstalledAntivirus(void) | Called by an MDM app to disable the antivirus function of the HarmonyOS VirusProtectionService for all users. |
| SecurityAntivirus_ErrCode HMS_SecurityAntivirus_EnablePreinstalledAntivirusByAccount(int32_t accountId) | Called by an MDM app to enable the antivirus function of the HarmonyOS VirusProtectionService for a user with the specified accountId. |
| SecurityAntivirus_ErrCode HMS_SecurityAntivirus_DisablePreinstalledAntivirusByAccount(int32_t accountId) | Called by an MDM app to disable the antivirus function of the HarmonyOS VirusProtectionService for a user with the specified accountId. |
When preparing for the development, you need to apply for the ohos.permission.REGISTER_ANTIVIRUS, ohos.permission.MANAGE_ANTIVIRUS, and ohos.permission.MANAGE_PREINSTALLED_ANTIVIRUS permissions.
Only apps in the trustlist can apply for these permissions. For details, please refer to Permissions for Enterprise Applications and Permissions for MDM Applications.
Import and link the VirusProtectionServiceManager shared library in CMakeLists.txt.
find_library(dsm-lib libsecurityantivirus_ndk.z.so)
target_link_libraries(entry PUBLIC libace_napi.z.so ${dsm-lib}) Import the VirusProtectionServiceManager header file.
#include <cstdio> #include <cstdlib> #include "DeviceSecurityKit/security_antivirus.h"
The EDR app calls the API to register, update, and deregister app information with the HarmonyOS security protection service. The ohos.permission.REGISTER_ANTIVIRUS permission is required.
std::string regisBundleName = GetStringFromJS(env, args[0]);
int ret = HMS_SecurityAntivirus_RegisterAntivirus(regisBundleName .c_str());
printf("HMS_SecurityAntivirus_RegisterAntivirus ret = %d \n", ret); SecurityAntivirus_Antivirus *updateAntivirus = GetAntivirusFromJS(env, args[0]);
int ret = HMS_SecurityAntivirus_UpdateAntivirus(updateAntivirus);
printf("HMS_SecurityAntivirus_UpdateAntivirus ret = %d \n", ret); std::string unRegisBundleName = GetStringFromJS(env, args[0]);
int ret = HMS_SecurityAntivirus_UnregisterAntivirus(unRegisBundleName .c_str());
printf("HMS_SecurityAntivirus_UnregisterAntivirus ret = %d \n", ret); The zero trust app calls the API to query the HarmonyOS VirusProtectionService for the information about all the registered third-party EDR apps. The ohos.permission.MANAGE_ANTIVIRUS permission is required.
After processing services based on the app process information, the zero trust app needs to release the memory allocated for the input and output parameters of the query API.
SecurityAntivirus_Antivirus *list = nullptr; // Construct output parameter 1 of the query API.
uint32_t length = 0; // Construct output parameter 2 of the query API.
int ret = HMS_SecurityAntivirus_QueryAntivirus(&list, &length);
printf("HMS_SecurityAntivirus_QueryAntivirus ret = %d \n", ret); The MDM app calls the required API to enable or disable the HarmonyOS VirusProtectionService. The ohos.permission.MANAGE_PREINSTALLED_ANTIVIRUS permission is required.
After processing services based on the app process information, the MDM app needs to release the memory allocated for the input and output parameters of the query API.
SecurityAntivirus_Antivirus *list = nullptr;
uint32_t length = 0;
int ret = HMS_SecurityAntivirus_QueryPreinstalledAntivirus(&list, &length);
printf("HMS_SecurityAntivirus_QueryPreinstalledAntivirus ret = %d \n", ret); int ret = HMS_SecurityAntivirus_EnablePreinstalledAntivirus();
printf("HMS_SecurityAntivirus_EnablePreinstalledAntivirus ret = %d \n", ret); int ret = HMS_SecurityAntivirus_DisablePreinstalledAntivirus();
printf("HMS_SecurityAntivirus_DisablePreinstalledAntivirus ret = %d \n", ret); int32_t accountId = 0;
// ...
int ret = HMS_SecurityAntivirus_EnablePreinstalledAntivirusByAccount(accountId);
printf("HMS_SecurityAntivirus_EnablePreinstalledAntivirusByAccount ret = %d \n", ret); int32_t accountId = 0;
// ...
int ret = HMS_SecurityAntivirus_DisablePreinstalledAntivirusByAccount(accountId);
printf("HMS_SecurityAntivirus_DisablePreinstalledAntivirusByAccount ret = %d \n", ret);