From 7b05e241ccceec187dea9343862f915cb19c10b5 Mon Sep 17 00:00:00 2001 From: ry Date: Wed, 14 Sep 2022 18:21:16 +0800 Subject: [PATCH 01/23] modify code path Signed-off-by: ry --- test/unittest/common/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/common/BUILD.gn b/test/unittest/common/BUILD.gn index 15937b3..aa33c11 100644 --- a/test/unittest/common/BUILD.gn +++ b/test/unittest/common/BUILD.gn @@ -44,7 +44,7 @@ if (defined(ohos_lite)) { deps = [ "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//test/developertest/third_party/lib/cpp:gtest_main", + "//test/testfwk/developer_test/third_party/lib/cpp:gtest_main", "//third_party/bounds_checking_function:libsec_static", ] From e6623d05fdbef1dc4bea5eef532e2cdd84ca6bef Mon Sep 17 00:00:00 2001 From: aodongbiao Date: Fri, 16 Sep 2022 12:31:32 +0800 Subject: [PATCH 02/23] =?UTF-8?q?=E9=87=8D=E6=9E=84syscap=5Fcheck.py?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aodongbiao Change-Id: I254c95372d2eaf0e182358450ebefe7a340c41b1 --- tools/syscap_check.py | 201 +++++++++++++----------------------------- 1 file changed, 59 insertions(+), 142 deletions(-) diff --git a/tools/syscap_check.py b/tools/syscap_check.py index bd6d34f..99c550d 100644 --- a/tools/syscap_check.py +++ b/tools/syscap_check.py @@ -46,7 +46,7 @@ def get_args(): nargs="*", type=str, help="option take effect only when the check_target is component_codec. allow multiple json file. " - "default: all bundle.json file", + "default: all bundle.json file", ) args = parser.parse_args() return args @@ -60,46 +60,37 @@ def convert_set_to_sorted_list(target_set) -> list: return sorted(list(target_set)) -def add_dict_as_table_row( - f_table: PrettyTable, d_dict: dict, out_converter=list_to_multiline -) -> None: +def add_dict_as_table_row(f_table: PrettyTable, d_dict: dict, out_converter=list_to_multiline) -> None: s_keys = convert_set_to_sorted_list(d_dict.keys()) for i, k in enumerate(s_keys): - f_table.add_row( - [i + 1, k, out_converter(convert_set_to_sorted_list(d_dict.get(k)))] - ) + f_table.add_row([i + 1, k, out_converter(convert_set_to_sorted_list(d_dict.get(k)))]) def bundle_syscap_post_handler(syscap: str) -> str: - return syscap.split("=")[0].strip() + return syscap.split('=')[0].strip() -def read_value_from_json( - filepath: str, key_hierarchy: tuple, result_dict: dict, post_handler=None -) -> None: +def read_value_from_json(filepath: str, + key_hierarchy: tuple, + result_dict: dict, + post_handler=None + ) -> None: if os.path.exists(filepath) is False: print('error: file "{}" not exist.'.format(filepath)) return if not os.path.isfile(filepath): print('error: "{}" is not a file.') return - f = open(filepath, "r") + f = open(filepath, 'r') data = json.load(f) if debug: print(filepath) for key in key_hierarchy: try: - if debug: - print("key={}".format(key)) - print("data={}".format(data)) data = data[key] except KeyError: if debug: - print( - 'warning: can\'t find the key:"{}" in file "{}"'.format( - key, filepath - ) - ) + print('warning: can\'t find the key:"{}" in file "{}"'.format(key, filepath)) return finally: f.close() @@ -108,7 +99,7 @@ def read_value_from_json( result_dict[filepath] = data -def collect_syscap_from_codec(filepath: str, pattern: str = r'{"(.*)"') -> set: +def collect_syscap_from_codec(filepath: str, pattern: str = r'{"(.*)"') -> tuple: """ 从syscap_define.h收集syscap :param filepath: 文件的路径 @@ -127,12 +118,11 @@ def collect_syscap_from_codec(filepath: str, pattern: str = r'{"(.*)"') -> set: return array_syscap_set, array_syscap_dict -def collect_syscap_from_component( - project_path: str, - black_dirs: tuple, - key_heirarchy: tuple, - bundles: list = None, -) -> tuple: +def collect_syscap_from_component(project_path: str, + black_dirs: tuple, + key_heirarchy: tuple, + bundles: list = None, + ) -> tuple: """ 从部件的bundle.json中收集syscap :param project_path: 项目根路径 @@ -152,20 +142,10 @@ def collect_syscap_from_component( output = os.popen("find {} -name bundle.json".format(folder)) for line in output: line = line.strip() - read_value_from_json( - line, - key_heirarchy, - result_dict, - post_handler=bundle_syscap_post_handler, - ) + read_value_from_json(line, key_heirarchy, result_dict, post_handler=bundle_syscap_post_handler) else: for bundle in bundles: - read_value_from_json( - bundle, - key_heirarchy, - result_dict, - post_handler=bundle_syscap_post_handler, - ) + read_value_from_json(bundle, key_heirarchy, result_dict, post_handler=bundle_syscap_post_handler) result_set = set() for v in result_dict.values(): result_set.update(v) @@ -176,11 +156,10 @@ def sdk_syscap_post_handler(syscap: str) -> str: return syscap.strip().lstrip("*").lstrip().lstrip("*@syscap").strip() -def collect_syscap_from_sdk( - ts_path: str, - pattern: str = r"\* *@syscap +(SystemCapability\..*)", - post_handler=None, -) -> tuple: +def collect_syscap_from_sdk(ts_path: str, + pattern: str = r"\* *@syscap +((?i)SystemCapability\..*)", + post_handler=None + ) -> tuple: """ 从sdk下的*.d.ts中收集syscap :param ts_path: ts文件的所在路径 @@ -196,7 +175,7 @@ def collect_syscap_from_sdk( syscap_dict = dict() ptrn = re.compile(pattern) for ts in ts_list: - with open(ts, "r") as f: + with open(ts, 'r') as f: content = f.read() sub_syscap_list = re.findall(ptrn, content) sub_syscap_set = set() @@ -231,26 +210,19 @@ def mutual_diff(a_set: set, b_set: set) -> tuple: return a_set.difference(b_set), b_set.difference(a_set) -def print_inconsistent( - diff_set: set, a_name: str, b_name: str, table: PrettyTable, value_file_dict: dict -) -> None: - if debug: - print(value_file_dict) +def print_inconsistent(diff_set: set, a_name: str, b_name: str, table: PrettyTable, + value_file_dict: dict) -> None: table.clear() if len(diff_set) != 0: table.field_names = ["index", "SysCap only in {}".format(a_name), "Files"] add_dict_as_table_row(table, value_file_dict) elif len(diff_set) == 0: - table.field_names = [ - "All SysCap in {} have been Covered by {}".format(a_name, b_name) - ] + table.field_names = ["All SysCap in {} have been Covered by {}".format(a_name, b_name)] print(table) print() -def print_consistent( - a_diff_b_set: set, b_diff_a_set: set, table: PrettyTable, a_name: str, b_name: str -) -> bool: +def print_consistent(a_diff_b_set: set, b_diff_a_set: set, table: PrettyTable, a_name: str, b_name: str) -> bool: if len(a_diff_b_set) == 0 and len(b_diff_a_set) == 0: table.field_names = ["{} and {} are Consistent".format(a_name, b_name)] print(table) @@ -259,102 +231,60 @@ def print_consistent( return False -def print_check_result( - a_diff_b_set: set, - b_diff_a_set: set, - a_name: str, - b_name: str, - a_value_file_dict: dict, - b_value_file_dict: dict, -) -> None: +def print_check_result(a_diff_b_set: set, + b_diff_a_set: set, + a_name: str, + b_name: str, + a_value_file_dict: dict, + b_value_file_dict: dict, + ) -> None: f_table = PrettyTable() f_table.hrules = ALL - consistent_flag = print_consistent( - a_diff_b_set, b_diff_a_set, f_table, a_name, b_name - ) + consistent_flag = print_consistent(a_diff_b_set, b_diff_a_set, f_table, a_name, b_name) if not consistent_flag: print_inconsistent(a_diff_b_set, a_name, b_name, f_table, a_value_file_dict) print_inconsistent(b_diff_a_set, b_name, a_name, f_table, b_value_file_dict) -def check_component_and_codec( - project_path, - syscap_define_path: str, - component_black_dirs: tuple, - bundle_key_heirarchy: tuple, - bundles=None, -): +def check_component_and_codec(project_path, syscap_define_path: str, component_black_dirs: tuple, + bundle_key_heirarchy: tuple, bundles=None): component_syscap_set, component_syscap_dict = collect_syscap_from_component( - project_path, - black_dirs=component_black_dirs, - key_heirarchy=bundle_key_heirarchy, - bundles=bundles, + project_path, black_dirs=component_black_dirs, key_heirarchy=bundle_key_heirarchy, bundles=bundles ) array_syscap_set, array_syscap_dict = collect_syscap_from_codec(syscap_define_path) - component_diff_array, array_diff_component = mutual_diff( - component_syscap_set, array_syscap_set - ) + component_diff_array, array_diff_component = mutual_diff(component_syscap_set, array_syscap_set) value_component_dict = find_files_containes_value( component_diff_array, component_syscap_dict ) value_h_dict = find_files_containes_value(array_diff_component, array_syscap_dict) - print_check_result( - component_diff_array, - array_diff_component, - a_name="Component", - b_name="Codec", - a_value_file_dict=value_component_dict, - b_value_file_dict=value_h_dict, - ) + print_check_result(component_diff_array, array_diff_component, a_name="Component", b_name="Codec", + a_value_file_dict=value_component_dict, b_value_file_dict=value_h_dict) -def check_component_and_sdk( - project_path, - component_black_dirs: tuple, - component_key_heirarchy: tuple, - sdk_path: str, -): +def check_component_and_sdk(project_path, component_black_dirs: tuple, component_key_heirarchy: tuple, sdk_path: str): component_syscap_set, component_syscap_dict = collect_syscap_from_component( - project_path, - black_dirs=component_black_dirs, - key_heirarchy=component_key_heirarchy, - ) - ts_syscap_set, ts_syscap_dict = collect_syscap_from_sdk( - ts_path=sdk_path, post_handler=sdk_syscap_post_handler - ) - component_diff_ts, ts_diff_component = mutual_diff( - component_syscap_set, ts_syscap_set + project_path, black_dirs=component_black_dirs, key_heirarchy=component_key_heirarchy ) + ts_syscap_set, ts_syscap_dict = collect_syscap_from_sdk(ts_path=sdk_path, + post_handler=sdk_syscap_post_handler) + component_diff_ts, ts_diff_component = mutual_diff(component_syscap_set, ts_syscap_set) value_ts_dict = find_files_containes_value(ts_diff_component, ts_syscap_dict) value_component_dict = find_files_containes_value( component_diff_ts, component_syscap_dict ) - print_check_result( - component_diff_ts, - ts_diff_component, - a_name="Component", - b_name="SDK", - a_value_file_dict=value_component_dict, - b_value_file_dict=value_ts_dict, - ) + print_check_result(component_diff_ts, ts_diff_component, a_name="Component", b_name="SDK", + a_value_file_dict=value_component_dict, b_value_file_dict=value_ts_dict) def check_sdk_and_codec(syscap_define_path: str, sdk_path: str) -> None: - ts_syscap_set, ts_syscap_dict = collect_syscap_from_sdk( - ts_path=sdk_path, post_handler=sdk_syscap_post_handler - ) + ts_syscap_set, ts_syscap_dict = collect_syscap_from_sdk(ts_path=sdk_path, + post_handler=sdk_syscap_post_handler) array_syscap_set, array_syscap_dict = collect_syscap_from_codec(syscap_define_path) ts_diff_array, array_diff_ts = mutual_diff(ts_syscap_set, array_syscap_set) value_ts_dict = find_files_containes_value(ts_diff_array, ts_syscap_dict) value_h_dict = find_files_containes_value(array_diff_ts, array_syscap_dict) - print_check_result( - ts_diff_array, - array_diff_ts, - a_name="SDK", - b_name="Codec", - a_value_file_dict=value_ts_dict, - b_value_file_dict=value_h_dict, - ) + print_check_result(ts_diff_array, array_diff_ts, a_name="SDK", b_name="Codec", a_value_file_dict=value_ts_dict, + b_value_file_dict=value_h_dict) def main(): @@ -362,37 +292,23 @@ def main(): project_path = args.project_path check_target = args.check_target bundles = args.bundles - syscap_define_path = os.path.join( - project_path, "developtools", "syscap_codec", "include", "syscap_define.h" - ) + syscap_define_path = os.path.join(project_path, "developtools", "syscap_codec", "include", "syscap_define.h") ts_path = os.path.join(project_path, "interface", "sdk-js", "api") component_black_dirs = ("out",) bundle_syscap_heirarchy = ("component", "syscap") - if ( - bundles is not None or (bundles is not None and len(bundles) != 0) - ) and check_target != "component_codec": + if (bundles is not None or (bundles is not None and len(bundles) != 0)) and check_target != "component_codec": print("error: --bundles could only be used with -t component_codec") return if "component_sdk" == check_target: - check_component_and_sdk( - project_path, - component_black_dirs, - bundle_syscap_heirarchy, - sdk_path=ts_path, - ) + check_component_and_sdk(project_path, component_black_dirs, bundle_syscap_heirarchy, sdk_path=ts_path) elif "sdk_codec" == check_target: check_sdk_and_codec(syscap_define_path=syscap_define_path, sdk_path=ts_path) elif "component_codec" == check_target: if bundles is not None and len(bundles) == 0: print(r"error: '--bundles' parameter is specified, but has no value") else: - check_component_and_codec( - project_path, - syscap_define_path, - component_black_dirs=component_black_dirs, - bundle_key_heirarchy=bundle_syscap_heirarchy, - bundles=bundles, - ) + check_component_and_codec(project_path, syscap_define_path, component_black_dirs=component_black_dirs, + bundle_key_heirarchy=bundle_syscap_heirarchy, bundles=bundles) def test(): @@ -407,3 +323,4 @@ def test(): if __name__ == "__main__": main() # test() + From b5096f38d633192d7ecc92965fcbf2491e8aa91d Mon Sep 17 00:00:00 2001 From: aodongbiao Date: Fri, 23 Sep 2022 11:38:29 +0800 Subject: [PATCH 03/23] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aodongbiao Change-Id: I70656958f0189843e04bc20465c07b4025003259 --- tools/syscap_check.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/tools/syscap_check.py b/tools/syscap_check.py index 99c550d..a4932aa 100644 --- a/tools/syscap_check.py +++ b/tools/syscap_check.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (c) 2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,9 +18,6 @@ import json import re import argparse from prettytable import PrettyTable, ALL -import sys - -debug = True if sys.gettrace() else False def get_args(): @@ -83,14 +80,10 @@ def read_value_from_json(filepath: str, return f = open(filepath, 'r') data = json.load(f) - if debug: - print(filepath) for key in key_hierarchy: try: data = data[key] except KeyError: - if debug: - print('warning: can\'t find the key:"{}" in file "{}"'.format(key, filepath)) return finally: f.close() @@ -114,7 +107,7 @@ def collect_syscap_from_codec(filepath: str, pattern: str = r'{"(.*)"') -> tuple array_syscap_set.update(re.findall(ptrn, content)) array_syscap_dict[filepath] = list() for v in array_syscap_set: - array_syscap_dict[filepath].append(v) + array_syscap_dict.get(filepath).append(v) return array_syscap_set, array_syscap_dict @@ -311,16 +304,6 @@ def main(): bundle_key_heirarchy=bundle_syscap_heirarchy, bundles=bundles) -def test(): - h_path = "./bundle.json" - key_heirarchy = ("component", "syscap") - result_dict = dict() - read_value_from_json(h_path, key_heirarchy, result_dict, bundle_syscap_post_handler) - print(result_dict) - print(len(result_dict)) - - if __name__ == "__main__": main() - # test() From 5a31ef8bcbbc775efc070efff9afc642b514e504 Mon Sep 17 00:00:00 2001 From: "taiyi.pei" Date: Sat, 24 Sep 2022 11:41:48 +0800 Subject: [PATCH 04/23] remove unused code Signed-off-by: taiyi.pei --- src/syscap_tool.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 402d00d..3f16580 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -27,14 +27,6 @@ #include "create_pcid.h" #include "syscap_tool.h" -typedef struct ProductCompatibilityIDHead { - uint16_t apiVersion : 15; - uint16_t apiVersionType : 1; - uint16_t systemType : 3; - uint16_t reserved : 13; - uint32_t manufacturerID; -} PCIDHead; - typedef struct RequiredProductCompatibilityIDHead { uint16_t apiVersion : 15; uint16_t apiVersionType : 1; @@ -730,4 +722,4 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t typ printf("Fail! The pcid does not meet the rpcid\n"); } return 0; -} \ No newline at end of file +} From d008e084a21dc6a5118f947c5e6e429e92e6ba7f Mon Sep 17 00:00:00 2001 From: aodongbiao Date: Mon, 26 Sep 2022 14:40:58 +0800 Subject: [PATCH 05/23] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aodongbiao Change-Id: I8e10789dca94bef1390f13a4f6f53ba63e9b29cf --- tools/syscap_check.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/syscap_check.py b/tools/syscap_check.py index a4932aa..e2b97fa 100644 --- a/tools/syscap_check.py +++ b/tools/syscap_check.py @@ -78,15 +78,15 @@ def read_value_from_json(filepath: str, if not os.path.isfile(filepath): print('error: "{}" is not a file.') return - f = open(filepath, 'r') - data = json.load(f) - for key in key_hierarchy: - try: - data = data[key] - except KeyError: - return - finally: - f.close() + with open(filepath, 'r', encoding='utf-8') as f: + data = json.load(f) + for key in key_hierarchy: + try: + data = data[key] + except KeyError: + return + finally: + pass data = [post_handler(x) for x in data if len(x) != 0 and not x.isspace()] if len(data) != 0: result_dict[filepath] = data From 8e15834d9d3bcd717ab4f67a28ab9448e4df01b2 Mon Sep 17 00:00:00 2001 From: yudechen Date: Mon, 26 Sep 2022 11:38:35 +0800 Subject: [PATCH 06/23] change sscanf_s return value check. Signed-off-by: yudechen Change-Id: I6d9e75b5f31bd1b98b52ecc384a88da5c75034f6 --- src/syscap_tool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 402d00d..914aa77 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -592,7 +592,7 @@ int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uin // get os syscap data for (i = 0; i < PCID_OUT_BUFFER; i++) { ret = sscanf_s(input, "%u,%s", &osArray[i], input, inputLen); - if (ret == -1) { + if (ret != 2) { // 2, sscanf_s return value PRINT_ERR("sscanf_s failed.\n"); free(input); return -1; From 8bbaa248e48e6e6bfd097ff5c894947ea1bce25c Mon Sep 17 00:00:00 2001 From: wangyongzhong2 Date: Wed, 28 Sep 2022 15:07:57 +0800 Subject: [PATCH 07/23] =?UTF-8?q?=E6=B7=BB=E5=8A=A0DTX=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyongzhong2 --- include/syscap_define.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/syscap_define.h b/include/syscap_define.h index 42b3b1a..8990fe0 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -247,6 +247,7 @@ typedef enum SystemCapabilityNum { // Add here MULTIMODALINPUT_INPUT_COOPERATOR, ABILITY_ABILITYRUNTIME_QUICKFIX, + SECURITY_DLPCREDENTIALSERVICE, SYSCAP_NUM_MAX = 960 } SyscapNum; @@ -471,6 +472,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Security.CryptoFramework", SECURITY_CRYPTOFRAMEWORK}, {"SystemCapability.MultimodalInput.Input.Cooperator", MULTIMODALINPUT_INPUT_COOPERATOR}, {"SystemCapability.Ability.AbilityRuntime.QuickFix", ABILITY_ABILITYRUNTIME_QUICKFIX}, + {"SystemCapability.Security.DlpCredentialService", SECURITY_DLPCREDENTIALSERVICE}, }; #ifdef __cplusplus From 09c189dc2061df8763cc95110a3522adc1f92ba5 Mon Sep 17 00:00:00 2001 From: yudechen Date: Fri, 30 Sep 2022 16:06:19 +0800 Subject: [PATCH 08/23] roll back change. Signed-off-by: yudechen Change-Id: Idde0118a6ac1898170f933171b4b41248a0b7c22 --- src/syscap_tool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 6791ed8..3f16580 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -584,7 +584,7 @@ int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uin // get os syscap data for (i = 0; i < PCID_OUT_BUFFER; i++) { ret = sscanf_s(input, "%u,%s", &osArray[i], input, inputLen); - if (ret != 2) { // 2, sscanf_s return value + if (ret == -1) { PRINT_ERR("sscanf_s failed.\n"); free(input); return -1; From 66263dba7b0e52fe31b550aa3ee0add4879bcc2c Mon Sep 17 00:00:00 2001 From: xsz233 Date: Tue, 11 Oct 2022 19:23:19 +0800 Subject: [PATCH 09/23] IssueNo: #I5V673 Description: add bundleframework.appcontrol syscap Signed-off-by: xsz233 --- include/syscap_define.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/syscap_define.h b/include/syscap_define.h index 8990fe0..7fdaf65 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -248,6 +248,7 @@ typedef enum SystemCapabilityNum { MULTIMODALINPUT_INPUT_COOPERATOR, ABILITY_ABILITYRUNTIME_QUICKFIX, SECURITY_DLPCREDENTIALSERVICE, + BUNDLEMANAGER_BUNDLEFRAMEWORK_APPCONTROL, SYSCAP_NUM_MAX = 960 } SyscapNum; @@ -473,6 +474,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.MultimodalInput.Input.Cooperator", MULTIMODALINPUT_INPUT_COOPERATOR}, {"SystemCapability.Ability.AbilityRuntime.QuickFix", ABILITY_ABILITYRUNTIME_QUICKFIX}, {"SystemCapability.Security.DlpCredentialService", SECURITY_DLPCREDENTIALSERVICE}, + {"SystemCapability.BundleManager.BundleFramework.AppControl", BUNDLEMANAGER_BUNDLEFRAMEWORK_APPCONTROL}, }; #ifdef __cplusplus From 1dfcc68e1b41de9f2e9970060203d1065a78527e Mon Sep 17 00:00:00 2001 From: wangtiantian Date: Fri, 14 Oct 2022 03:30:47 +0000 Subject: [PATCH 10/23] IssueNo:#I5VORZ Description:add syscap Sig:SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangtiantian --- include/syscap_define.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/syscap_define.h b/include/syscap_define.h index 7fdaf65..554276c 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -249,6 +249,11 @@ typedef enum SystemCapabilityNum { ABILITY_ABILITYRUNTIME_QUICKFIX, SECURITY_DLPCREDENTIALSERVICE, BUNDLEMANAGER_BUNDLEFRAMEWORK_APPCONTROL, + BUNDLEMANAGER_BUNDLEFRAMEWORK_CORE, + BUNDLEMANAGER_BUNDLEFRAMEWORK_FREEINSTALL, + BUNDLEMANAGER_BUNDLEFRAMEWORK_LAUNCHER, + BUNDLEMANAGER_BUNDLEFRAMEWORK_DEFAULTAPPMANAGER, + BUNDLEMANAGER_BUNDLEFRAMEWORK_RESOURCE, SYSCAP_NUM_MAX = 960 } SyscapNum; @@ -475,6 +480,12 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Ability.AbilityRuntime.QuickFix", ABILITY_ABILITYRUNTIME_QUICKFIX}, {"SystemCapability.Security.DlpCredentialService", SECURITY_DLPCREDENTIALSERVICE}, {"SystemCapability.BundleManager.BundleFramework.AppControl", BUNDLEMANAGER_BUNDLEFRAMEWORK_APPCONTROL}, + {"SystemCapability.BundleManager.BundleFramework.Core", BUNDLEMANAGER_BUNDLEFRAMEWORK_CORE}, + {"SystemCapability.BundleManager.BundleFramework.FreeInstall", BUNDLEMANAGER_BUNDLEFRAMEWORK_FREEINSTALL}, + {"SystemCapability.BundleManager.BundleFramework.Launcher", BUNDLEMANAGER_BUNDLEFRAMEWORK_LAUNCHER}, + {"SystemCapability.BundleManager.BundleFramework.DefaultAppManager", + BUNDLEMANAGER_BUNDLEFRAMEWORK_DEFAULTAPPMANAGER}, + {"SystemCapability.BundleManager.BundleFramework.Resource", BUNDLEMANAGER_BUNDLEFRAMEWORK_RESOURCE} }; #ifdef __cplusplus From 3ac7332af5f811e1577ffd42b997a42c130c6ca2 Mon Sep 17 00:00:00 2001 From: leiiyb Date: Tue, 18 Oct 2022 16:21:18 +0800 Subject: [PATCH 11/23] add avsession syscap Signed-off-by: leiiyb --- include/syscap_define.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/syscap_define.h b/include/syscap_define.h index 554276c..f6cea5f 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -254,6 +254,8 @@ typedef enum SystemCapabilityNum { BUNDLEMANAGER_BUNDLEFRAMEWORK_LAUNCHER, BUNDLEMANAGER_BUNDLEFRAMEWORK_DEFAULTAPPMANAGER, BUNDLEMANAGER_BUNDLEFRAMEWORK_RESOURCE, + MULTIMEDIA_AVSESSION_CORE, + MULTIMEDIA_AVSESSION_MANAGER, SYSCAP_NUM_MAX = 960 } SyscapNum; @@ -485,7 +487,9 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.BundleManager.BundleFramework.Launcher", BUNDLEMANAGER_BUNDLEFRAMEWORK_LAUNCHER}, {"SystemCapability.BundleManager.BundleFramework.DefaultAppManager", BUNDLEMANAGER_BUNDLEFRAMEWORK_DEFAULTAPPMANAGER}, - {"SystemCapability.BundleManager.BundleFramework.Resource", BUNDLEMANAGER_BUNDLEFRAMEWORK_RESOURCE} + {"SystemCapability.BundleManager.BundleFramework.Resource", BUNDLEMANAGER_BUNDLEFRAMEWORK_RESOURCE}, + {"SystemCapability.Multimedia.AVSession.Core", MULTIMEDIA_AVSESSION_CORE}, + {"SystemCapability.Multimedia.AVSession.Manager", MULTIMEDIA_AVSESSION_MANAGER} }; #ifdef __cplusplus From 6eb70f71bf36ecc811c378e55dad605155284b3b Mon Sep 17 00:00:00 2001 From: li-yifan2 Date: Fri, 21 Oct 2022 08:50:51 +0800 Subject: [PATCH 12/23] update include/syscap_define.h. Signed-off-by: li-yifan2 --- include/syscap_define.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/syscap_define.h b/include/syscap_define.h index f6cea5f..34ca72e 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -256,6 +256,7 @@ typedef enum SystemCapabilityNum { BUNDLEMANAGER_BUNDLEFRAMEWORK_RESOURCE, MULTIMEDIA_AVSESSION_CORE, MULTIMEDIA_AVSESSION_MANAGER, + MULTIMEDIA_AUDIO_TONE, SYSCAP_NUM_MAX = 960 } SyscapNum; @@ -489,7 +490,8 @@ const static SyscapWithNum g_arraySyscap[] = { BUNDLEMANAGER_BUNDLEFRAMEWORK_DEFAULTAPPMANAGER}, {"SystemCapability.BundleManager.BundleFramework.Resource", BUNDLEMANAGER_BUNDLEFRAMEWORK_RESOURCE}, {"SystemCapability.Multimedia.AVSession.Core", MULTIMEDIA_AVSESSION_CORE}, - {"SystemCapability.Multimedia.AVSession.Manager", MULTIMEDIA_AVSESSION_MANAGER} + {"SystemCapability.Multimedia.AVSession.Manager", MULTIMEDIA_AVSESSION_MANAGER}, + {"SystemCapability.Multimedia.Audio.Tone", MULTIMEDIA_AUDIO_TONE} }; #ifdef __cplusplus From aefdfa5a3cad116f11a88b53257a42b239ee721d Mon Sep 17 00:00:00 2001 From: yudechen Date: Tue, 25 Oct 2022 16:39:08 +0800 Subject: [PATCH 13/23] modify BUILD.gn for compile liteos_m device. Signed-off-by: yudechen Change-Id: I6d304af15af0707a06a946188f2b7702653ee5fe --- BUILD.gn | 83 ++++++-------------- test/syscap_tool_test.c | 143 ---------------------------------- test/unittest/common/BUILD.gn | 66 ++++++++-------- 3 files changed, 58 insertions(+), 234 deletions(-) delete mode 100644 test/syscap_tool_test.c diff --git a/BUILD.gn b/BUILD.gn index a8f3527..b01dff9 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -59,6 +59,9 @@ ohos_executable("syscap_tool_bin") { if (is_mingw) { defines += [ "_POSIX_" ] } + if (defined(ohos_lite) && ohos_kernel_type == "liteos_m") { + cflags = [ "-DPATH_MAX=1024" ] + } sources = [ "./src/main.c" ] sources += sources_platform_common @@ -74,71 +77,32 @@ ohos_executable("syscap_tool_bin") { part_name = "syscap_codec" } -ohos_executable("syscap_tool_test") { - install_enable = true - include_dirs = [ "src" ] - public_configs = [ ":pubilc" ] - defines = [] - - if (is_mingw) { - defines += [ "_POSIX_" ] - } - - sources = [ "./test/syscap_tool_test.c" ] - sources += sources_platform_common - - deps = [ "//third_party/bounds_checking_function:libsec_static" ] - - if (defined(ohos_lite)) { - deps += [ "//build/lite/config/component/cJSON:cjson_static" ] - } else { - deps += [ "//third_party/cJSON:cjson_static" ] - } - - subsystem_name = "developtools" - part_name = "syscap_codec" -} - -ohos_shared_library("syscap_tool_shared") { - output_name = "syscap_codec" - include_dirs = [ "src" ] - public_configs = [ ":pubilc" ] - - sources = sources_platform_common - - deps = [ "//third_party/bounds_checking_function:libsec_static" ] - - if (defined(ohos_lite)) { - deps += [ "//build/lite/config/component/cJSON:cjson_static" ] - } else { - deps += [ "//third_party/cJSON:cjson_static" ] - } - - subsystem_name = "developtools" - part_name = "syscap_codec" -} - config("syscap_interface_public_config") { include_dirs = [ "./interfaces/inner_api/" ] } if (defined(ohos_lite)) { - shared_library("syscap_interface_shared") { - include_dirs = [ - "include", - "src", - ] - public_configs = [ ":syscap_interface_public_config" ] - sources = [ - "./interfaces/inner_api/syscap_interface.c", - "./src/endian_internal.c", - "./src/syscap_tool.c", - ] + if (ohos_kernel_type == "liteos_m") { + group("syscap_interface_shared") { + } + } else { + shared_library("syscap_interface_shared") { + include_dirs = [ + "include", + "src", + ] + public_configs = [ ":syscap_interface_public_config" ] + sources = [ + "./interfaces/inner_api/syscap_interface.c", + "./src/endian_internal.c", + "./src/syscap_tool.c", + ] - deps = [ - "//build/lite/config/component/cJSON:cjson_static", - "//third_party/bounds_checking_function:libsec_static", - ] + deps = [ + "//build/lite/config/component/cJSON:cjson_static", + "//third_party/bounds_checking_function:libsec_static", + ] + } } } else { ohos_shared_library("syscap_interface_shared") { @@ -199,7 +163,6 @@ group("syscap_codec") { ":pcid_sc", ":syscap_define_check", ":syscap_interface_shared", - ":syscap_tool_shared", ] if (support_jsapi && is_standard_system) { deps += [ "napi:systemcapability" ] diff --git a/test/syscap_tool_test.c b/test/syscap_tool_test.c deleted file mode 100644 index acf45d1..0000000 --- a/test/syscap_tool_test.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "syscap_tool.h" -#include "create_pcid.h" - -char *g_testFilePcid = "{\n \"api_version\": 0,\n \"manufacturer_id\": 0,\n \"product\": \"rk3568\",\n" \ - " \"syscap\": {\n \"os\": [\n \"SystemCapability.Account.AppAccount\",\n" \ - " \"SystemCapability.Account.OsAccount\"\n ]\n },\n" \ - " \"system_type\": \"standard\"\n}"; -char *g_testFileRpcid = "{\n \"api_version\": 7,\n \"syscap\": [\n \"SystemCapability.hiviewdfx.hilog\",\n" \ - " \"SystemCapability.communication.softbus\",\n \"SystemCapability.hisicon.flashlight\"\n ]\n}"; - -int32_t PrepareTestFile(char *fileName, char *fileContext) -{ - int32_t ret; - FILE *fp = fopen(fileName, "wb"); - if (fp == NULL) { - return -1; - } - size_t len = fwrite(fileContext, 1, strlen(fileContext), fp); - if (len != strlen(fileContext)) { - (void)fclose(fp); - return -1; - } - ret = fclose(fp); - if (ret != 0) { - return -1; - } - return 0; -} - -int main(int argc, char **argv) -{ - int32_t status; - - char *pcidFileName = "SystemCapability.json"; - char *rpcidFileName = "rpcid.json"; - printf("###start syscap tool test###\n"); - - (void)unlink(pcidFileName); - (void)unlink(rpcidFileName); - (void)unlink("./rk3568.sc"); - (void)unlink("./newPCID.sc"); - (void)unlink("./rpcid.sc"); - (void)unlink("./rk3568.json"); - - pid_t pid = fork(); - if (pid == 0) { - printf("prepare test file...\n"); - int32_t passCnt = 0; - int32_t ret = PrepareTestFile(pcidFileName, g_testFilePcid); - if (ret != 0) { - printf(" error: prepare pcid file failed\n"); - exit(passCnt); - } - ret = PrepareTestFile(rpcidFileName, g_testFileRpcid); - if (ret != 0) { - printf(" error: prepare rpcid file failed\n"); - exit(passCnt); - } - printf("1.test rpcid.json encode to rpcid.sc\n"); - ret = RPCIDEncode(rpcidFileName, "./"); - if (ret != 0) { - printf(" error: rpcid.json encode failed\n"); - exit(passCnt); - } - passCnt++; - printf("pass\n"); - printf("2.test rpcid.sc decode to rpcid.json\n"); - ret = RPCIDDecode("rpcid.sc", "./"); - if (ret != 0) { - printf(" error: rpcid.sc decode failed\n"); - exit(passCnt); - } - passCnt++; - printf("pass\n"); - printf("3.test pcid.json encode to pcid.sc\n"); - ret = PCIDEncode(pcidFileName, "./"); - if (ret != 0) { - printf(" error: pcid.json encode failed\n"); - exit(passCnt); - } - passCnt++; - printf("pass\n"); - printf("4.test pcid.sc decode to pcid.json\n"); - ret = PCIDDecode("./rk3568.sc", "./"); - if (ret != 0) { - printf(" error: pcid.sc decode failed\n"); - exit(passCnt); - } - passCnt++; - printf("pass\n"); - printf("5.test pcid.json encode to new PCID.sc\n"); - ret = CreatePCID("./newPCID.sc", "./"); - if (ret != 0) { - printf(" error: new pcid.sc encode failed\n"); - exit(passCnt); - } - passCnt++; - printf("pass\n"); - printf("6.test new pcid.sc decode to pcid.json\n"); - ret = PCIDDecode("./newPCID.sc", "./"); - if (ret != 0) { - printf(" error: new pcid.sc decode failed\n"); - exit(passCnt); - } - passCnt++; - printf("pass\n"); - exit(passCnt); - } - (void)wait(&status); - printf("summary: total 4 passed %d\n", WEXITSTATUS(status)); - (void)unlink(pcidFileName); - (void)unlink(rpcidFileName); - (void)unlink("./rk3568.sc"); - (void)unlink("./newPCID.sc"); - (void)unlink("./rpcid.sc"); - (void)unlink("./rk3568.json"); - - return 0; -} \ No newline at end of file diff --git a/test/unittest/common/BUILD.gn b/test/unittest/common/BUILD.gn index aa33c11..4c431f5 100644 --- a/test/unittest/common/BUILD.gn +++ b/test/unittest/common/BUILD.gn @@ -11,51 +11,55 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/lite/config/component/lite_component.gni") if (defined(ohos_lite)) { - import("//build/lite/config/component/lite_component.gni") import("//build/lite/config/test.gni") - test_output_root = "$root_out_dir/test/unittest/syscap_codec" - executable("test_syscap_napi_unittest") { - output_extension = "bin" - output_dir = test_output_root + if (ohos_kernel_type != "liteos_m") { + test_output_root = "$root_out_dir/test/unittest/syscap_codec" - include_dirs = [ - "//commonlibrary/c_utils/base/include", - "//third_party/node/src", - "//third_party/googletest/include", - "//developtools/syscap_codec/src/", - "//developtools/syscap_codec/include/", - "//developtools/syscap_codec/interfaces/inner_api/", - "//developtools/syscap_codec/test/unittest/common/include/", - ] + executable("test_syscap_napi_unittest") { + output_extension = "bin" + output_dir = test_output_root - cflags = [ "-g3" ] + include_dirs = [ + "//commonlibrary/c_utils/base/include", + "//third_party/node/src", + "//third_party/googletest/include", + "//developtools/syscap_codec/src/", + "//developtools/syscap_codec/include/", + "//developtools/syscap_codec/interfaces/inner_api/", + "//developtools/syscap_codec/test/unittest/common/include/", + ] - sources = [ - "//developtools/syscap_codec/interfaces/inner_api/syscap_interface.c", - "//developtools/syscap_codec/src/create_pcid.c", - "//developtools/syscap_codec/src/endian_internal.c", - "//developtools/syscap_codec/src/syscap_tool.c", - "syscap_codec_test.cpp", - ] + cflags = [ "-g3" ] - defines = [ "NAPI_TEST" ] + sources = [ + "//developtools/syscap_codec/interfaces/inner_api/syscap_interface.c", + "//developtools/syscap_codec/src/create_pcid.c", + "//developtools/syscap_codec/src/endian_internal.c", + "//developtools/syscap_codec/src/syscap_tool.c", + "syscap_codec_test.cpp", + ] - deps = [ - "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//test/testfwk/developer_test/third_party/lib/cpp:gtest_main", - "//third_party/bounds_checking_function:libsec_static", - ] + defines = [ "NAPI_TEST" ] - deps += [ "//build/lite/config/component/cJSON:cjson_static" ] + deps = [ + "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//test/testfwk/developer_test/third_party/lib/cpp:gtest_main", + "//third_party/bounds_checking_function:libsec_static", + ] + + deps += [ "//build/lite/config/component/cJSON:cjson_static" ] + } } group("unittest") { - deps = [ ":test_syscap_napi_unittest" ] + if (ohos_kernel_type != "liteos_m") { + deps = [ ":test_syscap_napi_unittest" ] + } } } else { - import("//build/lite/config/component/lite_component.gni") import("//build/ohos.gni") import("//build/test.gni") From 48987150de4f185ee7bbb7ead96c550844bd7cd8 Mon Sep 17 00:00:00 2001 From: yudechen Date: Wed, 26 Oct 2022 18:49:23 +0800 Subject: [PATCH 14/23] fix: fix some code bugs. Signed-off-by: yudechen Change-Id: I0a1d256aabca1c34ac56b6ceaee77e6a7916d5ec --- interfaces/inner_api/syscap_interface.c | 2 +- src/create_pcid.c | 2 +- src/syscap_tool.c | 2 +- test/syscap_define_check.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index eeb349d..06c95ab 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -298,7 +298,7 @@ bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *o return true; } -static int SetOsSysCapBitMap(uint8_t *out, uint16_t outLen, uint16_t *index, uint16_t indexLen) +static int SetOsSysCapBitMap(uint8_t *out, uint16_t outLen, const uint16_t *index, uint16_t indexLen) { uint16_t sector, pos; diff --git a/src/create_pcid.c b/src/create_pcid.c index ab48c8b..5d6d98b 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -420,7 +420,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) } char *ptrPrivateSyscap = (char *)(pcidMain + 1); - uint16_t privateSyscapLen = contextBufLen - sizeof(PCIDMain) - 1; + size_t privateSyscapLen = contextBufLen - sizeof(PCIDMain) - 1; char priSyscapStr[SINGLE_SYSCAP_LEN] = {0}; char *tempPriSyscapStr = priSyscapStr; char fullPriSyscapStr[SINGLE_SYSCAP_LEN] = {0}; diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 3f16580..0765f17 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -395,7 +395,7 @@ FREE_CONTEXT_OUT: return ret; } -static int SetOsSysCapBitMap(uint8_t *out, uint16_t outLen, uint16_t *index, uint16_t indexLen) +static int SetOsSysCapBitMap(uint8_t *out, uint16_t outLen, const uint16_t *index, uint16_t indexLen) { uint16_t sector, pos; diff --git a/test/syscap_define_check.c b/test/syscap_define_check.c index 9ae0ca1..c063bd0 100644 --- a/test/syscap_define_check.c +++ b/test/syscap_define_check.c @@ -25,7 +25,7 @@ int main(void) for (size_t i = 0; i < size; i++) { if (g_arraySyscap[i].num != i) { - printf("[Error][syscap_define.h]: %s -> num(%u) should be %lu.\n", + printf("[Error][syscap_define.h]: %s -> num(%u) should be %zu.\n", g_arraySyscap[i].str, g_arraySyscap[i].num, i); flag++; } From 73d9cf0146106873eac596e7eb999404f9f65e6e Mon Sep 17 00:00:00 2001 From: wangtao Date: Fri, 28 Oct 2022 15:46:21 +0800 Subject: [PATCH 15/23] bundle Interrupt Signed-off-by: wangtao Change-Id: Icb56779399040b8cb1777ce561fc9016d3dbf48a --- include/syscap_define.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/syscap_define.h b/include/syscap_define.h index 34ca72e..b3f2a37 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -257,6 +257,7 @@ typedef enum SystemCapabilityNum { MULTIMEDIA_AVSESSION_CORE, MULTIMEDIA_AVSESSION_MANAGER, MULTIMEDIA_AUDIO_TONE, + MULTIMEDIA_AUDIO_INTERRUPT, SYSCAP_NUM_MAX = 960 } SyscapNum; @@ -491,7 +492,8 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.BundleManager.BundleFramework.Resource", BUNDLEMANAGER_BUNDLEFRAMEWORK_RESOURCE}, {"SystemCapability.Multimedia.AVSession.Core", MULTIMEDIA_AVSESSION_CORE}, {"SystemCapability.Multimedia.AVSession.Manager", MULTIMEDIA_AVSESSION_MANAGER}, - {"SystemCapability.Multimedia.Audio.Tone", MULTIMEDIA_AUDIO_TONE} + {"SystemCapability.Multimedia.Audio.Tone", MULTIMEDIA_AUDIO_TONE}, + {"SystemCapability.Multimedia.Audio.Interrupt", MULTIMEDIA_AUDIO_INTERRUPT} }; #ifdef __cplusplus From d47ad15592ff5ee5d9b6a61a15f709d0c208140b Mon Sep 17 00:00:00 2001 From: yudechen Date: Tue, 1 Nov 2022 18:12:12 +0800 Subject: [PATCH 16/23] fix: fix unsigned can't less than zero. Signed-off-by: yudechen Change-Id: Ica044f16c48d6e41746b2af3f5e9ddb0ec9103c5 --- src/create_pcid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/create_pcid.c b/src/create_pcid.c index 5d6d98b..50feb86 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -424,7 +424,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) char priSyscapStr[SINGLE_SYSCAP_LEN] = {0}; char *tempPriSyscapStr = priSyscapStr; char fullPriSyscapStr[SINGLE_SYSCAP_LEN] = {0}; - if (privateSyscapLen < 0) { + if ((long)privateSyscapLen < 0) { PRINT_ERR("parse private syscap failed."); ret = -1; goto FREE_VECTOR_OUT; From d732bd9ba5f4df6a2995cbf7c5e11b4d1f3cf2a2 Mon Sep 17 00:00:00 2001 From: yudechen Date: Thu, 3 Nov 2022 15:56:21 +0800 Subject: [PATCH 17/23] fix: privateSyscapLen cant be unsigned data. Signed-off-by: yudechen Change-Id: I729e1f50d84874a3d8117b7ff453bba4185c3c97 --- src/create_pcid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/create_pcid.c b/src/create_pcid.c index 50feb86..0742014 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -420,11 +420,11 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) } char *ptrPrivateSyscap = (char *)(pcidMain + 1); - size_t privateSyscapLen = contextBufLen - sizeof(PCIDMain) - 1; + int privateSyscapLen = contextBufLen - sizeof(PCIDMain) - 1; char priSyscapStr[SINGLE_SYSCAP_LEN] = {0}; char *tempPriSyscapStr = priSyscapStr; char fullPriSyscapStr[SINGLE_SYSCAP_LEN] = {0}; - if ((long)privateSyscapLen < 0) { + if (privateSyscapLen < 0) { PRINT_ERR("parse private syscap failed."); ret = -1; goto FREE_VECTOR_OUT; From 4a7a2d6155e715bac17726bc86907b2aaa14bbe3 Mon Sep 17 00:00:00 2001 From: yudechen Date: Thu, 10 Nov 2022 18:26:45 +0800 Subject: [PATCH 18/23] fix: modify for codecheck. Signed-off-by: yudechen Change-Id: I958ff1debd07586cdeee83e4732a4aefcfab4651 --- napi/napi_query_syscap.cpp | 48 +++++++++++++++++++------------------- src/create_pcid.c | 44 +++++++++++++++++----------------- src/syscap_tool.c | 26 ++++++++++----------- 3 files changed, 59 insertions(+), 59 deletions(-) diff --git a/napi/napi_query_syscap.cpp b/napi/napi_query_syscap.cpp index 5cbb3d9..858f934 100644 --- a/napi/napi_query_syscap.cpp +++ b/napi/napi_query_syscap.cpp @@ -42,7 +42,7 @@ constexpr size_t KEY_BUFFER_SIZE = 32; napi_get_cb_info(env, info, &argc, argv, &thisVar, &data) // Async Function Set -struct systemCapabilityAsyncContext { +struct SystemCapabilityAsyncContext { napi_env env = nullptr; napi_async_work work = nullptr; char key[KEY_BUFFER_SIZE] = { 0 }; @@ -64,7 +64,7 @@ static char* getSystemCapability() uint32_t *osCapU32 = nullptr; char *priOutput = nullptr; char *temp = nullptr; - char *allSyscapBUffer = nullptr; + char *allSyscapBuffer = nullptr; char osCapArray[PCID_MAIN_U32][U32_TO_STR_MAX_LEN] = {}; char (*priCapArray)[SINGLE_SYSCAP_LEN] = nullptr; @@ -105,39 +105,39 @@ static char* getSystemCapability() sumLen += (PCID_MAIN_U32 + priCapArrayCnt + 1); // split with ',' // splicing string - allSyscapBUffer = (char *)malloc(sumLen); - if (allSyscapBUffer == nullptr) { + allSyscapBuffer = (char *)malloc(sumLen); + if (allSyscapBuffer == nullptr) { PRINT_ERR("malloc failed!"); goto FREE_PRICAP_ARRAY; } - err = memset_s(allSyscapBUffer, sumLen, 0, sumLen); + err = memset_s(allSyscapBuffer, sumLen, 0, sumLen); if (err != EOK) { PRINT_ERR("memset failed!"); - free(allSyscapBUffer); - allSyscapBUffer = nullptr; + free(allSyscapBuffer); + allSyscapBuffer = nullptr; goto FREE_PRICAP_ARRAY; } temp = *osCapArray; for (size_t i = 1; i < PCID_MAIN_U32; i++) { - retError = sprintf_s(allSyscapBUffer, sumLen, "%s,%s", temp, osCapArray[i]); + retError = sprintf_s(allSyscapBuffer, sumLen, "%s,%s", temp, osCapArray[i]); if (retError == -1) { PRINT_ERR("splicing os syscap string failed."); - free(allSyscapBUffer); - allSyscapBUffer = nullptr; + free(allSyscapBuffer); + allSyscapBuffer = nullptr; goto FREE_PRICAP_ARRAY; } - temp = allSyscapBUffer; + temp = allSyscapBuffer; } for (int i = 0; i < priCapArrayCnt; i++) { - retError = sprintf_s(allSyscapBUffer, sumLen, "%s,%s", temp, *(priCapArray + i)); + retError = sprintf_s(allSyscapBuffer, sumLen, "%s,%s", temp, *(priCapArray + i)); if (retError == -1) { PRINT_ERR("splicing pri syscap string failed."); - free(allSyscapBUffer); - allSyscapBUffer = nullptr; + free(allSyscapBuffer); + allSyscapBuffer = nullptr; goto FREE_PRICAP_ARRAY; } - temp = allSyscapBUffer; + temp = allSyscapBuffer; } FREE_PRICAP_ARRAY: @@ -145,7 +145,7 @@ FREE_PRICAP_ARRAY: FREE_PRIOUTPUT: free(priOutput); - return allSyscapBUffer; + return allSyscapBuffer; } napi_value QuerySystemCapability(napi_env env, napi_callback_info info) @@ -154,7 +154,7 @@ napi_value QuerySystemCapability(napi_env env, napi_callback_info info) NAPI_ASSERT(env, argc <= 1, "too many parameters"); napi_value result = nullptr; - systemCapabilityAsyncContext* asyncContext = new systemCapabilityAsyncContext(); + SystemCapabilityAsyncContext* asyncContext = new SystemCapabilityAsyncContext(); asyncContext->env = env; @@ -178,7 +178,7 @@ napi_value QuerySystemCapability(napi_env env, napi_callback_info info) napi_create_async_work( env, nullptr, resource, [](napi_env env, void* data) { - systemCapabilityAsyncContext *asyncContext = (systemCapabilityAsyncContext *)data; + SystemCapabilityAsyncContext *asyncContext = (SystemCapabilityAsyncContext *)data; char *syscapStr = getSystemCapability(); if (syscapStr != nullptr) { asyncContext->value = syscapStr; @@ -188,8 +188,8 @@ napi_value QuerySystemCapability(napi_env env, napi_callback_info info) } }, [](napi_env env, napi_status status, void* data) { - systemCapabilityAsyncContext *asyncContext = (systemCapabilityAsyncContext *)data; - napi_value result[2] = {0}; + SystemCapabilityAsyncContext *asyncContext = (SystemCapabilityAsyncContext *)data; + napi_value result[2] = {nullptr, nullptr}; if (!asyncContext->status) { napi_get_undefined(env, &result[0]); napi_create_string_utf8(env, asyncContext->value, strlen(asyncContext->value), &result[1]); // ? @@ -235,14 +235,14 @@ EXTERN_C_END /* * Module define */ -static napi_module systemCapabilityModule = { +static napi_module g_systemCapabilityModule = { .nm_version = 1, .nm_flags = 0, .nm_filename = nullptr, .nm_register_func = QuerryExport, .nm_modname = "systemCapability", - .nm_priv = ((void*)0), - .reserved = {0}, + .nm_priv = nullptr, + .reserved = {nullptr}, }; /* @@ -250,6 +250,6 @@ static napi_module systemCapabilityModule = { */ extern "C" __attribute__((constructor)) void systemCapabilityRegisterModule(void) { - napi_module_register(&systemCapabilityModule); + napi_module_register(&g_systemCapabilityModule); } } \ No newline at end of file diff --git a/src/create_pcid.c b/src/create_pcid.c index 0742014..8ef9321 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -231,8 +231,8 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) uint16_t allPriSyscapStrLen = 0; for (i = 0; i < privateCapSize; i++) { - jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, i); - allPriSyscapStrLen += strlen(strchr(jsonArrayItem->valuestring, '.') + 1); + jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, (int)i); + allPriSyscapStrLen += (uint16_t)strlen(strchr(jsonArrayItem->valuestring, '.') + 1); allPriSyscapStrLen++; // for separator ',' } if ((allPriSyscapStrLen + 1) > PRIVATE_SYSCAP_SIZE) { @@ -241,18 +241,18 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) goto FREE_CONVERT_OUT; } - uint16_t PCIDLength = sizeof(PCIDMain) + allPriSyscapStrLen + 1; - PCIDMain *PCIDBuffer = (PCIDMain *)malloc(PCIDLength); - if (PCIDBuffer == NULL) { + uint16_t pcidLength = sizeof(PCIDMain) + allPriSyscapStrLen + 1; + PCIDMain *pcidBuffer = (PCIDMain *)malloc(pcidLength); + if (pcidBuffer == NULL) { PRINT_ERR("malloc for pcid buffer failed\n"); ret = -1; goto FREE_CONVERT_OUT; } - (void)memset_s(PCIDBuffer, PCIDLength, 0, PCIDLength); + (void)memset_s(pcidBuffer, pcidLength, 0, pcidLength); // process os syscap for (i = 0; i < osCapSize; i++) { - jsonArrayItem = cJSON_GetArrayItem(jsonOsSyscapObj, i); + jsonArrayItem = cJSON_GetArrayItem(jsonOsSyscapObj, (int)i); osCapIndex = cJSON_GetObjectItem(allOsSyscapObj, jsonArrayItem->valuestring); if (osCapIndex == NULL) { PRINT_ERR("can't find the syscap: %s, please add it in syscap_define.h.\n", jsonArrayItem->valuestring); @@ -266,14 +266,14 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) ret = -1; goto FREE_PCID_BUFFER_OUT; } - PCIDBuffer->osSyscap[sectorOfBits] |= 1 << (posOfBits); + pcidBuffer->osSyscap[sectorOfBits] |= 1 << (posOfBits); } // process private syscap - char *priSyscapHead = (char *)(PCIDBuffer + 1); + char *priSyscapHead = (char *)(pcidBuffer + 1); char *priSyscapStr = NULL; for (i = 0; i < privateCapSize; i++) { - jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, i); + jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, (int)i); priSyscapStr = strchr(jsonArrayItem->valuestring, '.') + 1; nRet = strcat_s(priSyscapHead, allPriSyscapStrLen + 1, priSyscapStr); nRet += strcat_s(priSyscapHead, allPriSyscapStrLen + 1, ","); @@ -290,8 +290,8 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) ret = -1; goto FREE_PCID_BUFFER_OUT; } - PCIDBuffer->apiVersion = HtonsInter((uint16_t)jsonSyscapObj->valueint); - PCIDBuffer->apiVersionType = 0; + pcidBuffer->apiVersion = HtonsInter((uint16_t)jsonSyscapObj->valueint); + pcidBuffer->apiVersionType = 0; jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "system_type"); if (jsonSyscapObj == NULL || !cJSON_IsString(jsonSyscapObj)) { @@ -300,10 +300,10 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) goto FREE_PCID_BUFFER_OUT; } systemType = jsonSyscapObj->valuestring; - PCIDBuffer->systemType = !strcmp(systemType, "mini") ? 0b001 : + pcidBuffer->systemType = !strcmp(systemType, "mini") ? 0b001 : (!strcmp(systemType, "small") ? 0b010 : (!strcmp(systemType, "standard") ? 0b100 : 0)); - if (PCIDBuffer->systemType == 0) { + if (pcidBuffer->systemType == 0) { PRINT_ERR("\"system_type\" is invaild, systemType = \"%s\"\n", systemType); ret = -1; goto FREE_PCID_BUFFER_OUT; @@ -315,10 +315,10 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) ret = -1; goto FREE_PCID_BUFFER_OUT; } - PCIDBuffer->manufacturerID = HtonlInter((uint32_t)jsonSyscapObj->valueint); + pcidBuffer->manufacturerID = HtonlInter((uint32_t)jsonSyscapObj->valueint); const char pcidFileName[] = "PCID.sc"; - ret = ConvertedContextSaveAsFile(outDirPath, pcidFileName, (char *)PCIDBuffer, PCIDLength); + ret = ConvertedContextSaveAsFile(outDirPath, pcidFileName, (char *)pcidBuffer, pcidLength); if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", outDirPath, pcidFileName); ret = -1; @@ -326,7 +326,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) } FREE_PCID_BUFFER_OUT: - free(PCIDBuffer); + free(pcidBuffer); FREE_CONVERT_OUT: free(allOsSyscapObj); FreeContextBuffer(contextBuffer); @@ -376,7 +376,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) } nRet = memcpy_s(osSyscap, OS_SYSCAP_BYTES, (uint8_t *)pcidMain + 8, OS_SYSCAP_BYTES); // 8, bytes of pcid header - if (EOK != nRet) { + if (nRet != EOK) { PRINT_ERR("memcpy_s failed."); ret = -1; goto FREE_VECTOR_OUT; @@ -420,7 +420,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) } char *ptrPrivateSyscap = (char *)(pcidMain + 1); - int privateSyscapLen = contextBufLen - sizeof(PCIDMain) - 1; + int privateSyscapLen = (int)(contextBufLen - sizeof(PCIDMain) - 1); char priSyscapStr[SINGLE_SYSCAP_LEN] = {0}; char *tempPriSyscapStr = priSyscapStr; char fullPriSyscapStr[SINGLE_SYSCAP_LEN] = {0}; @@ -694,15 +694,15 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) PRINT_ERR("Add syscap to json failed.\n"); goto ADD_JSON_FAILED; } - if (AddHeaderToJsonObj(pcidHeader, PCID_HEADER, rootObj)) { + if (AddHeaderToJsonObj(pcidHeader, PCID_HEADER, rootObj) != 0) { PRINT_ERR("Add header to json object failed.\n"); goto ADD_JSON_FAILED; } - if (AddOsSyscapToJsonObj(osSyscapUintArray, OS_SYSCAP_NUM, sysCapObj)) { + if (AddOsSyscapToJsonObj(osSyscapUintArray, OS_SYSCAP_NUM, sysCapObj) != 0) { PRINT_ERR("Add os syscap json object failed.\n"); goto ADD_JSON_FAILED; } - if (AddPriSyscapToJsonObj(priSyscapStr, strlen(priSyscapStr), sysCapObj)) { + if (AddPriSyscapToJsonObj(priSyscapStr, (uint32_t)strlen(priSyscapStr), sysCapObj) != 0) { PRINT_ERR("Add private syscap json object failed.\n"); goto ADD_JSON_FAILED; } diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 0765f17..ff3e461 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -170,7 +170,7 @@ static cJSON *CreateWholeSyscapJsonObj(void) return root; } -int32_t RPCIDEncode(char *inputFile, char *outDirPath) +int32_t RPCIDEncode(char *inputFile, char *outputPath) { int32_t ret; char *contextBuffer = NULL; @@ -240,7 +240,7 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath) *(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(sysCapSize * SINGLE_FEAT_LEN)); fillTmpPtr += sizeof(uint16_t); for (uint32_t i = 0; i < sysCapSize; i++) { - arrayItemPtr = cJSON_GetArrayItem(sysCapPtr, i); + arrayItemPtr = cJSON_GetArrayItem(sysCapPtr, (int)i); char *pointPos = strchr(arrayItemPtr->valuestring, '.'); if (pointPos == NULL) { PRINT_ERR("context of \"syscap\" array is invalid\n"); @@ -263,9 +263,9 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath) fillTmpPtr += SINGLE_FEAT_LEN; } - ret = ConvertedContextSaveAsFile(outDirPath, "RPCID.sc", convertedBuffer, convertedBufLen); + ret = ConvertedContextSaveAsFile(outputPath, "RPCID.sc", convertedBuffer, convertedBufLen); if (ret != 0) { - PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:rpcid.sc\n", outDirPath); + PRINT_ERR("ConvertedContextSaveAsFile failed, outputPath:%s, filename:rpcid.sc\n", outputPath); goto FREE_CONVERT_OUT; } @@ -360,7 +360,7 @@ static int32_t CheckRpcidFormat(char *inputFile, char **Buffer, uint32_t *Len) return 0; } -int32_t RPCIDDecode(char *inputFile, char *outDirPath) +int32_t RPCIDDecode(char *inputFile, char *outputPath) { int32_t ret = 0; char *contextBuffer = NULL; @@ -375,16 +375,16 @@ int32_t RPCIDDecode(char *inputFile, char *outDirPath) // parse rpcid to json cJSON *rpcidRoot = cJSON_CreateObject(); - if (ParseRpcidToJson(contextBuffer, bufferLen, rpcidRoot)) { + if (ParseRpcidToJson(contextBuffer, bufferLen, rpcidRoot) != 0) { PRINT_ERR("Prase rpcid to json failed. Input failed: %s\n", inputFile); goto FREE_RPCID_ROOT; } // save to json file convertedBuffer = cJSON_Print(rpcidRoot); - ret = ConvertedContextSaveAsFile(outDirPath, "RPCID.json", convertedBuffer, strlen(convertedBuffer)); + ret = ConvertedContextSaveAsFile(outputPath, "RPCID.json", convertedBuffer, strlen(convertedBuffer)); if (ret != 0) { - PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:rpcid.json\n", outDirPath); + PRINT_ERR("ConvertedContextSaveAsFile failed, outputPath:%s, filename:rpcid.json\n", outputPath); goto FREE_RPCID_ROOT; } @@ -440,7 +440,7 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath) // parse rpcid to json rpcidRoot = cJSON_CreateObject(); - if (ParseRpcidToJson(contextBuffer, bufferLen, rpcidRoot)) { + if (ParseRpcidToJson(contextBuffer, bufferLen, rpcidRoot) != 0) { PRINT_ERR("Prase rpcid to json failed. Input file: %s\n", inputFile); goto FREE_RPCID_ROOT; } @@ -466,17 +466,17 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath) (void)memset_s(osSysCapIndex, sizeof(uint16_t) * sysCapArraySize, 0, sizeof(uint16_t) * sysCapArraySize); // malloc for save private syscap string - priSyscapArray = (char *)malloc(sysCapArraySize * SINGLE_SYSCAP_LEN); + priSyscapArray = (char *)malloc((uint32_t)sysCapArraySize * SINGLE_SYSCAP_LEN); if (priSyscapArray == NULL) { PRINT_ERR("malloc(%d) failed.\n", sysCapArraySize * SINGLE_SYSCAP_LEN); goto FREE_MALLOC_OSSYSCAP; } - (void)memset_s(priSyscapArray, sysCapArraySize * SINGLE_SYSCAP_LEN, - 0, sysCapArraySize * SINGLE_SYSCAP_LEN); + (void)memset_s(priSyscapArray, (size_t)(sysCapArraySize * SINGLE_SYSCAP_LEN), + 0, (size_t)(sysCapArraySize * SINGLE_SYSCAP_LEN)); priSyscap = priSyscapArray; // part os syscap and ptivate syscap for (i = 0; i < (uint32_t)sysCapArraySize; i++) { - cJSON *cJsonItem = cJSON_GetArrayItem(sysCapArray, i); + cJSON *cJsonItem = cJSON_GetArrayItem(sysCapArray, (int)i); cJsonTemp = cJSON_GetObjectItem(sysCapDefine, cJsonItem->valuestring); if (cJsonTemp != NULL) { osSysCapIndex[indexOs++] = (uint16_t)(cJsonTemp->valueint); From 300e90913affaf1b73408fb885f30ec1ea2c09ba Mon Sep 17 00:00:00 2001 From: zhaogan Date: Thu, 17 Nov 2022 19:29:57 +0800 Subject: [PATCH 19/23] Issue: #I61RFS Description: master: modify syscap of defaultAppManager Sig: SIG_ApplicaitonFramework Feature or Bugfix: Feature Binary Source: No Signed-off-by: zhaogan --- include/syscap_define.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/syscap_define.h b/include/syscap_define.h index b3f2a37..dead8fc 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -252,7 +252,7 @@ typedef enum SystemCapabilityNum { BUNDLEMANAGER_BUNDLEFRAMEWORK_CORE, BUNDLEMANAGER_BUNDLEFRAMEWORK_FREEINSTALL, BUNDLEMANAGER_BUNDLEFRAMEWORK_LAUNCHER, - BUNDLEMANAGER_BUNDLEFRAMEWORK_DEFAULTAPPMANAGER, + BUNDLEMANAGER_BUNDLEFRAMEWORK_DEFAULTAPP, BUNDLEMANAGER_BUNDLEFRAMEWORK_RESOURCE, MULTIMEDIA_AVSESSION_CORE, MULTIMEDIA_AVSESSION_MANAGER, @@ -487,8 +487,8 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.BundleManager.BundleFramework.Core", BUNDLEMANAGER_BUNDLEFRAMEWORK_CORE}, {"SystemCapability.BundleManager.BundleFramework.FreeInstall", BUNDLEMANAGER_BUNDLEFRAMEWORK_FREEINSTALL}, {"SystemCapability.BundleManager.BundleFramework.Launcher", BUNDLEMANAGER_BUNDLEFRAMEWORK_LAUNCHER}, - {"SystemCapability.BundleManager.BundleFramework.DefaultAppManager", - BUNDLEMANAGER_BUNDLEFRAMEWORK_DEFAULTAPPMANAGER}, + {"SystemCapability.BundleManager.BundleFramework.DefaultApp", + BUNDLEMANAGER_BUNDLEFRAMEWORK_DEFAULTAPP}, {"SystemCapability.BundleManager.BundleFramework.Resource", BUNDLEMANAGER_BUNDLEFRAMEWORK_RESOURCE}, {"SystemCapability.Multimedia.AVSession.Core", MULTIMEDIA_AVSESSION_CORE}, {"SystemCapability.Multimedia.AVSession.Manager", MULTIMEDIA_AVSESSION_MANAGER}, From 2ba377c1cd48203bdb5af6c05af6c7348e104c61 Mon Sep 17 00:00:00 2001 From: yudechen Date: Thu, 17 Nov 2022 15:25:33 +0800 Subject: [PATCH 20/23] fix: fix some defects. Signed-off-by: yudechen Change-Id: Ifcba58db1dfe58e22aa652abc5399d8e24e5413b --- src/syscap_tool.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/syscap_tool.c b/src/syscap_tool.c index ff3e461..54193ff 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -40,6 +40,7 @@ typedef struct RequiredProductCompatibilityIDHead { #define PCID_OUT_BUFFER RPCID_OUT_BUFFER #define BYTES_OF_OS_SYSCAP 120 #define U32_TO_STR_MAX_LEN 11 +#define STRING_FORMAT_LEN_MAX 1024 #define PRINT_ERR(...) \ do { \ @@ -115,12 +116,12 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename char path[PATH_MAX + 1] = {0x00}; #ifdef _POSIX_ - if (strlen(outDirPath) > PATH_MAX || strncpy_s(path, PATH_MAX, outDirPath, strlen(outDirPath)) != EOK) { + if (strlen(outDirPath) >= PATH_MAX || strncpy_s(path, PATH_MAX, outDirPath, strlen(outDirPath)) != EOK) { PRINT_ERR("get path(%s) failed\n", outDirPath); return -1; } #else - if (strlen(outDirPath) > PATH_MAX || realpath(outDirPath, path) == NULL) { + if (strlen(outDirPath) >= PATH_MAX || realpath(outDirPath, path) == NULL) { PRINT_ERR("get file(%s) real path failed\n", outDirPath); return -1; } @@ -162,9 +163,9 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename static cJSON *CreateWholeSyscapJsonObj(void) { - size_t numOfSyscapAll = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); + size_t allSyscapNum = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); cJSON *root = cJSON_CreateObject(); - for (size_t i = 0; i < numOfSyscapAll; i++) { + for (size_t i = 0; i < allSyscapNum; i++) { cJSON_AddItemToObject(root, g_arraySyscap[i].str, cJSON_CreateNumber(g_arraySyscap[i].num)); } return root; @@ -281,6 +282,10 @@ static int32_t ParseRpcidToJson(char *input, uint32_t inputLen, cJSON *rpcidJson uint32_t i; int32_t ret = 0; uint16_t sysCapLength = NtohsInter(*(uint16_t *)(input + sizeof(uint32_t))); + if (sysCapLength > inputLen - sizeof(uint32_t)) { + PRINT_ERR("Get sysCapLength(%u) error, inputLen = %u\n", sysCapLength, inputLen); + return -1; + } uint16_t sysCapCount = sysCapLength / SINGLE_FEAT_LEN; char *sysCapBegin = input + sizeof(RPCIDHead) + sizeof(uint32_t); RPCIDHead *rpcidHeader = (RPCIDHead *)input; @@ -421,7 +426,6 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath) int32_t ret = 0; int32_t sysCapArraySize; uint32_t bufferLen, i; - uint16_t indexOs = 0; uint16_t indexPri = 0; uint16_t *osSysCapIndex; char *contextBuffer = NULL; @@ -475,8 +479,9 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath) 0, (size_t)(sysCapArraySize * SINGLE_SYSCAP_LEN)); priSyscap = priSyscapArray; // part os syscap and ptivate syscap - for (i = 0; i < (uint32_t)sysCapArraySize; i++) { - cJSON *cJsonItem = cJSON_GetArrayItem(sysCapArray, (int)i); + uint16_t indexOs = 0; + for (int i = 0; i < sysCapArraySize; i++) { + cJSON *cJsonItem = cJSON_GetArrayItem(sysCapArray, i); cJsonTemp = cJSON_GetObjectItem(sysCapDefine, cJsonItem->valuestring); if (cJsonTemp != NULL) { osSysCapIndex[indexOs++] = (uint16_t)(cJsonTemp->valueint); @@ -557,7 +562,7 @@ int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uin { int32_t ret = 0; uint32_t i; - size_t inputLen = strlen(inputString); + uint32_t count = 0; char *temp = NULL; char *tok = NULL; @@ -568,7 +573,16 @@ int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uin } // copy to temp string input - char *input = (char *)malloc(strlen(inputString) + 1); + if (inputString == NULL) { + PRINT_ERR("inputString is null.\n"); + return -1; + } + size_t inputLen = strlen(inputString); + if (inputLen > STRING_FORMAT_LEN_MAX) { + PRINT_ERR("input string too long(%zu).\n", inputLen); + return -1; + } + char *input = (char *)malloc(inputLen + 1); if (input == NULL) { PRINT_ERR("malloc failed.\n"); return -1; @@ -650,6 +664,7 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t typ bool priSysFound; uint32_t pcidOsAarry[PCID_OUT_BUFFER] = {0}; uint32_t rpcidOsAarry[PCID_OUT_BUFFER] = {0}; + const size_t allSyscapNum = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); if (type == TYPE_FILE) { if (GetFileContext(pcidFile, &pcidContent, &pcidContentLen)) { @@ -692,9 +707,13 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t typ continue; } for (uint8_t k = 0; k < INT_BIT; k++) { - if (temp2 & (0x1 << k)) { - // 2, header of pcid & rpcid - printf("Missing: %s\n", g_arraySyscap[(i - 2) * INT_BIT + k].str); + if (!(temp2 & (0x1 << k))) { + continue; + } + // 2, header of pcid & rpcid + size_t pos = (size_t)((i - 2) * INT_BIT + k); + if (pos < allSyscapNum) { + printf("Missing: %s\n", g_arraySyscap[pos].str); ossyscapFlag += 1; } } From 92fce6ef774f4d51c91f70141358f2121b952a80 Mon Sep 17 00:00:00 2001 From: lifeng Date: Mon, 21 Nov 2022 15:39:56 +0800 Subject: [PATCH 21/23] Issue: #I62859 Description: add syscap of cloud aaid Sig: SIG_ApplicaitonFramework Feature or Bugfix: Feature Binary Source: No Signed-off-by: xuanfeng8 --- include/syscap_define.h | 4 +++- src/syscap_tool.c | 43 +++++++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/include/syscap_define.h b/include/syscap_define.h index dead8fc..78aa3e0 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -258,6 +258,7 @@ typedef enum SystemCapabilityNum { MULTIMEDIA_AVSESSION_MANAGER, MULTIMEDIA_AUDIO_TONE, MULTIMEDIA_AUDIO_INTERRUPT, + CLOUD_AAID, SYSCAP_NUM_MAX = 960 } SyscapNum; @@ -493,7 +494,8 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Multimedia.AVSession.Core", MULTIMEDIA_AVSESSION_CORE}, {"SystemCapability.Multimedia.AVSession.Manager", MULTIMEDIA_AVSESSION_MANAGER}, {"SystemCapability.Multimedia.Audio.Tone", MULTIMEDIA_AUDIO_TONE}, - {"SystemCapability.Multimedia.Audio.Interrupt", MULTIMEDIA_AUDIO_INTERRUPT} + {"SystemCapability.Multimedia.Audio.Interrupt", MULTIMEDIA_AUDIO_INTERRUPT}, + {"SystemCapability.Cloud.AAID", CLOUD_AAID} }; #ifdef __cplusplus diff --git a/src/syscap_tool.c b/src/syscap_tool.c index ff3e461..54193ff 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -40,6 +40,7 @@ typedef struct RequiredProductCompatibilityIDHead { #define PCID_OUT_BUFFER RPCID_OUT_BUFFER #define BYTES_OF_OS_SYSCAP 120 #define U32_TO_STR_MAX_LEN 11 +#define STRING_FORMAT_LEN_MAX 1024 #define PRINT_ERR(...) \ do { \ @@ -115,12 +116,12 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename char path[PATH_MAX + 1] = {0x00}; #ifdef _POSIX_ - if (strlen(outDirPath) > PATH_MAX || strncpy_s(path, PATH_MAX, outDirPath, strlen(outDirPath)) != EOK) { + if (strlen(outDirPath) >= PATH_MAX || strncpy_s(path, PATH_MAX, outDirPath, strlen(outDirPath)) != EOK) { PRINT_ERR("get path(%s) failed\n", outDirPath); return -1; } #else - if (strlen(outDirPath) > PATH_MAX || realpath(outDirPath, path) == NULL) { + if (strlen(outDirPath) >= PATH_MAX || realpath(outDirPath, path) == NULL) { PRINT_ERR("get file(%s) real path failed\n", outDirPath); return -1; } @@ -162,9 +163,9 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename static cJSON *CreateWholeSyscapJsonObj(void) { - size_t numOfSyscapAll = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); + size_t allSyscapNum = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); cJSON *root = cJSON_CreateObject(); - for (size_t i = 0; i < numOfSyscapAll; i++) { + for (size_t i = 0; i < allSyscapNum; i++) { cJSON_AddItemToObject(root, g_arraySyscap[i].str, cJSON_CreateNumber(g_arraySyscap[i].num)); } return root; @@ -281,6 +282,10 @@ static int32_t ParseRpcidToJson(char *input, uint32_t inputLen, cJSON *rpcidJson uint32_t i; int32_t ret = 0; uint16_t sysCapLength = NtohsInter(*(uint16_t *)(input + sizeof(uint32_t))); + if (sysCapLength > inputLen - sizeof(uint32_t)) { + PRINT_ERR("Get sysCapLength(%u) error, inputLen = %u\n", sysCapLength, inputLen); + return -1; + } uint16_t sysCapCount = sysCapLength / SINGLE_FEAT_LEN; char *sysCapBegin = input + sizeof(RPCIDHead) + sizeof(uint32_t); RPCIDHead *rpcidHeader = (RPCIDHead *)input; @@ -421,7 +426,6 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath) int32_t ret = 0; int32_t sysCapArraySize; uint32_t bufferLen, i; - uint16_t indexOs = 0; uint16_t indexPri = 0; uint16_t *osSysCapIndex; char *contextBuffer = NULL; @@ -475,8 +479,9 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath) 0, (size_t)(sysCapArraySize * SINGLE_SYSCAP_LEN)); priSyscap = priSyscapArray; // part os syscap and ptivate syscap - for (i = 0; i < (uint32_t)sysCapArraySize; i++) { - cJSON *cJsonItem = cJSON_GetArrayItem(sysCapArray, (int)i); + uint16_t indexOs = 0; + for (int i = 0; i < sysCapArraySize; i++) { + cJSON *cJsonItem = cJSON_GetArrayItem(sysCapArray, i); cJsonTemp = cJSON_GetObjectItem(sysCapDefine, cJsonItem->valuestring); if (cJsonTemp != NULL) { osSysCapIndex[indexOs++] = (uint16_t)(cJsonTemp->valueint); @@ -557,7 +562,7 @@ int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uin { int32_t ret = 0; uint32_t i; - size_t inputLen = strlen(inputString); + uint32_t count = 0; char *temp = NULL; char *tok = NULL; @@ -568,7 +573,16 @@ int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uin } // copy to temp string input - char *input = (char *)malloc(strlen(inputString) + 1); + if (inputString == NULL) { + PRINT_ERR("inputString is null.\n"); + return -1; + } + size_t inputLen = strlen(inputString); + if (inputLen > STRING_FORMAT_LEN_MAX) { + PRINT_ERR("input string too long(%zu).\n", inputLen); + return -1; + } + char *input = (char *)malloc(inputLen + 1); if (input == NULL) { PRINT_ERR("malloc failed.\n"); return -1; @@ -650,6 +664,7 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t typ bool priSysFound; uint32_t pcidOsAarry[PCID_OUT_BUFFER] = {0}; uint32_t rpcidOsAarry[PCID_OUT_BUFFER] = {0}; + const size_t allSyscapNum = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); if (type == TYPE_FILE) { if (GetFileContext(pcidFile, &pcidContent, &pcidContentLen)) { @@ -692,9 +707,13 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t typ continue; } for (uint8_t k = 0; k < INT_BIT; k++) { - if (temp2 & (0x1 << k)) { - // 2, header of pcid & rpcid - printf("Missing: %s\n", g_arraySyscap[(i - 2) * INT_BIT + k].str); + if (!(temp2 & (0x1 << k))) { + continue; + } + // 2, header of pcid & rpcid + size_t pos = (size_t)((i - 2) * INT_BIT + k); + if (pos < allSyscapNum) { + printf("Missing: %s\n", g_arraySyscap[pos].str); ossyscapFlag += 1; } } From ce0053aa93054c5609c83c1bae49a1cd23e33097 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Mon, 28 Nov 2022 10:03:29 +0800 Subject: [PATCH 22/23] update devicestatus syscap Signed-off-by:mayunteng_1 Signed-off-by: mayunteng_1 --- include/syscap_define.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/syscap_define.h b/include/syscap_define.h index 78aa3e0..1e53714 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -339,7 +339,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.MiscServices.Time", MISCSERVICES_TIME}, {"SystemCapability.MiscServices.Upload", MISCSERVICES_UPLOAD}, {"SystemCapability.MiscServices.Wallpaper", MISCSERVICES_WALLPAPER}, - {"SystemCapability.Msdp.DeviceStatus", MSDP_DEVICESTATUS}, + {"SystemCapability.Msdp.DeviceStatus.Stationary", MSDP_DEVICESTATUS}, {"SystemCapability.Msdp.Geofence", MSDP_GEOFENCE}, {"SystemCapability.Msdp.Motion", MSDP_MOTION}, {"SystemCapability.Msdp.Movement", MSDP_MOVEMENT}, From 00497cea911032d806835173e133c556b6615064 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Tue, 29 Nov 2022 15:19:41 +0800 Subject: [PATCH 23/23] update devicestatus syscap Signed-off-by:mayunteng_1 Signed-off-by: mayunteng_1 --- include/syscap_define.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/syscap_define.h b/include/syscap_define.h index 1e53714..2792e53 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -106,7 +106,6 @@ typedef enum SystemCapabilityNum { MISCSERVICES_TIME, MISCSERVICES_UPLOAD, MISCSERVICES_WALLPAPER, - MSDP_DEVICESTATUS, MSDP_GEOFENCE, MSDP_MOTION, MSDP_MOVEMENT, @@ -259,6 +258,7 @@ typedef enum SystemCapabilityNum { MULTIMEDIA_AUDIO_TONE, MULTIMEDIA_AUDIO_INTERRUPT, CLOUD_AAID, + MSDP_DEVICESTATUS_STATIONARY, SYSCAP_NUM_MAX = 960 } SyscapNum; @@ -339,7 +339,6 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.MiscServices.Time", MISCSERVICES_TIME}, {"SystemCapability.MiscServices.Upload", MISCSERVICES_UPLOAD}, {"SystemCapability.MiscServices.Wallpaper", MISCSERVICES_WALLPAPER}, - {"SystemCapability.Msdp.DeviceStatus.Stationary", MSDP_DEVICESTATUS}, {"SystemCapability.Msdp.Geofence", MSDP_GEOFENCE}, {"SystemCapability.Msdp.Motion", MSDP_MOTION}, {"SystemCapability.Msdp.Movement", MSDP_MOVEMENT}, @@ -495,7 +494,8 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Multimedia.AVSession.Manager", MULTIMEDIA_AVSESSION_MANAGER}, {"SystemCapability.Multimedia.Audio.Tone", MULTIMEDIA_AUDIO_TONE}, {"SystemCapability.Multimedia.Audio.Interrupt", MULTIMEDIA_AUDIO_INTERRUPT}, - {"SystemCapability.Cloud.AAID", CLOUD_AAID} + {"SystemCapability.Cloud.AAID", CLOUD_AAID}, + {"SystemCapability.Msdp.DeviceStatus.Stationary", MSDP_DEVICESTATUS_STATIONARY}, }; #ifdef __cplusplus