diff --git a/README_ZH.md b/README_ZH.md index 9e8e72e..b39cfbc 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -170,6 +170,11 @@ python3 syscap_check.py -p path_of_openarmony -t component_sdk python3 syscap_check.py -p path_of_openarmony -t sdk_codec ``` +## syscap_define.h 文件规则 +- 每一个 SyscapNum 枚举值都唯一对应于一个 syscap 字符串。 +- 如果弃用某个 syscap,在对应的枚举值后面注释 "// abandoned" 即可,请勿删除和修改。对应的 syscap 字符串也不需要修改。 +- 添加 syscap,请在 SyscapNum 和 g_arraySyscap 末尾添加相应数据。 +- 数组 g_arraySyscap 按照 SyscapNum 枚举值从小到大排序。 ## Release Note diff --git a/include/syscap_define.h b/include/syscap_define.h index 37a6e95..5f84c54 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -46,7 +46,7 @@ typedef enum SystemCapabilityNum { COMMUNICATION_BLUETOOTH_CORE, COMMUNICATION_CONNECTEDTAG, COMMUNICATION_NETMANAGER_CORE, - COMMUNICATION_NETMANAGER_EXTENSION, + COMMUNICATION_NETMANAGER_EXTENSION, // abandoned COMMUNICATION_NETSTACK, COMMUNICATION_NFC_CORE, COMMUNICATION_SOFTBUS_CORE, @@ -243,7 +243,6 @@ typedef enum SystemCapabilityNum { RESOURCESCHEDULE_BACKGROUNDTASKMANAGER_EFFICIENCYRESOURCESAPPLY, SECURITY_SECURITYGUARD, SECURITY_CRYPTOFRAMEWORK, - // Add here MULTIMODALINPUT_INPUT_COOPERATOR, ABILITY_ABILITYRUNTIME_QUICKFIX, SECURITY_DLPCREDENTIALSERVICE, @@ -259,7 +258,15 @@ typedef enum SystemCapabilityNum { MULTIMEDIA_AUDIO_INTERRUPT, CLOUD_AAID, MSDP_DEVICESTATUS_STATIONARY, - PRINT_PRINT, + COMMUNICATION_NETMANAGER_ETHERNET, + COMMUNICATION_NETMANAGER_NETSHARING, + COMMUNICATION_NETMANAGER_MDNS, + COMMUNICATION_NETMANAGER_VPN, + COMMUNICATION_NFC_TAG, + COMMUNICATION_NFC_CARDEMULATION, + SECURITY_CERT, + PRINT_PRINT_FRAMEWORK, + // Add before here SYSCAP_NUM_MAX = 960 } SyscapNum; @@ -497,7 +504,14 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Multimedia.Audio.Interrupt", MULTIMEDIA_AUDIO_INTERRUPT}, {"SystemCapability.Cloud.AAID", CLOUD_AAID}, {"SystemCapability.Msdp.DeviceStatus.Stationary", MSDP_DEVICESTATUS_STATIONARY}, - {"SystemCapability.Print.Print", PRINT_PRINT} + {"SystemCapability.Communication.NetManager.Ethernet", COMMUNICATION_NETMANAGER_ETHERNET}, + {"SystemCapability.Communication.NetManager.NetSharing", COMMUNICATION_NETMANAGER_NETSHARING}, + {"SystemCapability.Communication.NetManager.MDNS", COMMUNICATION_NETMANAGER_MDNS}, + {"SystemCapability.Communication.NetManager.Vpn", COMMUNICATION_NETMANAGER_VPN}, + {"SystemCapability.Communication.NFC.Tag", COMMUNICATION_NFC_TAG}, + {"SystemCapability.Communication.NFC.CardEmulation", COMMUNICATION_NFC_CARDEMULATION}, + {"SystemCapability.Security.Cert", SECURITY_CERT}, + {"SystemCapability.Print.PrintFramework", PRINT_PRINT_FRAMEWORK} }; #ifdef __cplusplus diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 06c95ab..bf8372d 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -583,7 +583,7 @@ int32_t ComparePcidString(const char *pcidString, const char *rpcidString, Compa continue; } for (uint8_t k = 0; k < INT_BIT; k++) { - if (temp2 & (0x1 << k)) { + if (temp2 & (1U << k)) { char *temp = (char *)malloc(sizeof(char) * SINGLE_SYSCAP_LEN); if (temp == NULL) { PRINT_ERR("malloc failed.\n"); @@ -632,10 +632,10 @@ int32_t ComparePcidString(const char *pcidString, const char *rpcidString, Compa } if (versionFlag > 0) { - retFlag |= 0x1 << 0; + retFlag |= 1U << 0; } if (ossyscapFlag > 0 || prisyscapFlag > 0) { - retFlag |= 0x1 << 1; + retFlag |= 1U << 1; result->missSyscapNum = ossyscapFlag + prisyscapFlag; } return (int32_t)retFlag; diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 54193ff..01f1802 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include #include @@ -425,7 +426,7 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath) { int32_t ret = 0; int32_t sysCapArraySize; - uint32_t bufferLen, i; + uint32_t bufferLen; uint16_t indexPri = 0; uint16_t *osSysCapIndex; char *contextBuffer = NULL; @@ -518,7 +519,7 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath) PRINT_ERR("sprintf_s failed.\n"); goto FREE_OUTBUFFER; } - for (i = 1; i < RPCID_OUT_BUFFER; i++) { + for (int i = 1; i < RPCID_OUT_BUFFER; i++) { ret = sprintf_s(outBuffer, outBufferLen, "%s,%u", outBuffer, outUint[i]); if (ret == -1) { PRINT_ERR("sprintf_s failed.\n"); @@ -526,7 +527,7 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath) } } - for (i = 0; i < indexPri; i++) { + for (uint16_t i = 0; i < indexPri; i++) { ret = sprintf_s(outBuffer, outBufferLen, "%s,%s", outBuffer, priSyscapArray + i * SINGLE_SYSCAP_LEN); if (ret == -1) { @@ -707,7 +708,7 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t typ continue; } for (uint8_t k = 0; k < INT_BIT; k++) { - if (!(temp2 & (0x1 << k))) { + if (!(temp2 & (1U << k))) { continue; } // 2, header of pcid & rpcid diff --git a/test/syscap_define_check.c b/test/syscap_define_check.c index c063bd0..dc05e11 100644 --- a/test/syscap_define_check.c +++ b/test/syscap_define_check.c @@ -18,21 +18,40 @@ #include #include "syscap_define.h" -int main(void) +int CheckSortBySyscapNum(void) { - size_t size = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); - size_t flag = 0; + int size = (int)sizeof(g_arraySyscap) / sizeof(SyscapWithNum); + int flag = 0; - for (size_t i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { if (g_arraySyscap[i].num != i) { - printf("[Error][syscap_define.h]: %s -> num(%u) should be %zu.\n", + printf("[ERROR][syscap_define.h]: %s -> num(%u) should be %d.\n", g_arraySyscap[i].str, g_arraySyscap[i].num, i); flag++; } } - if (flag == 0) { - return 0; - } else { + return flag; +} + +int CheckSyscapNumOrder(void) +{ + if (COMMUNICATION_NETMANAGER_VPN != 227) { // 227, special number + printf("[ERROR][syscap_define.h]: " + "enum value 'COMMUNICATION_NETMANAGER_VPN' should be 227. " + "Please don't change original SyscapNum's enum value order, " + "and add the new enum value at the end.\n"); + return 1; + } + return 0; +} + +int main(void) +{ + if (CheckSyscapNumOrder() != 0) { return -1; } + if (CheckSortBySyscapNum() != 0) { + return -1; + } + return 0; } \ No newline at end of file