From 3371ef6035f0ad4f8b5978ca4e92d4e8ce6bafc5 Mon Sep 17 00:00:00 2001 From: cheng Date: Tue, 2 Apr 2024 21:47:02 +0800 Subject: [PATCH 01/14] add avsession extendeddisplay syscap Signed-off-by: cheng --- include/codec_config/syscap_define.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 1e42cbd..9cd3e75 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -343,6 +343,7 @@ typedef enum SystemCapabilityNum { RESOURCESCHEDULE_SYSTEMLOAD, MSDP_MULTIMODAL_AWARENESS, ABILITY_APP_STARTUP, + MULTIMEDIA_AVSESSION_EXTENDEDDISPLAYCAST, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; @@ -596,6 +597,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Multimedia.AVSession.Core", MULTIMEDIA_AVSESSION_CORE}, {"SystemCapability.Multimedia.AVSession.Manager", MULTIMEDIA_AVSESSION_MANAGER}, {"SystemCapability.Multimedia.AVSession.AVCast", MULTIMEDIA_AVSESSION_AVCAST}, + {"SystemCapability.Multimedia.AVSession.ExtendedDisplayCast", MULTIMEDIA_AVSESSION_EXTENDEDDISPLAYCAST}, {"SystemCapability.Multimedia.Audio.Tone", MULTIMEDIA_AUDIO_TONE}, {"SystemCapability.Multimedia.Audio.Interrupt", MULTIMEDIA_AUDIO_INTERRUPT}, {"SystemCapability.Cloud.AAID", CLOUD_AAID}, From c35a908cb581d6dd297572bc894d937ff78dd535 Mon Sep 17 00:00:00 2001 From: flying Date: Wed, 10 Apr 2024 07:15:38 +0000 Subject: [PATCH 02/14] update tools/syscap_config_merge.py. Signed-off-by: flying --- tools/syscap_config_merge.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/syscap_config_merge.py b/tools/syscap_config_merge.py index c3d676e..9ab45de 100755 --- a/tools/syscap_config_merge.py +++ b/tools/syscap_config_merge.py @@ -18,6 +18,7 @@ 1. 扩展syscap头文件的枚举定义,须在开始位置标记最小值,且必须大于等于500。 ''' import argparse +import os LICENCE = '''/* * Copyright (c) 2023 Huawei Device Co., Ltd. @@ -151,6 +152,6 @@ if __name__ == '__main__': output_file = args.output full = assemble_header_file(base_file, extern_file) - with open(output_file, 'w') as out: + with os.fdopen(os.open(output_file, os.O_WRONLY | os.O_CREAT, mode=0o640), 'w') as out: out.writelines(full) From 89849ae99625d7a7d220a907216f26af3e3e5adc Mon Sep 17 00:00:00 2001 From: flying Date: Wed, 10 Apr 2024 07:27:11 +0000 Subject: [PATCH 03/14] update tools/syscap_collector.py. Signed-off-by: flying --- tools/syscap_collector.py | 59 +++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py index be014c1..ab835d5 100755 --- a/tools/syscap_collector.py +++ b/tools/syscap_collector.py @@ -304,15 +304,6 @@ class BundlePartObj(object): self._build_config_file = bundle_config_file self._loading_config() - def _loading_config(self): - if not os.path.exists(self._build_config_file): - raise Exception("file '{}' doesn't exist.".format( - self._build_config_file), "2011") - self.bundle_info = _read_json_file(self._build_config_file) - if not self.bundle_info: - raise Exception("read file '{}' failed.".format( - self._build_config_file), "2011") - def to_ohos_build(self): _component_info = self.bundle_info.get('component') _subsystem_name = _component_info.get('subsystem') @@ -349,6 +340,15 @@ class BundlePartObj(object): _ohos_build_info['parts'] = {_part_name: _part_info} return _ohos_build_info + def _loading_config(self): + if not os.path.exists(self._build_config_file): + raise Exception("file '{}' doesn't exist.".format( + self._build_config_file), "2011") + self.bundle_info = _read_json_file(self._build_config_file) + if not self.bundle_info: + raise Exception("read file '{}' failed.".format( + self._build_config_file), "2011") + class LoadBuildConfig(object): """load build config file and parse configuration info.""" @@ -368,6 +368,26 @@ class LoadBuildConfig(object): self._parts_module_list = {} self._parts_deps = {} + def parse(self): + """parse part info from build config file.""" + if self._is_load: + return + subsystem_config, parts_path_dict = self._merge_build_config() + parts_config = subsystem_config.get('parts') + self._parts_module_list.update(parts_config) + self._parts_path_dict = parts_path_dict + self._is_load = True + + def parts_path_info(self): + """parts to path info.""" + self.parse() + return self._parts_path_dict + + def parts_info_filter(self, save_part): + if save_part is None: + raise Exception + self._parts_info_dict = { + key: value for key, value in self._parts_info_dict.items() if key in save_part} def _merge_build_config(self): _build_files = self._build_info.get('build_files') is_thirdparty_subsystem = False @@ -398,27 +418,6 @@ class LoadBuildConfig(object): subsystem_config['parts'] = parts_info return subsystem_config, parts_path_dict - def parse(self): - """parse part info from build config file.""" - if self._is_load: - return - subsystem_config, parts_path_dict = self._merge_build_config() - parts_config = subsystem_config.get('parts') - self._parts_module_list.update(parts_config) - self._parts_path_dict = parts_path_dict - self._is_load = True - - def parts_path_info(self): - """parts to path info.""" - self.parse() - return self._parts_path_dict - - def parts_info_filter(self, save_part): - if save_part is None: - raise Exception - self._parts_info_dict = { - key: value for key, value in self._parts_info_dict.items() if key in save_part} - def get_parts_info(source_root_dir, subsystem_info, build_xts=False): """ From 464648829c014c2d12909cf36ff6c678e47a4020 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Fri, 12 Apr 2024 01:45:54 +0000 Subject: [PATCH 04/14] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=9A=E6=A8=A1?= =?UTF-8?q?=E7=BA=A2=E5=A4=96=E7=9A=84syscap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mayunteng_1 Change-Id: I60cb8d853cb3c85d2d20eaa7fd4e2000467acbf0 --- include/codec_config/syscap_define.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 9cd3e75..0aab83b 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -344,6 +344,8 @@ typedef enum SystemCapabilityNum { MSDP_MULTIMODAL_AWARENESS, ABILITY_APP_STARTUP, MULTIMEDIA_AVSESSION_EXTENDEDDISPLAYCAST, + MULTIMODALINPUT_INPUT_POINTER, + MULTIMODALINPUT_INPUT_INFRAREDEMITTER // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; @@ -671,6 +673,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.AI.MindSporeLite", AI_MINDSPORELITE}, {"SystemCapability.Ability.AppStartup", ABILITY_APP_STARTUP}, {"SystemCapability.Base", BASE}, + {"SystemCapability.MultimodalInput.Input.InfraredEmitter", MULTIMODALINPUT_INPUT_INFRAREDEMITTER}, }; #ifdef __cplusplus From a13ee15930fa55057d6c5e013f22eff9f9f728e3 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Fri, 12 Apr 2024 03:18:08 +0000 Subject: [PATCH 05/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99sysca?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mayunteng_1 Change-Id: I37db4431b2d4282d4cd28fc3104ab0214787882f --- include/codec_config/syscap_define.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 0aab83b..a98b179 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -344,8 +344,7 @@ typedef enum SystemCapabilityNum { MSDP_MULTIMODAL_AWARENESS, ABILITY_APP_STARTUP, MULTIMEDIA_AVSESSION_EXTENDEDDISPLAYCAST, - MULTIMODALINPUT_INPUT_POINTER, - MULTIMODALINPUT_INPUT_INFRAREDEMITTER + MULTIMODALINPUT_INPUT_INFRAREDEMITTER, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; From 56f5d2f8a9363f72543c3ab40f0f7858ceabe759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=B1=B6=E9=92=8A?= Date: Fri, 12 Apr 2024 06:12:52 +0000 Subject: [PATCH 06/14] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BD=AC=E7=A0=81?= =?UTF-8?q?=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韩汶钊 --- include/codec_config/syscap_define.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 9cd3e75..2e32c8a 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -344,6 +344,7 @@ typedef enum SystemCapabilityNum { MSDP_MULTIMODAL_AWARENESS, ABILITY_APP_STARTUP, MULTIMEDIA_AVSESSION_EXTENDEDDISPLAYCAST, + MULTIMEDIA_MEDIA_AVTRANSCODER, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; @@ -670,6 +671,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Resourceschedule.Ffrt.Core", RESOURCESCHEDULE_FFRT_CORE}, {"SystemCapability.AI.MindSporeLite", AI_MINDSPORELITE}, {"SystemCapability.Ability.AppStartup", ABILITY_APP_STARTUP}, + {"SystemCapability.Multimedia.Media.AVTransCoder", MULTIMEDIA_MEDIA_AVTRANSCODER}, {"SystemCapability.Base", BASE}, }; From e73f3fc77b5ddb1dcf52719bc484feb4b8268ece Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Tue, 16 Apr 2024 16:34:40 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lichao --- interfaces/inner_api/syscap_interface.c | 4 ++++ src/create_pcid.c | 13 +++++++++++-- src/main.c | 10 ++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 4eb457c..d28800a 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -119,6 +119,10 @@ bool EncodePrivateSyscap(char **output, int *outputLen) return false; } + if (bufferLen < (PCID_MAIN_BYTES + 1) || bufferLen > INT32_MAX) { + PRINT_ERR("Parameter bufferLen out of range."); + return false; + } uint32_t priLen = bufferLen - PCID_MAIN_BYTES - 1; if ((int)priLen <= 0) { *outputLen = 0; diff --git a/src/create_pcid.c b/src/create_pcid.c index cea4e57..30cd37e 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -254,6 +254,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) cJSON *jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "syscap"); if (jsonSyscapObj == NULL || !cJSON_IsObject(jsonSyscapObj)) { PRINT_ERR("get \"syscap\" object failed\n"); + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, -1); } @@ -267,6 +268,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) uint16_t allPriSyscapStrLen = 0; ret = GetPriSyscapLen(privateCapSize, jsonPriSyscapObj, &allPriSyscapStrLen); if (ret != 0) { + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, ret); } @@ -274,6 +276,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) PCIDMain *pcidBuffer = (PCIDMain *)malloc(pcidLength); if (pcidBuffer == NULL) { PRINT_ERR("malloc for pcid buffer failed\n"); + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, -1); } (void)memset_s(pcidBuffer, pcidLength, 0, pcidLength); @@ -305,6 +308,7 @@ int32_t GetOsSyscap(PCIDMain *pcidMain, cJSON *sysCapObject) errno_t nRet = memcpy_s(osSyscap, OS_SYSCAP_BYTES, (uint8_t *)pcidMain + 8, OS_SYSCAP_BYTES); if (nRet != EOK) { PRINT_ERR("memcpy_s failed."); + cJSON_Delete(capVectorPtr); return -1; } @@ -361,10 +365,12 @@ int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufL int32_t ret = sprintf_s(fullCapStr, SINGLE_SYSCAP_LEN, "SystemCapability.%s", priSyscapStr); if (ret == -1) { printf("sprintf_s failed\n"); + cJSON_Delete(capVectorPtr); return -1; } if (!cJSON_AddItemToArray(capVectorPtr, cJSON_CreateString(fullCapStr))) { printf("cJSON_AddItemToArray or cJSON_CreateString failed\n"); + cJSON_Delete(capVectorPtr); return -1; } tempPriSyscapStr = priSyscapStr; @@ -643,6 +649,7 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt if (priSyscapStringLen == 0) { if (!cJSON_AddItemToObject(sysCapObj, "private", sysCapArray)) { PRINT_ERR("Add private syscap array to json failed.\n"); + cJSON_Delete(sysCapArray); free(sysCapArray); return -1; } @@ -653,6 +660,7 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt while (token != NULL) { if (!cJSON_AddItemToArray(sysCapArray, cJSON_CreateString(token))) { PRINT_ERR("Add private syscap string to json failed.\n"); + cJSON_Delete(sysCapArray); free(sysCapArray); return -1; } @@ -714,10 +722,11 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) } ret = 0; - SAVE_FAILED: +SAVE_FAILED: free(jsonBuffer); - ADD_JSON_FAILED: +ADD_JSON_FAILED: cJSON_Delete(rootObj); + cJSON_Delete(sysCapObj); PARSE_FAILED: free(ctx); return ret; diff --git a/src/main.c b/src/main.c index 4cc9e42..47a7769 100644 --- a/src/main.c +++ b/src/main.c @@ -37,6 +37,7 @@ #define INPUT_FILE 8 #define OUTPUT_FILE 9 #define HELP 10 +#define INPUT_FILE_NUM 4 static void PrintHelp(void); static void PrintVersion(void); @@ -85,7 +86,7 @@ int main(int argc, char **argv) break; } if (flag == 'C') { - if (argc != 4 || optind < 0 || optind >= argc) { // 4, argc of ./syscap_tool -C f1 f2 + if (argc != INPUT_FILE_NUM || optind < 0 || optind >= argc) { // 4, argc of ./syscap_tool -C f1 f2 PRINT_ERR("Input file too few or too many.\n"); return -1; } @@ -126,7 +127,12 @@ int32_t OperateByBitMap(char *const *argv, uint16_t bitMap, char *outputpath) case 0x10E: // 0x10E, -Rdsi inputfile printf("-Rdsi is not support currently.\n"); break; case 0x80: // 0x80, -v - (void)OutputVersion(argv[optind], optind); break; + if (optind < 0 || optind >= INPUT_FILE_NUM) { + PRINT_ERR("Input file too few or too many.\n"); + return -1; + } else { + (void)OutputVersion(argv[optind], optind); break; + } default: (void)OutputHelp(); } From 8d1e1bc7294c96c034a17e72620960d96e91dd98 Mon Sep 17 00:00:00 2001 From: z00428214 Date: Fri, 19 Apr 2024 12:58:33 +0800 Subject: [PATCH 08/14] add image_effect Signed-off-by: z00428214 --- include/codec_config/syscap_define.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 1761131..ea79d15 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -346,6 +346,7 @@ typedef enum SystemCapabilityNum { MULTIMEDIA_AVSESSION_EXTENDEDDISPLAYCAST, MULTIMODALINPUT_INPUT_INFRAREDEMITTER, MULTIMEDIA_MEDIA_AVTRANSCODER, + MULTIMEDIA_IMAGEEFFECT_CORE, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; @@ -675,6 +676,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Multimedia.Media.AVTransCoder", MULTIMEDIA_MEDIA_AVTRANSCODER}, {"SystemCapability.Base", BASE}, {"SystemCapability.MultimodalInput.Input.InfraredEmitter", MULTIMODALINPUT_INPUT_INFRAREDEMITTER}, + {"SystemCapability.Multimedia.ImageEffect.Core", MULTIMEDIA_IMAGEEFFECT_CORE}, }; #ifdef __cplusplus From 0d085c290cefff49de73469146013ed72184abbb Mon Sep 17 00:00:00 2001 From: lichao Date: Sun, 21 Apr 2024 18:21:55 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lichao --- interfaces/inner_api/syscap_interface.c | 2 -- src/create_pcid.c | 12 +++++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index d28800a..a4a342e 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -320,8 +320,6 @@ static int32_t ParseRpcidToJson(char *input, uint32_t inputLen, cJSON *rpcidJson ret = -1; goto FREE_SYSCAP_OUT; } - - return 0; FREE_SYSCAP_OUT: cJSON_Delete(sysCapJson); return ret; diff --git a/src/create_pcid.c b/src/create_pcid.c index 30cd37e..e8aac78 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -262,6 +262,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) cJSON *jsonPriSyscapObj = cJSON_GetObjectItem(jsonSyscapObj, "private"); ret = GetOsAndPriSyscapSize(jsonOsSyscapObj, jsonPriSyscapObj, &osCapSize, &privateCapSize); if (ret != 0) { + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, ret); } @@ -347,6 +348,11 @@ int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufL return -1; } + if (contextBufLen < 0 || contextBufLen > UINT32_MAX) { + PRINT_ERR("the data privateSyscapLen is out of scope."); + return -1; + } + int32_t privateSyscapLen = (int32_t)(contextBufLen - sizeof(PCIDMain) - 1); if (privateSyscapLen < 0) { PRINT_ERR("parse private syscap failed."); @@ -381,9 +387,9 @@ int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufL } if (!cJSON_AddItemToObject(sysCapObject, "private", capVectorPtr)) { PRINT_ERR("cJSON_AddItemToObject failed\n"); + cJSON_Delete(capVectorPtr); return -1; } - return 0; } @@ -653,6 +659,7 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt free(sysCapArray); return -1; } + cJSON_Delete(sysCapArray); return 0; } @@ -726,8 +733,7 @@ SAVE_FAILED: free(jsonBuffer); ADD_JSON_FAILED: cJSON_Delete(rootObj); - cJSON_Delete(sysCapObj); - PARSE_FAILED: +PARSE_FAILED: free(ctx); return ret; } From 122aa467c209f76471810e006eb3164cb5910ed0 Mon Sep 17 00:00:00 2001 From: lichao Date: Sun, 21 Apr 2024 19:06:45 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lichao --- src/create_pcid.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/create_pcid.c b/src/create_pcid.c index e8aac78..1a606df 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -358,6 +358,7 @@ int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufL PRINT_ERR("parse private syscap failed."); return -1; } else if (privateSyscapLen == 0) { + cJSON_Delete(capVectorPtr); return 0; } @@ -656,7 +657,6 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt if (!cJSON_AddItemToObject(sysCapObj, "private", sysCapArray)) { PRINT_ERR("Add private syscap array to json failed.\n"); cJSON_Delete(sysCapArray); - free(sysCapArray); return -1; } cJSON_Delete(sysCapArray); @@ -668,16 +668,16 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt if (!cJSON_AddItemToArray(sysCapArray, cJSON_CreateString(token))) { PRINT_ERR("Add private syscap string to json failed.\n"); cJSON_Delete(sysCapArray); - free(sysCapArray); return -1; } token = strtok(NULL, ","); } if (!cJSON_AddItemToObject(sysCapObj, "private", sysCapArray)) { PRINT_ERR("Add private syscap array to json failed.\n"); - free(sysCapArray); + cJSON_Delete(sysCapArray); return -1; } + cJSON_Delete(sysCapArray); return 0; } @@ -705,18 +705,22 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) cJSON *rootObj = cJSON_CreateObject(); if (!cJSON_AddItemToObject(rootObj, "syscap", sysCapObj)) { PRINT_ERR("Add syscap to json failed.\n"); + cJSON_Delete(sysCapObj); goto ADD_JSON_FAILED; } if (AddHeaderToJsonObj(pcidHeader, PCID_HEADER, rootObj) != 0) { PRINT_ERR("Add header to json object failed.\n"); + cJSON_Delete(sysCapObj); goto ADD_JSON_FAILED; } if (AddOsSyscapToJsonObj(osSyscap, OS_SYSCAP_NUM, sysCapObj) != 0) { PRINT_ERR("Add os syscap json object failed.\n"); + cJSON_Delete(sysCapObj); goto ADD_JSON_FAILED; } if (AddPriSyscapToJsonObj(priSyscapStr, (uint32_t)strlen(priSyscapStr), sysCapObj) != 0) { PRINT_ERR("Add private syscap json object failed.\n"); + cJSON_Delete(sysCapObj); goto ADD_JSON_FAILED; } // save as json file @@ -767,18 +771,21 @@ static int32_t GetEncodePCIDOut(uint16_t priSyscapCount, uint32_t privateSyscapL output = (char *)malloc(outputLen); if (output == NULL) { PRINT_ERR("malloc failed\n"); + free(output); return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_PRISYSCAP_FULL_OUT, ret); } (void)memset_s(output, outputLen, 0, outputLen); ret = sprintf_s(output, outputLen, "%u", mainSyscap[0]); if (ret == -1) { PRINT_ERR("sprintf_s failed\n"); + free(output); return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); } for (i = 1; i < PCID_OUT_BUFFER; i++) { ret = sprintf_s(output, outputLen, "%s,%u", output, mainSyscap[i]); if (ret == -1) { PRINT_ERR("sprintf_s failed\n"); + free(output); return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); } } @@ -786,6 +793,7 @@ static int32_t GetEncodePCIDOut(uint16_t priSyscapCount, uint32_t privateSyscapL ret = sprintf_s(output, outputLen, "%s,%s", output, freePcidInfo.priSyscapFull + i * SINGLE_SYSCAP_LEN); if (ret == -1) { PRINT_ERR("sprintf_s failed\n"); + free(output); return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); } } @@ -796,6 +804,7 @@ static int32_t GetEncodePCIDOut(uint16_t priSyscapCount, uint32_t privateSyscapL PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", freePcidInfo.outDirPathFinal, outputFileName); } + free(output); return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); } From 321b1208ee4696a8921e2d1b3626866cbd50dfe0 Mon Sep 17 00:00:00 2001 From: lichao Date: Sun, 21 Apr 2024 20:04:40 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lichao --- interfaces/inner_api/syscap_interface.c | 8 +++++--- src/create_pcid.c | 3 +++ src/syscap_tool.c | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index a4a342e..887d498 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -245,6 +245,7 @@ bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *o *bufferPos = '\0'; if (sprintf_s(*outputArray, SINGLE_SYSCAP_LEN, "SystemCapability.%s", buffer) == -1) { free(outputArray); + free(output); return false; } bufferPos = buffer; @@ -328,24 +329,25 @@ FREE_SYSCAP_OUT: static int32_t TransStringFormatAndSaveSyscap(struct FreeAfterDecodeRpcidInfo freeAfterDecodeRpcidInfo, cJSON *sysCapArray, const char *inputFile) { + int32_t ret = -1; // trans to string format sysCapArray = cJSON_GetObjectItem(freeAfterDecodeRpcidInfo.rpcidRoot, "syscap"); if (sysCapArray == NULL || !cJSON_IsArray(sysCapArray)) { PRINT_ERR("Get syscap failed. Input file: %s\n", inputFile); - return -1; + return ret; } freeAfterDecodeRpcidInfo.sysCapArraySize = cJSON_GetArraySize(sysCapArray); if (freeAfterDecodeRpcidInfo.sysCapArraySize < 0) { PRINT_ERR("Get syscap size failed. Input file: %s\n", inputFile); - return -1; + return ret; } // malloc for save os syscap index freeAfterDecodeRpcidInfo.osSysCapIndex = (uint16_t *)malloc(sizeof(uint16_t) * freeAfterDecodeRpcidInfo.sysCapArraySize); if (freeAfterDecodeRpcidInfo.osSysCapIndex == NULL) { PRINT_ERR("malloc failed.\n"); - return -1; } + free(freeAfterDecodeRpcidInfo.osSysCapIndex); return 0; } diff --git a/src/create_pcid.c b/src/create_pcid.c index 1a606df..da181d8 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -286,10 +286,12 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) ret += SetPriSyscap(pcidBuffer, jsonPriSyscapObj, privateCapSize, allPriSyscapStrLen); ret += SetPCIDHeader(pcidBuffer, jsonRootObj); if (ret != 0) { + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(pcidBuffer, allOsSyscapObj, contextBuffer, FREE_CREATE_PCID_BUFFER_OUT, ret); } ret = CheckConvertedContextSaveAsFile(outDirPath, pcidBuffer, pcidLength, ret); + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(pcidBuffer, allOsSyscapObj, contextBuffer, FREE_CREATE_PCID_BUFFER_OUT, ret); } @@ -520,6 +522,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", outDirPath, outputFileName); } + free(strJson); return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_CONVERT_OUT, ret); } diff --git a/src/syscap_tool.c b/src/syscap_tool.c index ff4e084..b79c6b7 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -266,6 +266,7 @@ int32_t RPCIDDecode(char *inputFile, char *outputPath) FREE_RPCID_ROOT: cJSON_Delete(rpcidRoot); + free(convertedBuffer); FREE_CONTEXT_OUT: FreeContextBuffer(contextBuffer); return ret; From fdd83911b2d9912267ef6a2b69a4b9739a7e3564 Mon Sep 17 00:00:00 2001 From: lichao Date: Sun, 21 Apr 2024 20:54:04 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E7=BC=96=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lichao --- interfaces/inner_api/syscap_interface.c | 29 +++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 887d498..8b9749e 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -57,7 +57,7 @@ typedef struct ProductCompatibilityID { uint8_t osSyscap[OS_SYSCAP_BYTES]; } PCIDMain; -static const char *g_pcidPath = "/system/etc/PCID.sc"; +static const char *g_PCID_PATH = "/system/etc/PCID.sc"; struct FreeAfterDecodeRpcidInfo { char *priSyscap; @@ -89,7 +89,7 @@ bool EncodeOsSyscap(char *output, int len) return false; } - ret = GetFileContext(g_pcidPath, &contextBuffer, &bufferLen); + ret = GetFileContext(g_PCID_PATH, &contextBuffer, &bufferLen); if (ret != 0) { PRINT_ERR("GetFileContext failed, input file : /system/etc/PCID.sc\n"); return false; @@ -113,7 +113,7 @@ bool EncodePrivateSyscap(char **output, int *outputLen) char *outputStr = NULL; uint32_t bufferLen; - ret = GetFileContext(g_pcidPath, &contextBuffer, &bufferLen); + ret = GetFileContext(g_PCID_PATH, &contextBuffer, &bufferLen); if (ret != 0) { PRINT_ERR("GetFileContext failed, input file : /system/etc/PCID.sc\n"); return false; @@ -181,18 +181,19 @@ bool DecodeOsSyscap(const char input[PCID_MAIN_BYTES], char (**output)[SINGLE_SY for (i = 0; i < countOfSyscap; i++) { for (j = 0; j < sizeof(g_arraySyscap) / sizeof(SyscapWithNum); j++) { - if (g_arraySyscap[j].num == indexOfSyscap[i]) { - nRet = strcpy_s(*strSyscap, SINGLE_SYSCAP_LEN, g_arraySyscap[j].str); - if (nRet != EOK) { - printf("strcpy_s failed. error = %d\n", nRet); - *outputCnt = 0; - free(strSyscap); - strSyscap = NULL; - return false; - } - strSyscap++; - break; + if (g_arraySyscap[j].num != indexOfSyscap[i]) { + continue; } + nRet = strcpy_s(*strSyscap, SINGLE_SYSCAP_LEN, g_arraySyscap[j].str); + if (nRet != EOK) { + printf("strcpy_s failed. error = %d\n", nRet); + *outputCnt = 0; + free(strSyscap); + strSyscap = NULL; + return false; + } + strSyscap++; + break; } } From c2a0bd217b109a9a0f8093265f3c19316b35d651 Mon Sep 17 00:00:00 2001 From: lichao Date: Mon, 22 Apr 2024 08:40:58 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E7=BC=96=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lichao --- interfaces/inner_api/syscap_interface.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 8b9749e..9e1dff5 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -57,7 +57,7 @@ typedef struct ProductCompatibilityID { uint8_t osSyscap[OS_SYSCAP_BYTES]; } PCIDMain; -static const char *g_PCID_PATH = "/system/etc/PCID.sc"; +static const char *PCID_PATH = "/system/etc/PCID.sc"; struct FreeAfterDecodeRpcidInfo { char *priSyscap; @@ -89,7 +89,7 @@ bool EncodeOsSyscap(char *output, int len) return false; } - ret = GetFileContext(g_PCID_PATH, &contextBuffer, &bufferLen); + ret = GetFileContext(PCID_PATH, &contextBuffer, &bufferLen); if (ret != 0) { PRINT_ERR("GetFileContext failed, input file : /system/etc/PCID.sc\n"); return false; @@ -113,7 +113,7 @@ bool EncodePrivateSyscap(char **output, int *outputLen) char *outputStr = NULL; uint32_t bufferLen; - ret = GetFileContext(g_PCID_PATH, &contextBuffer, &bufferLen); + ret = GetFileContext(PCID_PATH, &contextBuffer, &bufferLen); if (ret != 0) { PRINT_ERR("GetFileContext failed, input file : /system/etc/PCID.sc\n"); return false; From ef0e1de8073da1d08c81bc8775aecb9d5b434043 Mon Sep 17 00:00:00 2001 From: flying Date: Tue, 23 Apr 2024 02:58:17 +0000 Subject: [PATCH 14/14] update tools/syscap_collector.py. Signed-off-by: flying --- tools/syscap_collector.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py index ab835d5..47be694 100755 --- a/tools/syscap_collector.py +++ b/tools/syscap_collector.py @@ -33,14 +33,6 @@ def get_args(): return args -def adjust_syscaps_list(sys_list: list, product: str): - # 调整syscaps_list:如果产品属于standard类,则去掉其中以.Lite结尾的syscap - standard_product = ["default", "ipcamera", "pc", "tablet"] - if product in standard_product: - sys_list = [syscap for syscap in sys_list if not syscap.endswith(".Lite")] - return sys_list - - def dict_to_json(output_path: str, syscaps_dict: dict): """ output diff product syscaps json to output path @@ -59,7 +51,6 @@ def dict_to_json(output_path: str, syscaps_dict: dict): syscaps_list = list(set(syscaps_list)) filename = os.path.join(output_path, f'{product_name}.json') with os.fdopen(os.open(filename, flags, modes), 'w') as f: - syscaps_list = adjust_syscaps_list(syscaps_list, product_name) json.dump({'SysCaps': syscaps_list}, f, indent=4) print("end...")